fft of given data

2 views (last 30 days)
Juan
Juan on 16 Nov 2013
Commented: Wayne King on 17 Nov 2013
I got data from a lab, and the FFT I get have a peak in zero Hz. But it is not right, it should have a peak at 50 Hz (european frecuncy). I just don't know what else to try, I'm without new ideas of way to continuo. Please give me an adavise!
The data is xlsx below.
Summering:
% same as in http://www.mathworks.es/es/help/matlab/ref/fft.html but with Fs=150, thus 150/2=75 so close to my 50 Hz, and y and t are vectors given.
y=v;
Fs = 150; % Sampling frequency
% T = 1/Fs; % Sample time
L = length(t); % Length of signal
% t = (0:L-1)*T; % Time vector
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
  2 Comments
Juan
Juan on 17 Nov 2013
Finally semi solved, from
x=i;
%//If youre getting a massive peak at zero that dwarfs everything else, you
%//probably have a large DC offset. Easily removed in the time domain using
%//the following ..
x = x-mean(x);
tAxis = t;
dt = diff(tAxis(1:2)); %//sample period from time axis
fs = 1/dt;%//sample rate from sample period
NFFT = numel(x); %//number of fft bins - change if you like
Y = abs(fft(x, NFFT)).^2; %power spectrum
%//Calculate frequency axis
df = fs/NFFT;
fAxis = 0:df:(fs-df);
%//Plot it all
figure; plot(fAxis(1:NFFT/2), Y(1:NFFT/2))
xlabel('Frequency in Hz')
ylabel('Power')
xlim([0,300]);
Juan
Juan on 17 Nov 2013
Note: for better view of my data
change:
NFFT = 1e6;
add:
xlim([0,300]);
PD: it seems like i didnt need help from here, the stackoverflow-given-an-array-of-data-extract-possible-frequencies-with-fft-how-to would have been enough, but I wont delete this. This may help others.

Sign in to comment.

Answers (1)

Wayne King
Wayne King on 16 Nov 2013
Edited: Wayne King on 16 Nov 2013
That indicates that the data has a non-zero mean. First, subtract the mean
y = detrend(y,0);
or simply
y = y-mean(y);
Then execute your commands above.
  2 Comments
Juan
Juan on 17 Nov 2013
Edited: Juan on 17 Nov 2013
Thanks for the answer.
But that doesnt solve the problem. The DC offset or mean is so small that I think is not a problem:
>> mean(y)
ans =
1.3573e-13
>> max(y)
ans =
309.9389
Wayne King
Wayne King on 17 Nov 2013
which column in the excel file is the data you are trying to Fourier transform? what is the title of the column

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!