1
votes

Question 1
I have a signal x with sampling frequency 1000.
I want to do X = fft(x,nfft); in Matlab. The question is I don't know how to find the value of nfft. I saw that one may calculate the nfft by nfft = 2^nextpow2(length(x)); But I don't know the meaning of it, anyone can explain it?

Question 2
I have a signal x with sampling frequency 1000.
I want to add a rectangular window this time and then do the fft.
Such as X = fft(x(1:200),nfft); in Matlab.
Suppose I know how to calculate the nfft this time, but I want to ask that what is the relationship between the window size and the X.
For example, if I have a big window, how will it change the X?
If I have a small window, how will it change the X?

2

2 Answers

3
votes

Question 1

To answer the first question, the standard convention is to chose the power of 2 that is next above the size of the data you are putting in. The reason for the power of 2 is due to the way the fft algorithm splits data. While you can use a size other than a power of 2, it will be slower if you do, so it is highly recommended to use a power of 2. Also use length(x) not size(x)

Also you do not want to use a value smaller than the size of the data you are analyzing because if you do, not all of the samples will be used, however if you use something larger, the function will just append 0's to the end so it is the correct size, called zero padding.

Question 2

Windowing, especially with a rectangular filter, will not really affect x, other than making the sample size smaller leading to less accuracy from the FFT. As you trim out data, your resolution is lowered for the output X. More data typically means better resolution/accuracy

Note

StackOverflow is not really a venue for these questions. Please do your homework. Read up before asking questions that could have easily been answered by reading a Wikipedia article or googling FFT.

Update Information regarding FFT algorithm. FFT

The process of splitting data is called decimation in time, for the forward FFT, and decimation in frequency for the inverse FFT

0
votes

The best answer as I asked myself the same question is: nexpower of 2 is for better fitting the FFT in a 2^N window. But the choice depends on the resolution you want to get in the FFT, as the FFT with bigger window just appends some zeros to the FFT. Also, if you want to plot the signal, you must choose the correct frequency range:

For 2*nextpowerof2, you should use f from 0 to N+1 For 1*nextpowerof2, you should use f from 0 to N/2+1