fft of given data

4 vues (au cours des 30 derniers jours)
Juan
Juan le 16 Nov 2013
Commenté : Wayne King le 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 commentaires
Juan
Juan le 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 le 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.

Connectez-vous pour commenter.

Réponses (1)

Wayne King
Wayne King le 16 Nov 2013
Modifié(e) : Wayne King le 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 commentaires
Juan
Juan le 17 Nov 2013
Modifié(e) : Juan le 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 le 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

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by