fourier transform for non-stationary signal
The discrete Fourier transform works on the assumption that your signal is periodic.

So, say we start with this arbitrary time-domain signal:



If it's periodic, we should be able to repeat it:



Well I guess that works, but we've introduced a discontinuity. This is like adding a square wave to your signal: you are going to see a new frequency component emerge equal to the DFT period, plus all of its odd harmonics.

In other words, the DFT sees any discontinuities even if they are at the ends of the signal. In fact, since the signal is periodic, it doesn't matter if we rotate all the inputs. If we do that with our original, we end up with:



This is exactly the same input as the first, as far as the DFT is concerned.

A window function works by tapering the ends to some similar value (usually 0) gradually, thereby making them equal. But it does so gradually, so that a minimum of extra frequency components are introduced. If we apply a window function to our original signal, you get something like this:



Which when duplicated, gives you:



or rotated:



No discontinuities! Now our non-periodic signal looks like a periodic signal, and we made it so while introducing a minimum of frequency-domain distortion. Of course, different window functions define "minimum distortion" in different ways, according to what you are trying to accomplish with the transform.