This is the sixth post in the blinkdagger signal processing series.

Matlab Logo Windowing is a valuable technique that is used primarily to reduce/redistribute sprectral leakage (error in the fft measurement) to better represent the frequency spectrum of the data. In addition, windowing can make it easier to identify peaks at specific frequencies, and can help in accurately indicating the amplitude level of a peak. One of the quirks of using the fft command is the implied periodicty of the input signal. If your signal doesn’t end and start at the same value, then this can lead to spectral leakage in the fourier transform. In this tutorial, we will explain what spectral leakage is, why it occurs, and how windowing can help resolve this problem.

Contents

What is Spectral Leakage?

Spectral leakage refers to the small amounts of signal energy that are observed in frequency components that do not exist in the original waveform. How does spectral leakage come about? Let’s quickly investigate this matter. Let’s start with a sine wave that has fundamental frequency at 10 Hz.

Sine Wave Equation

Example Sine Wave #1 with Frequency Spectrum

fo = 10;   %frequency of the sine wave
Fs = 200; %sampling rate
Ts = 1/Fs; %sampling period
t1 = 0:Ts:1 - Ts; %time vector
n1 = length(t1); %number of samples

y1 = 2*sin(2*pi*fo*t1);
%plot the curve in the time domain
sinePlot1= figure;
plot(t1,y1)  %plot the sine wave

Sine Wave #1

When we take the fft of the above signal, we expect to get the following result:

[Y1,freq1] = positiveFFT(y1,Fs);  %compute the frequency spectrum
%positiveFFT is a custom function that is included in the source file
fftPlot = figure;
stem(freq1,abs(Y1))  %plot the frequency spectrum

fft of Sine Wave #1

So far, so good. Nothing that we did not expect.

Example Sine Wave #2 with Frequency Spectrum

Now, lets look at the following sine wave:

fo = 10;   %frequency of the sine wave
Fs = 200; %sampling rate
Ts = 1/Fs; %sampling periodl
t2 = 0:Ts:0.95 -Ts; %time vector(notice the difference here!)
n2 = length(t2); %number of samples

y2 = 2*sin(2*pi*fo*t2);
%plot the curve in the time domain
sinePlot2 = figure;
plot(t2,y2)

Sine Wave #2

It looks pretty similar to the previous sine wave right? (It does look similar, but you should notice that the plot ends a little bit before Sine Wave #1) Let’s see what the fft of Sine Wave #2 looks like:

fftPlot2 = figure;
[Y2,freq2] = positiveFFT(y2,Fs); %compute the frequency spectrum
%positiveFFT is a custom function that is included in the source file
stem(freq2,abs(Y2)) %plot the frequency spectrum

fft of Sine Wave #2

If you compare the frequency spectrums of the two sample waves, you will notice that they differ greatly. The extra energy around 10 Hz is what we refer to as Spectral Leakage! What is going on here? Weren’t the two example sine waves pretty much identical?

Implied Periodicity in the fft

The fft command assumes that the input signal is periodic from negative infinity to infinity. We’ll illustrate what this means with a simple example. Lets take Sample Wave #1 and repeat it three times. We’ll also do the same for Sample Wave #2.

t3 = (0:length(y1)*3-1)/Fs; %new time vector
repeatingSignal = figure;
subplot(2,1,1)
plot(t3,[y1 y1 y1]) %plot 3 iterations of sine wave #1
ylabel('Sample Wave #1','FontWeight','bold')
title('Repeating Signal','FontWeight','bold')

t4 = (0:length(y2)*3-1)/Fs; %new time vector
subplot(2,1,2)
plot(t4,[y2 y2 y2])  %plot 3 iterations of sine wave #2

repeating signals

Now, just imagine that we infinitely repeated the input signal. Did you notice that the second sine wave has discontinuities? This is because the original signal didn’t start and end at the same place! This is the very reason why we get spectral leakage!!

Next Time

In the next tutorial, we will discuss how windowing can help us alleviate this problem. Essentially, windowing forces a signal to start and end at zero so that the modified signal emulates a periodic signal. In the next tutorial, we will continue the discussion on windowing and show some examples on how windowing can help mitigate spectral leakage.

Download Source Files and References

Download the source files here.

Reference