Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

about plotting FFT in matlab

Status
Not open for further replies.

serhannn

Member level 4
Joined
Sep 28, 2010
Messages
69
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,939
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:
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:
our.jpg

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:
mws.jpg

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.
 

I think the FFT algorithm require radix 2 block sizes (zero padding to fill blocks)
You must use windowing before the FFT (Hanning)
 

While comparing two approaches to calculate FFT, better to use identical data with 2^n (say 1024) points. The outcome should agree. You can do that using your own program. availability of a sample data will also help more quantitative responses. You may try math cad too.
 

fft - Fast Fourier transform

Syntax

Y = fft(x)
Y = fft(X,n)
Y = fft(X,[],dim)
Y = fft(X,n,dim)

= fft(x) returns the discrete Fourier transform (DFT) of vector x, computed with a fast Fourier transform (FFT) algorithm.

If the input X is a matrix, Y = fft(X) returns the Fourier transform of each column of the matrix.

If the input X is a multidimensional array, fft operates on the first nonsingleton dimension.

Y = fft(X,n) returns the n-point DFT. fft(X) is equivalent to fft(X, n) where n is the size of X in the first nonsingleton dimension. If the length of X is less than n, X is padded with trailing zeros to length n. If the length of X is greater than n, the sequence X is truncated. When X is a matrix, the length of the columns are adjusted in the same manner.

Y = fft(X,[],dim) and Y = fft(X,n,dim) applies the FFT operation across the dimension dim.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top