fft of given data

4 次查看(过去 30 天)
Juan
Juan 2013-11-16
评论: Wayne King 2013-11-17
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 个评论
Juan
Juan 2013-11-17
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 2013-11-17
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.

请先登录,再进行评论。

回答(1 个)

Wayne King
Wayne King 2013-11-16
编辑:Wayne King 2013-11-16
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 个评论
Juan
Juan 2013-11-17
编辑:Juan 2013-11-17
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 2013-11-17
which column in the excel file is the data you are trying to Fourier transform? what is the title of the column

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by