Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fft/ifft: Sampling Frequency and Length of Signal

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 length of the signal is a multiple of the sampling frequency, the sinusoid is reconstructed correctly (apart from some shift), e.g. here Fs = 30, L = 60:

enter image description here

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

enter image description here

Is this behaviour correct? Why is this happening and how can I avoid this? Just throw away some part of the signal such that the length "fits" the sampling frequency?

like image 812
Tobias Avatar asked Jun 11 '12 15:06

Tobias


1 Answers

When you use the abs(fft()) in ifft, you are using only the amplitude of the signal and dropping the phase information, which is needed.

Use the whole signal (removed abs):

plot(real(ifft(fft(x)))); % fft then ifft
like image 101
Ran Avatar answered Oct 13 '22 21:10

Ran