In an answer to a previous question, it was stated that one should
zero-pad the input signals (add zeros to the end so that at least half of the wave is "blank")
What's the reason for this?
|
In an answer to a previous question, it was stated that one should
What's the reason for this? |
|||||||||||
|
|
Zero padding allows one to use a longer FFT, which will produce a longer FFT result vector. A longer FFT result has more frequency bins that are more closely spaced in frequency. But they will be essentially providing the same result as a high quality Sinc interpolation of a shorter non-zero-padded FFT of the original data. This might result in a smoother looking spectrum when plotted without further interpolation. Although this interpolation won't help with resolving or the resolution of and/or between adjacent or nearby frequencies, it might make it easier to visually resolve the peak of a single isolated frequency that does not have any significant adjacent signals or noise in the spectrum. Statistically, the higher density of FFT result bins will probably make it more likely that the peak magnitude bin is closer to the frequency of a random isolated input frequency sinusoid, and without further interpolation (parabolic, et.al.). But, essentially, zero padding before a DFT/FFT is a computationally efficient method of interpolating a large number of points. Zero-padding for cross correlation is used to not mix convolution results. The full result of a convolution is longer than either of the two input vectors. If you don't provide a place to put the end of this longer convolution result, FFT fast convolution will just mix it in with and cruft up your desired result. Zero-padding provides a bunch zeros into which to mix the longer result. And it's far far easier to un-mix something that has only been mixed/summed with a zero vector. |
|||||||||||||
|
|
There are a few things to consider before you decide to zero pad your time-domain signal. You may not need to zero pad the signal at all! 1) Lengthen the time-domain data (not zero padding) to get better resolution in the frequency domain. 2) Increase the number of FFT points beyond your time-domain signal length (zero padding) if you would like to see better definition of the FFT bins, though it doesn't buy you any more true resolution. You can also pad to get to a power of 2 number of FFT points. 3) When fiddling with the FFT points (in the previous point), make sure your frequency points end up where you want them. The spacing of the points is $f_s/N$, where $f_s$ is the sampling frequency and $N$ is the number of FFT points. There are some nice figures illustrating these points at http://www.bitweenie.com/listings/fft-zero-padding/ One last thing to mention: If you zero pad the signal in the time domain and you want to use a windowing function, make sure you window the signal before you zero pad. If you apply the window function after zero padding, you won't accomplish what the window is supposed to accomplish. More specifically, you'll still have a sharp transition from the signal to zero instead of a smooth transition to zero. |
||||
|
|
|
In general zero-padding prior to DFT is equivalent to interpolation, or sampling more often, in the transformed domain. Here is a quick visualization. If you sample a bandlimited signal in time at higher rate, you get a more 'squashed' spectrum, i.e., spectrum with more zeros at both ends. In other words, you can obtain more samples in time by simply zero-padding in frequency after DFT and IDFTing the result. The same effect holds in reverse when zero-padding occurs in time. This is all because the perfect signal reconstruction is possible as long as a signal is bandlimited and sampled at least at the Nyquist rate. The term 'resolution' depends on how you define it. For me, it means how well the two adjacent points of observation in time or frequency can be reliably (statistically) discriminated. In this case the resolution actually depends on the DFT size due to spectral leakage. That is, smaller the window size, more blurry or smeared the transformed signal, and vice versa. It is different from how often you sample, or what I term 'definition'. For example, you can have a very blurry image sampled at high rate (high definition), yet you still cannot obtain more information than sampling at lower rate. So in summary, zero-padding does not improve resolution at all since you do not gain any more information than before. |
|||
|
|
|
If one has any interest in the spectrum of the windowing function used to isolate the time-domain sample, then zero-padding WILL increase the frequency resolution of the windowing function. If the time signal is $x(t)w(t)$, where $w(t)$ is the windowing function, then the overall spectrum is $X(f) * W(f)$, where $*$ inidicates convolution. If your windowing function is a simple rectangle (an extraction of some set of values from $x(t)$. Then $X(f)$ is the sync function. So, for example, if Nfft is the same as the width of your rectangle, and you had a sinusoid at precisely one of the bin frequencies, then the samples of the sync function that would appear centered on that bin happen to fall exactly at the off-peak zero crossings, and you don't see the shape of the sync in the spectrum at all. If you now zero pad your data going into the FFT, you'll see some samples at places other than the peak and the zero crossings, revealing the shape of the sync function in the resulting spectrum. So of what use is zero-padding? It is certainly of educational use in revealing the nature of the discrete transform of windowed signals, which is the usual case. In a practical sense, it could be useful in any case where you are interested in the spectral shape of an isolated envelope riding on a carrier wave. |
||||
|
|
|
There can be different reasons for this depending on any processes carried out before and after the Fourier transform. The most common reason is to achieve greater frequency resolution in any resulting transform. That is to say that, the larger the number of samples used in your transform, the narrower the binwidth in the resulting power spectrum. Remember: binwidth = sample_frequency/transform_size (often called window size). You can imagine from this, that as you increase your transform size, binwidth reduces (=better frequency resolution). Zero padding is a way of increasing the transform size without introducing new information to the signal. So why not just take a bigger transform without zero padding? Would that not achieve the same effect? Good question. In many cases you may want to analyze a stream of time domain data, for which you may be using a short time Fourier transform (stft). This involves taking a transform every N samples according to the time resolution you need in order to characterize changes in the frequency spectrum. Here in lies the problem. Too big a window and you will lose time resolution, too small a window and you will lose frequency resolution. The solution then is to take small time domain windows giving you good time resolution and then zero pad them to give you good frequency resolution. Hope this is useful for you Update |
|||||||||||
|
|
DFT of the zero padding signal is just a better approximation of the DTFT of the original signal. |
|||
|
|