I have a audio signal sample at the rate of 10Khz, I need to find fourier coefficients of my signal. I saw one example in mathwork's website where they are using following code to do the fft decomposition of a signal y:
NFFT = 2^nextpow2(L);
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
where L is the length of the signal, I don't really understand why its defining the variable NFFT the way shown in the code above? Can't I just chose any value for NFFT? Also why are we taking Fs/2 in third line of the code above?
The non-equidistant fast Fourier transform (NFFT) is an extension of the famous fast Fourier transform (FFT), which can be applied to non-equidistantly sampled data in time/space or frequency domain.
Y = fft( X , n ) returns the n -point DFT. If no value is specified, Y is the same size as X . If X is a vector and the length of X is less than n , then X is padded with trailing zeros to length n . If X is a vector and the length of X is greater than n , then X is truncated to length n .
The fft function in MATLAB® uses a fast Fourier transform algorithm to compute the Fourier transform of data. Consider a sinusoidal signal x that is a function of time t with frequency components of 15 Hz and 20 Hz.
1) NFFT must be greater than your series length: N = length(x); 2 ) yes, FFT is faster if it is an exponential of 2: NFFT = 2^(nextpow2(N)+3); 3 makes more points!
NFFT
can be any positive value, but FFT computations are typically much more efficient when the number of samples can be factored into small primes. Quoting from Matlab documentation:
The execution time for fft depends on the length of the transform. It is fastest for powers of two. It is almost as fast for lengths that have only small prime factors. It is typically several times slower for lengths that are prime or which have large prime factors.
It is thus common to compute the FFT for the power of 2 which is greater or equal to the number of samples of the signal y
. This is what NFFT = 2^nextpow2(L)
does (in the Example from Matlab documentation y
is constructed to have a length L
).
When NFFT > L
the signal is zero padded to the NFFT
length.
As far as fs/2
goes, it is simply because the frequency spectrum of a real-valued signal has Hermitian symmetry (which means that the values spectrum above fs/2
can be obtained from the complex-conjugate of the values below fs/2
), and as such is completely specifies from the first NFFT/2+1
values (with the index NFFT/2+1
corresponding to fs/2
). So, instead of showing the redundant information above fs/2
, the example chose to illustrate only the spectrum up to fs/2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With