next up previous contents
Next: The windowed DFT Up: Frequency domain analysis Previous: Making matlab's fft() function   Contents

Zero-Padding of FFTs

``Zero-padding'' means adding additional zeros to a sample of data (after the data has been windowed, if applicable). For example, you may have 1023 data points, but you might want to run a 1024 point FFT or even a 2048 point FFT. There are two reasons why you might do this. First, from section6.1 we recall that the FFT is slow for prime numbers, but much faster for powers of two. We can add an extra zero to the end of the sample and thus get much better performance. On a modern PC, one need not be too concerned with this for moderate sample sizes. 1023 is not noticeably slower than 1024. But if one is running very big FFTs (100,000 or more) or using lower powered embedded devices, one might be concerned about this.

The other reason that zero-padding is used is to get better frequency resolution. There is something to be gained here, but it is very subtle. National Instruments has a good writeup on this [4]. Here is a summary. Recall from section 6.1 that the DFT is a sampling of the DTFT. Zero padding allows us to take more samples of the DTFT. For example, if we have 1000 points of data, sampled at 1000 Hz, and perform the standard FFT, I get a frequency bin every 1 Hz. But if I pad with 1000 zeros and then run a 2000 point FFT, now I get frequency bins every 0.5 Hz. This allows us to get around some of the disadvantages of the DFT (e.g. it may allow us to read amplitudes more accurately - reducing the spacing between bins may put a bin closer to true frequency of a signal and those avoid the picket fence effect). But, since all this does is sample the DTFT more finely, we cannot get around any inherent limitations of the DTFT itself. Most noteable, if your choice of window type and length do not allow you to resolve two closely spaced frequency components, then zero padding is not going to help. See fig:Zero-padding-ex.

Note that simply increasing the sampling rate does not confer the same benefits that zero padding does. What matters is the length of the data in seconds, not the length of the data in samples.

As mentioned at the begining of the section, if the data is to be windowed (which it probably should be), then the zero pad should be applied after the window. This is illustrated in Figure 15, where the signal is an 11 Hz sine wave. When taken with a 2 Hz resolution FFT and no window, there is significant leakage and picket fence effect. Adding a window reduces the leakage, but not the picket fence effect. Zero padding before the window doubles the frequency resolution to 1 Hz, and thus reduces the picket fence, but now the leakge has returned. The best procedure is to window first, then zero pad. The reason, of course, is that the point of the window is to smooth out the begining and end of the data sample. If the zero pad is applied first, then the middle of the data set could still be non-smooth.

Figure 14: Example of the benefits and limitations of zero padding FFTs. Top: Using a rectangular window, a two second sample at 1000 S/s consisting of a 10.3 Hz tone and a 10.8 Hz tone is computed using a 2000 sample FFT, as well as zero padded FFTs for a total length of 4000, 8000, and 16000. With the standard FFT, the two signals are distinguishable, but the picket fence effect has distorted their magnitudes. The zero-padded FFTs allow a better estimation of the amplitudes and frequencies. Bottom: the same procedure is used, but with tones at 10.4 Hz and 10.7 Hz. These tones are not distinguishable and zero padding the FFT does not help the situtation. To resolve these, one must take a longer data sample.
\includegraphics{fig6-zero-pad}

Figure 15:
Image zeropad_vs_window


next up previous contents
Next: The windowed DFT Up: Frequency domain analysis Previous: Making matlab's fft() function   Contents " . $row['Name'] . " Posted on " . $row['DateTime']; echo "
"; echo $row['Comment']; echo "

"; } echo "
"; ?> Leave a comment on this page:

Name: (optional)
To prove you are not a robot, what is 2+3?

Creative Commons License
This work by Daniel Kiracofe (daniel dot kiracofe at gmail dot com) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License./' $I