serhannn
Member level 4
Hi,
We are trying to analyse the frequency content of some signals. For this we dump the signals into matlab and run the fft command. however we experience problems while we are plotting it.
we have written a code ourselves for plotting and we have the code mathworks provides its users with in their "help". With our code and their code we get different frequency spectrums from same signals.
for example we have a signal of length 1000. when we use 1000 point fft with our plotting algorithm, we get a totally different result than what we get from a 1024 point fft with mathworks' algorithm; the amplitudes, proportions between the specific frequency components are different.
for example, our code:
result we get:
mathworks' code:
mathworks' result:
We could not be sure which outcome is true. We don't see any fault in our approach, but results turn out to be different...
Also, if anyone has a working code to produce and plot FFT of a signal, can you please send it to us?
Thanks a lot.
We are trying to analyse the frequency content of some signals. For this we dump the signals into matlab and run the fft command. however we experience problems while we are plotting it.
we have written a code ourselves for plotting and we have the code mathworks provides its users with in their "help". With our code and their code we get different frequency spectrums from same signals.
for example we have a signal of length 1000. when we use 1000 point fft with our plotting algorithm, we get a totally different result than what we get from a 1024 point fft with mathworks' algorithm; the amplitudes, proportions between the specific frequency components are different.
for example, our code:
Code:
N_eff=2000;
fft_res=fs_eff/N_eff;
f=(-fs_eff/2+fft_res):fft_res:(fs_eff/2-fft_res);
figure;
Y=fftshift(fft(y,N_eff)/L);
Y=Y(1:1999);
plot(f, log(2*abs(Y))); title('FFT of the signal');
xlabel('Frequency [Hz]'); grid minor;
result we get:
mathworks' code:
Code:
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = fs_eff/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure;plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
mathworks' result:
We could not be sure which outcome is true. We don't see any fault in our approach, but results turn out to be different...
Also, if anyone has a working code to produce and plot FFT of a signal, can you please send it to us?
Thanks a lot.