# FFT and Spectral Leakage

(14 votes, average: 4.93 out of 5)

Frequency Transform is used to study a signal’s frequency domain characteristics. When using FFT to study the frequency domain characteristics of a signal, there are two limits : 1) The detectability of a small signal in the presence of a larger one ; 2) frequency resolution – which distinguishes two different frequencies.

For more similar discussions check this ebook : Simulation of Digital Communications using Matlab – by Mathuranathan Viswanathan

In practice, the measured signals are limited in time and the FFT calculates the frequency transform over a certain number of discrete frequencies called bins.

### Spectral Leakage:

In reality, signals are of time-limited nature and nothing can be known about the signal beyond the measured interval. For example, if the measurement of a never ending continuous train of sinusoidal wave is of interest, at some point of time we need to terminate our observation to do further analysis. The limit on the time is also posed by limitations of the measurement system itself (example: buffer size), besides other factors.

It is often said that the FFT implicitly assumes that the signal essentially repeats itself after the measured interval and hence the FFT assumes the signal to be continuous (conceptually, juxtapose the measured signal repetitively). This lead to glitches in the assumed signal (see Figure 1). When the measurement time is purposefully made to be a non-integral multiple of the actual signal rate, these sharp discontinuities will spread out in the frequency domain leading to spectral leakage. This explanation for spectral leakage need to be carefully investigated.

## Experiment 1: Effect of FFT length and frequency resolution

Consider a pure sinusoidal signal of frequency $$f_x = 10 \;Hz$$ and to represent in computer memory, the signal is observed for $$1$$ second and sampled at frequency $$F_s=100 \; Hz$$. Now, there will be $$100$$ samples in the buffer and the buffer will contain integral number of waveform cycles ($$10$$ cycles in this case). The signal samples are analyzed using N-point DFT. Two cases are considered here for investigation : 1) The FFT size $$N$$ is same as the length of the signal samples, i.e, $$N=100$$ and 2) FFT size set to next power of 2 that fits the signal samples i.e, $$N=128$$. The result are plotted next.

One might wonder, even though the buffered samples contain integral number of waveform cycles, why the frequency spectrum registered a distinct spike at $$10 \; Hz$$ when $$N=100$$ and not when $$N=128$$. This is due to the different frequency resolution, the measure of ability to resolve two different adjacent frequencies

For case 1, the frequency resolution is $$\Delta f = f_s/N = 100/10 = 1 Hz$$. This means that the frequency bins are spaced $$1 \; Hz$$ apart and that is why it is able to hit the bull’s eye at $$10 \; Hz$$ peak.

For case 2, the frequency resolution is $$\Delta f = f_s/128 = 100/128 = 0.7813 Hz$$. With this frequency resolution, the x-axis of the frequency plot cannot have exact value of $$10 \; Hz$$. Instead, the nearest adjacent frequency bins are $$9.375 \; Hz$$ and $$10.1563 \; Hz$$ respectively. Therefore, the frequency spectrum cannot represent $$10\;Hz$$ and the energy of the signal gets leaked to adjacent bins, leading to $$spectral \; leakage$$.

## Experiment 2: Effect of time-limited observation

In the previous experiment, the signal wave observed for $$1$$ second duration and that fetched whole $$10$$ cycles in the signal buffer. Now, reduce the observation time to $$0.91$$ second and re-run the same code, results below. In this case, the signal buffer will have $$9.1$$ cycles of the sinewave, which is not a whole number. For case 1, the frequency resolution is $$1 \; Hz$$ and the FFT plot has registered a distinct peak at $$10 Hz$$. Careful investigation of the plot will reveal very low spectral leakage even in case 1 (observed the non-zero amplitude values for the rest of the bins).This is primarily due to the change in the observation interval leading to non-integral number of cycles within the observed window. The spectral leakage in case 2, when $$N=128$$, is predominantly due to mismatch in the frequency resolution.

From these two experiments, we can say that
1) The mismatch between the tone of the signal and the chosen frequency resolution (result of sampling frequency and the FFT length) leads to spectral leakage (experiment 1).
2) Time-limiting an observation (at inappropriate times), may lead to spectral leakage (experiment 2).
3) Hence, the spectral leakage from a larger signal component, if present, may significantly overshadow other smaller signals making them difficult to identify or detect.

### External Resources:

Recommended Signal Processing Books

• Pingback: Computation of Power of a Signal in Matlab()

• LP

Very interesting, cheers !

• Pingback: SPECTRAL LEAKAGE II - maxwell's muse, llc()

• Seba

Excellent article, thanks a lot! I don’t understand why in the fig3, the FFT has spectral leakage, given the measured signal is an integral number of cycles.

• Even though it has integral number of cycles, the observation time is much shorter. The spectral leakage in this case is due to “limited observation interval#

• Seba

I kindly do not agree with that. It is necessary just 1 period to entirely determine its DFT, making sure that we do not add spurious points at the edges. Cheers

• MJEngineer

He is right Seba. Observing the signal for a finite time we effectively apply a square window on it. This leads to the window response overlap with the signal spectrum. Different shape windows can be used depending on need but every one introduces some leakage into the spectrum: https://en.wikipedia.org/wiki/Window_function

Thanks for the nice post Math! Neatly explained.

• SSS

I think Seba is right. If you see the code supposedly for sine wave with 1 second window (7 exact cycles of the sine wave), you can see that it is infact not the case. For it to be exactly 7 cycles, the line should be,
t=0:1/Fs:(observationTime – 1/Fs).

In the present situation, the code is adding an extra zero at the end (effectively, it is padding a zero) that makes it a non-perfect sinusoid, and that is the reason for leakage.

• Good catch. Yeah I missed the -1/Fs part in the code and was oblivious to the fact that 1 sec duration should entirely contain integral number of cycles without any glitches. Thanks for finding that. !!!

• ArrozConCostra

As a complement to what you just explained, you might as well have mentioned coherent sampling, which is used to improve FFT visualization a little bit more. Excellent explanation anyway. Thanks

• ArrozConCostra

I have a question regarding the way you are calculating FFT here. It’s actually not straight forward to 100% understand every step regarding the FFT calculation, as sources seem to slightly disagree, mainly on scaling factor applied to FFT. From your code:

NFFX=2.^(ceil(log(length(x))/log(2)));
NumUniquePts=ceil((NFFX+1)/2);
FFTX=FFTX(1:NumUniquePts);
MY=abs(FFTX);
MY=MY*2;
MY(1)=MY(1)/2;
MY(length(MY))=MY(length(MY))/2;
MY=MY/length(x);
f1=(0:NumUniquePts-1)*Fs/NFFX;

I can see that you multiply by 2 to account for the half FFT that you threw away. Is this correct?
What I do not get is why you then “undo” that 2x scaling factor to the first and last value of vector MY ?

Thanks

• siva kumar reddy

Solid discussion…thnk u so much for sharing…….just rock it………

• Hao Yi

the two sources of spectral leakage have confused me for a while. This is exactly the article I’m look for. excellent work! thank you!

• Pingback: Spectral Leakage II | Israel Vaughn()

• Eugen

How can it be explained, that there is a kind of leakage effect if we take 9 8 7 down to 1 cycle(s) of the signal? Or is it the fourier transform of a rect window, what can be seen (so in spectral dimension it will be a sinc)?

• Lets do the experiment. Set observationTime=0.1 (equivalent to 1 cycle, fetches 10 samples). Now you have the choice of setting the DFT length.

Case 1: DFT length set equal to integral multiple of number of samples in the observation window. Result shows, perfect spikes at +/-10Hz frequencies. Same will be true for the cases where the DFT length is set to any multiple of 10

Case 2: Set DFT length to some arbitrary number that is not a multiple of samples in the observation window. Examples shown for N=64,128,256. The frequency leaks to all other bins. Examples below

• Eugen

If I do this experiment i get the result as seen below (setting N=100 and observationTime=0.1) . https://uploads.disquscdn.com/images/e249e89cca959d3de20e14ce5185ca98cbcfdc6f9e0121c1826de5e667d2bcdc.png

The result as can bee seen in the first picture of yours, i only get if i set N to 10 (Though the title says its N=100, because it’s not a ‘variable’in the title).

• Here is the updated code, where I have replaced all the hard-coded values with variables. Now, you should see similar results as shown here

clear all; clc;
Fx=10; %Frequency of the sinusoid
Fs=100; %Sampling Frequency
observationTime = 0.1; %observation time in seconds
t=0:1/Fs:observationTime-1/Fs; %time base
x=sin(2*pi*Fx*t);%sampled sine wave

N=length(x); %DFT length same as signal length
X1 = 1/N*fftshift(fft(x,N));%N-point complex DFT of x
f1=(-N/2:1:N/2-1)*Fs/N; %frequencies on x-axis, Fs/N is the frequency resolution

figure;
subplot(3,1,1);stem(x,’r’)
title(‘Time domain’);xlabel(‘Sample index (n)’);ylabel(‘x[n]’);
subplot(3,1,2);stem(f1,abs(X1)); %magnitudes vs frequencies
xlim([-Fx-20,Fx+20]);title([‘FFT, N=’,num2str(N),’, Delta f=’,num2str(Fs/N)]);xlabel(‘f (Hz)’); ylabel(‘|X(k)|’);

N=128; %DFT length
X2 = 1/N*fftshift(fft(x,N));%N-point complex DFT of x
f2=(-N/2:1:N/2-1)*Fs/N; %frequencies on x-axis, Fs/N is the frequency resolution

subplot(3,1,3);stem(f2,abs(X2)); %magnitudes vs frequencies
xlim([-Fx-20,Fx+20]);title([‘FFT, N=’,num2str(N),’, Delta f=’,num2str(Fs/N)]);xlabel(‘f (Hz)’); ylabel(‘|X(k)|’);

• Eugen

Thanks for the updated code. Is it in this case correct, that only the same length of the signal and FFT provide a leakage free spectrum? Because if I try integral multiples (e.g. N=100 -> frequency res. is 1 Hz), i also get leakage kind spectrum (as mentioned in the first post of mine).

And for example if i set the observation time to 0.6 (6 cycles), and set N=60 i will get a leakage free spectrum.

I’m sorry for asking this, but i’m struggeling right now with this kind of topic.