I am analyzing a signal in MATLAB by taking its fft. The singal has $200$ samples and I am currently taking nfft = 256. I understand that this would result in zero padding. Now, I want to try to reduce the nfft to 128, 64 etc. I wanted to ask what will happen to the fft.

Matlab says for Y = fft(X,n), If X is a vector and the length of X is greater than n, then X is truncated to length n. What would this actually result in. Can anyone explain, please?


The fast Fourier transform (FFT) is an efficient algorithm to compute the discrete Fourier transform (DFT). The DFT $X[k]$ of time-domain signal $x[k]$ of length $M$ is defined by

$$ X[k] = \sum_{\color{red}{i=0}}^{\color{red}{N-1}}x[\color{red}{i}]\cdot e^{-j2\pi k\color{red}{i}/N}, $$

with $N$ the length of the DFT. If $N>M$, i.e., the DFT length is greater than the length of the time-domain signal, it is typically assumed that $x[k]=0$ for $k\geq M$. You already mentioned that this process is usually called zero-padding. Alternatively, observe what happens in the equation if $M>N$, i.e., if the DFT length is shorter than the signal: The last values of $x$ are not taken into account for the computation, for all frequency bins $k$.

Hence, (as usual) what MATLAB says is correct. The question to your answer "What would this actually result in?", however, depends on the properties of the time-domain signal $x$. What happens if $x$ is a periodic signal has been addressed extensively in other answers here. In every case everything behaves as if the last $M-N$ values of $x$ would not exist, as described above.

|improve this answer|||||

Reducing the NFFT samples in your DFT will result is less resolution in the spectrum you'll be observing. The frequency resolution is defined as $$ f_k = \frac{F_s}{N}k\quad \text{with}\quad k=0, 1, \ldots, N-1\tag{1} $$ In your $N$-point Discrete Fourier Transform (DFT), decreasing $N$ increases the spacing between the $f_k$. Or put in another way, for a fixed sampling frequency $F_s$,

\begin{align} N_2 &< N_1 \implies \Delta f_{k_2} > \Delta f_{k_1}\\ \text{Where}\quad f_{k_1} &=\frac{F_s}{N_1}k_1\quad\text{and}\quad f_{k_2} =\frac{F_s}{N_2}k_2\\ \implies \Delta f_{k_1} &=\frac{F_s}{N_1}\quad\text{and}\quad \Delta f_{k_2} =\frac{F_s}{N_2} \end{align}

So say, you have some frequency components (i.e. peaks) you're observing in your spectrum with a high $N$, gradually reducing this value, you'll see that the peaks are getting less and less localized visually. Note that it is only visually, your DFT got your spectrum, you play with $N$ (i.e. NFFT) to visualise more out of your spectrum. Together with $F_s$, it determines the frequency resolution as defined in $(1)$.


To compute the energy, you sum the squared amplitudes spectrum values. Look for instance at the MATLAB code below for the sine wave $$ s(t) = 3\sin(2\pi 150t) $$

Fs = 500;            % Sampling frequency
T = 1/Fs;             % Sampling period
L = 2000;             % Length of signal
t = (0:L-1)*T;        % Time vector
f = Fs*(0:(L/2))/L;

S = 3*sin(2*pi*150*t);

NFFT = 2^nextpow2(L);
NFFT1 = L;

Y = fft(S, NFFT1)/NFFT1;
Y2 = fft(S, NFFT2)/NFFT2;
Y3 = fft(S, NFFT3)/NFFT3;

EY = sum(Y.*conj(Y));
EY2 = sum(Y2.*conj(Y2));
EY3 = sum(Y3.*conj(Y3));

Your FFT have to be normalized and the energy computed as sum of the squared amplitude spectrum. For the sample code above you get:

EY = 4.5    
EY2 = 4.49644474953643  
EY3 =4.49832143842713

Which is from the amplitude of the sine $3$, giving ($3^2/2$). Also showing the effect of taking different $N$ values for the FFT on resulting energy.

|improve this answer|||||
  • $\begingroup$ I understand your point that the resolution of the bins would worsen as N is decreased. But when I use the produced fft indexes to compute the energy in the signal, that gives me the wrong answer. Can you explain, why I can't use Y = fft(data, L); Y3energy = (Y.*conj(Y))/L; energy3 = sum(Y3energy); to find the energy of the in the signal. $\endgroup$ – Usman Ashraf Feb 12 '18 at 9:58
  • 1
    $\begingroup$ I think it is also important to note that not all signal samples will be used for the spectrum computation if the DFT length is lower than the signal length. Of course, this is related to a reduced frequency resolution, but may have further consequences, e.g., if the signal is nonzero only in the last samples. $\endgroup$ – applesoup Feb 12 '18 at 10:14
  • $\begingroup$ @applesoup, this is exactly what I have observed in matlab code. If I reduce NFFT below the signal length, the energy value is the same as if the last samples of the signal X are dropped from it. $\endgroup$ – Usman Ashraf Feb 12 '18 at 10:41
  • $\begingroup$ @applesoup, can you suggest a way in which I don't lose information from the signal and still be able to reduce the NFFT below the input sample length. I want to do this for the more optimized implementation on verilog (hardware design language). $\endgroup$ – Usman Ashraf Feb 12 '18 at 10:49
  • $\begingroup$ @UsmanAshraf, please see the edit in my answer. $\endgroup$ – Gilles Feb 12 '18 at 10:59

An FFT of a finite segment of longer data convolves that longer data with the transform of a rectangular window the length of the FFT. The transform of that rectangle is a periodic Sinc, which gets conjugate mirrored by strictly real data, The shorter the FFT the shorter the window, the “fatter” the Sinc lobes.

Added: If a short FFT window excludes a portion of a longer signal, the energy in the portion completely excluded will no longer be represented in an unnormalized FFT result. For normalized results, if the energy in the portion excluded is exactly proportional to the length excluded, then the normalized FFT result can appear to be the same. But that requires that you know or have measured the energy in the excluded portion.

For signals that are known to be exactly integer periodic in both the longer and shorter DFT lengths, the data can be wrapped around the shorter window by summation, and the DFT results normalized to the longer of the two lengths will be the same.

|improve this answer|||||
  • $\begingroup$ For an aperiodic signal, does taking an FFT with NFFT less than the length of signal have any effect on the energy computation made through Y.*conj(Y). $\endgroup$ – Usman Ashraf Feb 12 '18 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.