# Window functions and the Fourier transform

I want to clarify the 'correct' way to use windowing and Fourier transforms.

My question is somewhat related to this one, but I have a few additional queries.

I have some real, non periodic signal in the time domain $$y(t)$$. Since this is a real signal, the data is naturally discrete.

I want to calculate the Fourier transform of this signal, $$Y(f)$$, within an observation time, $$T$$. I understand that

$$\tilde{Y}(f) = \int^{+T/2}_{-T/2} y(t) \exp(-2 \pi i f t) dt$$

$$= Y(f) \ast T \operatorname{sinc} (\pi f T)$$

where $$Y(f)$$ is the unwindowed FT of the infinite signal

To avoid the effects of the $$\operatorname{sinc}$$ function, windowing is recommended to taper the signal within the observation period $$T$$.

My question is: If I want to calculate $$\tilde{Y}(f)$$ computationally (e.g. using python/numpy),

1. Is it required for the time signal to be zero at the edges? Why so?
2. Does spectral leakage still occur if so?
3. Aren't we distorting the true time signal $$y(t)$$?
4. If we increase the observation time $$T$$ to e.g. $$2T$$, how does $$\tilde{Y}(f)$$ change?
• "Since this is a real signal, the data is naturally discrete." -- do you mean discrete time? If not, what do you mean? – TimWescott Feb 18 at 16:48
• Yes, sorry not clear - discrete in time – user1887919 Feb 18 at 17:48

So called spectral leakage always occurs when transforming any finite length observation. That's because it's an artifact of windowing, and any non-infinite length observation (-t/2 ... +t/2) requires some sort of window, inherent rectangular or otherwise. A window function allow you to choose your artifact: from window "distortion" to Sinc effects, and/or many other choices.

• Ok. But it is accepted that e.g. a Nuttal window which drives the time signal to 0 at the edge of the time interval is 'more correct' than a simple box function? – user1887919 Feb 18 at 17:49
• What if the actual signal is only non-0 within the observation interval? – user1887919 Feb 18 at 17:50
• Neither is "more correct". Both depend on what type of analysis you want to do on what type of signal. I've used either in situations where the other was comparitively bad. – hotpaw2 Feb 18 at 18:35
• If the signal is zero outside the window, and you aren't using an unpadded circular DFT/FFT, then a rectangular window is equivalent to a no-op. – hotpaw2 Feb 18 at 18:37
• Great that is v.useful. Just to clarify: 'no-op' means? – user1887919 Feb 18 at 18:42

Focusing on your question (the final part of your text), You don't really have to impose any "boundary conditions" (forgive the somewhat abusive use of the term). You have to keep in mind though, that any kind of tapering (or any kind of modification of the signal), will affect the result of the analysis. Roughly speaking, in order to perform the Fourier Transform, you assume that the signal is periodic (this means it spans the range from $$-\infty$$ to $$+\infty$$).

Now, if your signal's boundaries have different values, then the wraparound that will be conceptually performed (doesn't really happen) will create a signal that exhibits a discontinuity. This is depicted for an artificial signal in the image below. The different colours represent the same signal replicated (which is what is mathematically assumed). It is obvious that there is a quite prominent discontinuity at every colour change. Now, the spectrum of this signal (only one colour) is what you can see in the next image The actual frequencies in the signal are $$7.65 Hz$$ and $$9.87 Hz$$. The frequency bin bandwidth is $$3.\bar{3} Hz$$ (signal length is 30 samples and the sampling frequency is $$100 Hz$$). As you can see the frequency components are not very distinct (you can differentiate between them but there is a lot of leakage). Additionally, there has been introduced an initial phase of $$135 ^{o}$$ and $$-12 ^{o}$$ for each component and the amplitude of the second component is $$0.83$$ (in a normalised manner).

In this case, we can think of it like using a rectangular window on the data. As you may already know, multiplying the data in the time domain is like convolving their frequency representation. This is identical to placing a weighted (the weight being the amplitude of each frequency component of the signal) frequency response of the window, at each frequency component of the signal and adding them at each frequency bin. You can see the frequency response of a Rectangular and a Blackman (just a random choice) window in the next image If we apply the window to the time domain signal and see the conceptual wrapping happening after the window application it looks like this As you can see the edges go to zero and there is no discontinuity at the wrap around. This eliminates the high frequencies that can be seen in the spectrum of the signal with no window applied. The spectrum of the signal with and without (rectangular) windowing is shown below. As described above one can see that the high-frequency content has been eliminated. In addition to that, the frequency discrimination has been improved somewhat, but the amplitude is not accurate anymore (or at least less accurate than with the rectangular window).

So, in general, windowing can improve the situation (in most cases). The only case where the window will decrease performance is if the signal components fit exactly in one window length (thus, there will be no discontinuity at the "wraparounds"). For more information regarding windowing, one can have a look at this DSPRelated Spectrum Analysis Windows page, Wikipedia - Window Function page and at the Digital Signal Processing book by Proakis and Manolakis.

Regarding the increase of observation time, what you effectively achieve with it is to get more information about the signal. There will always be a trade-off between frequency and time discrimination (the more time you observe, the more accurate you will be in frequency, but you won't be able to say when each frequency showed up, ceased to exist and how long it lasted). By considering the "time quantization" of the digital signal, you can achieve greater frequency accuracy with each bin's bandwidth being narrower. You have to keep in mind though that, at least mathematically, you will experience the picket-fence effect (in practice, depending on the application the amount may be unimportant), but you can minimise the leakage by using windowing functions.

In addition to that, you have to keep in mind that windowing functions will always "distort" the signal, but in the frequency domain, this provides some advantages (like those mentioned above), which may or may not provide improvements, but this strongly depends on the application!