I have read about spectral leakages in other posts here. From what i understand, it occurs because you dont have an integer number of time periods in your sampled data. By default a rectangular window (=no window) is used and it corresponds to a sinc function in the frequency domain. If we have an integer number of time periods in our data the zeros of the sinc cancel out every other frequency component giving us the correct value. If however we dont have an integer number of time periods in our sample, that corresponds to a shifted sinc and this is convolved with the frequency spectrum of the original resulting in leakage. In essence there is always leakage but it is masked by carefully choosing the number of samples to be an integer number of time-periods.

I wrote a simple program in scilab to see if i can remove this leakage with windowing. f(x) = Asin(20*pi*X). Maximum frequency = 10, sampling rate Fs = 30. I use a sinc window. A finite sinc window leaks in the frequency domain. For n samples the FFT(sinc) = (m1, m2, m3,...mn), m2 to mn are mirrored about the center. I changed the FFT(sinc) to FFTnew = (-m1, m2/abs(m2)-m2,-m3,-m4,...,mn/abs(mn)-mn) so that abs(FFT + FFTnew) = (0,1,0,...,1). I now create a new window called modifiedSincWindow = sinc + InvFFT(FFTnew). (in scilab invFFT(FFT(f(x)) = f(x), no scaling issues). the abs(FFT(modifiedSincWindow)) has all 0s except for 2 1s as expected. This is obvious from the linearity property of the DFT.

a) NumSamples = 30. FFT(f(x) x modifiedSincWindow) gives me the correct amplitude A.

b) NumSamples = 31. FFT(f(x) x modifiedSincWindow) does not give me the correct amplitude A. it doesnt even look anything like in (a). why is this? if we are convolving the frequency spectrum of the signal with the spectrum of the modifiedSincWindow and since the component falls in some bin shouldnt we get the same result as in (a). the spectrum for the modifiedSincWindow is exactly 1 for a particular bin and zero for the rest. And convolving this with the spectrum of f(x) should get me the same result as (a) but it isnt. Can anyone help me understand what exactly is happening here? why is it not working as expected? thanks for your comments.

EDIT: Added scilab code below.

My question basically boils down to if we are getting leakage because of the convolution by the sinc function, why not multiply the signal with a window whose magnitude response is 1 for one bin and zero for the rest. This should give us the right amplitude value irrespective of whether the number of samples is an integer number of time periods or not. right?

maxFreq = 10;
T = 3*maxFreq;

numSamples = T; %%(b) numSamples = T+1
timeRes = 1/T;

%%sampling the sinc function

sincVals = zeros(numSamples);

for i = 1:1:numSamples
    xval = (i - numSamples/2) * timeRes;
    if(xval == 0) %%then
        sincVals(i) = 1;
        sincVals(i) = sinc(xval);

fftVals = fft(sincVals);

modifiedFFTArray = zeros(numSamples);

for i = 1:1:numSamples
    modifiedFFTArray(i) = -fftVals(i);

modifiedFFTArray(2) = fftVals(2)/abs(fftVals(2)) - fftVals(2);
modifiedFFTArray(numSamples) = fftVals(numSamples)/abs(fftVals(numSamples)) - fftVals(numSamples);

invModified = ifft(modifiedFFTArray);

%%sincDiffs magnitude response is 0 for all bins except for 2 bins where it is 1

sincDiff = sincVals + (invModified);
signal = zeros(numSamples);

for i = 1:1:numSamples
    xval = i * timeRes;
    signal(i) = 1.5*cos(2*pi*maxFreq*xval) * (sincDiff(i));

binRes = T/numSamples;

binID = 1+floor(maxFreq/binRes); %%indexing is from 1 so add 1
fftVals = fft(signal);

  • $\begingroup$ Can you simply paste the code, instead of describing it in your own words? This will really help to address your question and answer it. Thanks. $\endgroup$
    – jojeck
    Commented Mar 15, 2014 at 20:58

3 Answers 3


First, very short explanation is that if you do that, it will make Heisenberg angry and he will sent a Shrodinger's Cat after you ;) Accordingly to Uncertainty Principle you must always sacrifice something. If your signal is finite in time domain (it always is in our applications), then it's spectrum must be infinite. Take for example rectangular pulse of some given length. We know that its FT is a $sinc$ function, which side-lobes are oscillating around X-axis towards infinity (well, in digital domain up to sampling frequency).

So what you stated (if I understand you correctly) is: instead taking window with spectrum sinc-like, we want it to be a delta-like: one at the centre and zero elsewhere. That would require your signal to be infinite in the time domain. Let's imagine then: you are making your signal longer and longer. Starting at some initial point it has $N$ samples, so the frequency resolution is $f_s/N$ (probably you can observe some leakage). You are extending it further up to $100\cdot N$ samples which makes your frequency resolution 100 times better, squeezing your $sinc$ function. At some point, when signal is going to be infinite, your frequency resolution is infinitesimal and $sinc$ looks like $\delta$. You would not have any problems with leakage. But obviously - we cannot do that.

  • $\begingroup$ i was trying to create a window whose spectrum is delta-like. to do this, a) start with a finite sinc window and compute its FFT b) subtract the spectrum of delta from the spectrum of the sinc window call this modifiedSinc c) inverse FFT on the modifiedSinc and add it to the original sincWindow. $\endgroup$
    – user7502
    Commented Mar 15, 2014 at 22:13
  • 1
    $\begingroup$ Subtracting a delta function on one domain is the same as adding a sinusoid of the opposite phase in the other domain. $\endgroup$
    – hotpaw2
    Commented Mar 15, 2014 at 22:18
  • $\begingroup$ a spectrum that is delta-like and the spectrum of a complex sinusoid of a particular frequency both look similar. so what is the difference? this is where i am confused. sorry i cant upvote your answers as i dont have enough reputation points. $\endgroup$
    – user7502
    Commented Mar 15, 2014 at 22:30
  • $\begingroup$ Indeed you are right, as FT of sinusoid is a sum of two shifted $\delta$'s. But you must keep in mind that it is for infinite sinusoid (Fourier Integral is from $-\infty$ to $+\infty$). So when you are analysing finite signals, you are in fact multiplying them by rectangular window, ergo you are convolving spectrum of sinusoid (two $\delta$'s) with $sinc$ function. That's a must. $\endgroup$
    – jojeck
    Commented Mar 15, 2014 at 22:40
  • 1
    $\begingroup$ @jojek: (from abyss.uoregon.edu/~js/21st_century_science/lectures/lec14.html): "The uncertainty principle, developed by W. Heisenberg, is a statement of the effects of wave-particle duality on the properties of subatomic objects." -- 'Subatomic' is key here -- macroscopic physics such as acoustics are a different matter. $\endgroup$ Commented Mar 16, 2014 at 5:29

I see you've already accepted one of the answers, but you (or others) might be interested in: R. J. Webster, “Leakage Regulation in the Discrete Fourier Transform Spectrum,” Proc. IEEE, vol. 68, no. 10, Oct. 1980, pp. 1339-1341. -- Among the statements:

"A point insufficiently emphasized in the literature is that leakage in the DFT spectrum is a phenomenon of calculation. The continuous distribution of leakage energy is determined only by the form of the window, and the DFT is a kind of lattice through which this continuous function is observed. Because the lattice is fixed by convention, and the leakage distribution shifts according to the frequency of the signal, the discrete leakage components become dependent on the signal frequency."

(regarding the familiar 'picket-fence' effect): "The reader should note, importantly, that this effect is not a property of the harmonic nature of (the signal frequency fzero), as seems often suggested, e.g., [5], [6], but of the essentially arbitrary way G(f - (the signal frequency fzero)) is evaluated. The apparently special relationship between harmonic frequencies and the rectangular window, in which the zeros of the window transform coincide precisely with the DFT sampling frequencies, is neither significant nor unique."

The author then goes on to show an example of using a shifted sum-of-cosines window centered on f = 10.25 that reduces the leakage to zero beyond bin 11 of his FFT when given an input signal of that frequency.

  • $\begingroup$ Would you know of a copy of that paper on the web, not paywalled ? Thanks $\endgroup$
    – denis
    Commented Feb 2, 2018 at 11:33

The transform of a signal (or window) that appears in exactly 1-bin of an FFT is a pure complex sinusoid, periodic in the FFT aperture. Multiplying by a periodic complex sinusoid in the time domain merely circularly shifts the spectrum in the frequency domain by an integer number of bins (as it's the equivalent of circular convolution with a shifted impulse).

If you multiply in the time domain by a complex sinusoid that is not exactly periodic in the FFT aperture, you might be able to shift the spectrum by a fractional bin width to put a specific frequency of interest (not necessarily a spectral peak) right at a bin center, but that sinusoidal window will leave artifacts of its own.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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