Getting wrong results with fft

16 visualizzazioni (ultimi 30 giorni)
Kokalz
Kokalz il 16 Feb 2014
Risposto: Paul il 16 Feb 2014
Hi guys!
I just can't get my head around fft function in MATLAB. I have a set of variable-step data and variable-step time obtained from SIMULINK model. I now want to plot that data in frequency domain, but I just can't seem to get the right results. I used interp1 function to get fixed step size time and data. I then found sampling freq. as
fs = 1/(fixedTime(1)-fixedTime(2));
fq = fs/2; % Niquist freqency
But what do I do now, to find the frequency response of my data? just using abs(fft(data)) does not seem to do the job, as the results I get are different to what I would expect.
Thank you very much for your help!!

Risposte (1)

Paul
Paul il 16 Feb 2014
y = signal; %the signal you want to fft
L = length(y);
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 single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by