Getting wrong results with fft

16 views (last 30 days)
Kokalz
Kokalz on 16 Feb 2014
Answered: Paul on 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!!

Answers (1)

Paul
Paul on 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)|')

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!