views:

168

answers:

1

Hello

I want to use fft in MATLAB to analize some exprimental data saved as an excell file. my code:

A=xlsread('Book.xls'); G=A'; x=G(2, : );
N=length(x);
F=[-N/2:N/2-1]/N;
X = abs(fft(x-mean(x),N))
X = fftshift(X);
plot(F,X)

But it plots a graph with a large 0Hz wrong component, my true frequency is about 395Hz and it is not shown in the plotted graph. Please tell me what is wrong.

Any help would be appreciated.

+5  A: 

Assume we read the signal from file:

G = xlsread('Book.xls');
t = G(:,1);
x = G(:,2);
N = length(x);

First we estimate the sampling frequency from the time axis, and build the frequency vector:

Fs = 1 ./ abs( t(2)-t(1) );
F = (-N/2:N/2-1)*Fs/N;

then compute the FFT and plot:

X = abs( fft(x-mean(x),N) );
X = fftshift(X);
stem(F,X)

finally find the peak and the corresponding frequency:

>> [~,ind] = max(X);
>> F(ind)
ans =
         -400

you might want to zoom-in near the origin to see things more clearly:

xlim([-1000 1000])
Amro
+1: thanks for providing a good clear example
Paul R
Nice. It works. Many thanks for your good clear answer.
roujhan