# Zero-pad before or after windowing for FFT

What's the correct way. Should I zero-pad a signal before or after applying a windowing function?

• I'd go with before the signal, at the rate in which you are computing the FFT, so signal -> zero pad -> FFT -> Window but just my opinion. – Phorce Jan 12 '14 at 14:14
• Is there an argumentation why to go this way? – mhawker Jan 12 '14 at 14:16
• Post to dsp.se before or after comp.dsp? – John Jan 12 '14 at 14:37
• @mhawker - I don't believe it really matters. Ok, for example, why do you zero-pad? Well, usually, to produce a longer FFT resulting vector. I don't understand why you would do this after applying the window function, because in essence the analysis has already been done. dsp.stackexchange.com/questions/741/… – Phorce Jan 12 '14 at 14:39
• Why would one want to do this? – user7358 Jan 12 '14 at 17:54

If done correctly, the order should not matter. You apply windowing to remove the jumps at the end of the signal segment by fading the values there to zero. Zero-padding then continues with zeros. Irregardless if padded or not, the windowing should only be applied to the original signal segment.

The wrong way would be to zero-pad and then apply windowing to the now longer signal over its full length, i.e., without regard to the position of the jumps. This would not remove the jumps and thus keep the background in the spectrum that is not related to the frequency content of the signal but the segmentation method.

• "If done correctly, the order should not matter." what, Lutz?? are you implying that multiplication is a commutative operation? – robert bristow-johnson Jan 12 '14 at 18:46
• No, only as explained that the windowing might be applied to the wrong segment, with disastrous results. – Lutz Lehmann Jan 13 '14 at 0:14
• i was being sorta facetious, L. order should not matter because multiplication is commutative. just make sure the overall window, $w[n]$, is the same between the two cases for all samples. $w[n]=0$ for those samples corresponding to the zero padding. this question was just asked at the USENET group comp.dsp. i think maybe by the same person. – robert bristow-johnson Jan 13 '14 at 4:19
• @robertbristow-johnson Isn't the point of the question the fact that the window in the two cases is different? – Jim Clay Jan 13 '14 at 14:50
• well, the question is not clear about that. only about whether to "zero-pad a signal before or after applying a windowing function". i am assuming the operations are adjacent to each other in the signal chain and there is nothing (like an FFT) going on in between. zero-padding is equivalent to multiplying the samples that were there to begin with by zero. those zeros can be combined with the non-zero samples of the window to be a bigger window of sorts. of course, if the window in the two cases are different, the results are different. – robert bristow-johnson Jan 13 '14 at 16:10

I would window and then zero-pad.

The purpose of the window is to smooth out the boundary transitions. When you zero-pad you are introducing a very abrubt transition at the zero-pad point which, if you want the window to be effective, is where the smoothed out transition should happen.

You must window your data, before zero-padding. The point of the windowing process is to smooth out the end-points of your data prior to taking the FFT, so that we reduce spectral leakage.

If you zero-pad and then window, you are making the implicit statement that all the zeros you added are part of your data, which is incorrect.