1
$\begingroup$

I guess this is a pretty basic question, but I am kinda stuck... So if I am remembering the DSP theory correctly, spectral leakage can occur when we take "inappropriate" combinations of the following:

1) FFT length

2) sampling frequency

3) fundamental frequency of input signal

Here is a MATLAB script for demonstrating this, in a case of a sinusoid input:

F0=10; %Frequency of the sinusoid
Fs=100; %Sampling Frequency
observationTime = 1; %observation time in seconds
t=0:1/Fs:observationTime-1/Fs; %time base

x=sin(2*pi*F0*t);%sampled sine wave

N1=100; %DFT length same as signal length
X1 = 1/N1*fftshift(fft(x,N1));%N-point complex DFT of x
f1=(-N1/2:1:N1/2-1)*Fs/N1; %frequencies on x-axis
stem(f1,abs(X1));

MY thought was that if the fundamental frequency is a multiple of the frequency resolution, then there will be no spectral leakage, since there is a bin that corresponds to the exact value of the fundamental frequency F0. However, it seems like I am wrong here... enter image description here

Can someone please explain to me what's the flaw in my rationale? Why is there leakage in the 3rd plot? Thanks in advance

$\endgroup$
  • 1
    $\begingroup$ what's the input to the FFT of the 3rd plot? is it the same 100 samples that you had at the beginning? did they get zero-padded to 200 samples? or did you extend it with another 10 cycles of the sinusoid? $\endgroup$ – robert bristow-johnson Dec 10 '15 at 18:28
1
$\begingroup$

It looks like what you are doing is only changing the DFT size (using N1 variable), this is equivalent to padding your signals with zeros up to a given length. Your signal (for N1=200) looks like:

enter image description here

It can be immediately seen that the periodic extension is not really a continuous waveform. This discontinuity is introducing the leakage effect that you are observing.

Below a quick and dirty code that demonstrates that. I did both padding of input signal in time domain, as well as calling the fft function with twice the signal size. Plots are in dB scale.

enter image description here

F0=10; %Frequency of the sinusoid
Fs=100; %Sampling Frequency
observationTime = 1; %observation time in seconds
t=0:1/Fs:observationTime-1/Fs; %time base

%% Ideal case
x=sin(2*pi*F0*t);%sampled sine wave

N1=100; %DFT length same as signal length
X1 = abs(1/N1*fftshift(fft(x,N1)));%N-point complex DFT of x
f1=(-N1/2:1:N1/2-1)*Fs/N1; %frequencies on x-axis
X1 = 10*log10(X1/max(X1));
subplot(2,1,1)
plot(f1,X1, 'o-');
title('Ideal case')
grid on

%% Padding signal with zeros
x2 = [x zeros(1, length(x))];

N2=200; %DFT length same as signal length
X2 = abs(1/N2*fftshift(fft(x, N2)));%N-point complex DFT of x
f2=(-N2/2:1:N2/2-1)*Fs/N2; %frequencies on x-axis
X2 = 10*log10(X2/max(X2));
subplot(2,1,2)
plot(f2,X2, 'o-');
hold on
grid on

%% Padding with zeros implicitly
N2=200; %DFT length same as signal length
X3 = abs(1/N2*fftshift(fft(x, N2)));%N-point complex DFT of x
f3=(-N2/2:1:N2/2-1)*Fs/N2; %frequencies on x-axis
X3 = 10*log10(X3/max(X3));
plot(f3,X3, 'r-');
title('Padding with zeros')
legend({'Padded vector', 'Twice the FFT size'})
$\endgroup$
  • $\begingroup$ Thank you! Hence, when we are to increase the frequency resolution, with no leakage effects, we should increase the observation window (accumulate more samples) to the dft size, which kinda makes sense... :P $\endgroup$ – Cobe Dec 10 '15 at 22:59
  • $\begingroup$ What can I say... Yes! ;) $\endgroup$ – jojek Dec 11 '15 at 7:50
0
$\begingroup$

It's not just the FFT length that causes the so-called "leakage". It's the window type and window's length. In the 3rd plot, you show the effects of a rectangular window half the length of the FFT.

Note that if a signal has any existence for greater than the length of a finite FFT, it gets rectangularly windowed by default. That's why certain frequencies (non-integer-periodic-in-aperture) show windowing artifacts (oft called "leakage").

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.