Fft / ifft: Sampling frequency and signal length

This is partly taken from the Matlab fft documentation:

Fs = 30;                    % Sampling frequency
T = 1/Fs;                   % Sample time
L = 130;                    % Length of signal
t = (0:L-1)*T;              % Time vector

x = sin(2*pi*1*t);          % 1 Hz sinus

plot(real(ifft(abs(fft(x))))); % fft then ifft

% Fs = 30, L = 60 / 90 / 120 ... : ok
% Fs = 20, L = 60 / 80 / 100 ... : ok
% Fs = 30, L = 50 / 70 / 80 ... : not ok

It seems to me that whenever the signal length is a multiple of the sampling frequency, the sine wave is restored correctly (except for some shift), for example, here Fs = 30, L = 60:

enter image description here

However, if, for example, Fs = 30, L = 80(not multiple), the result looks odd:

enter image description here

Is this behavior right? Why is this happening and how can I avoid this? Just throw away part of the signal so that the length "matches" the sampling rate?

+5
source share
1 answer

When you use abs (fft ()) in ifft, you only use the amplitude of the signal and discard the necessary phase information.

Use the whole signal (remote abs):

plot(real(ifft(fft(x)))); % fft then ifft
+7
source

All Articles