2
$\begingroup$

Are there ways to reduce the smearing / spectral leakage of zero-padding interpolated data?

I learned that, given a small collection of samples, one can increase the frequency resolution of an FFT operation by interpolating the sample size by appending zeros. This makes it easier to identify a peak frequency that would otherwise fall between bins of the original samples, but it also increases smearing.

To illustrate this, I generated 4 cycles of a 50hz sine wave at a sample rate of 48khz. This resulted in 3,840 samples, interpolated to 32,768 samples, and ran the results through FFT:
(written in Kotlin and using JTransforms for FFT operations) Zero-padding interpolated FFT results

The smearing makes sense as zero-padding does not fundamentally increase the amount of useful data. Consequently, I don't expect to be able to eliminate smearing completely (as nice as it would be). But, it would be nice if there were filters/algorithms/etc that reduce the severity given we know how many samples were padded.


Additional context, if helpful:
I am building an open-source light organ that colors LEDs based on the average frequency (weighted by magnitude) between 20hz and 120hz. Given that this is processing music in real time and updating the LEDs accordingly, low latency is essential.

I am using a buffer to increase responsiveness, but increasing my buffer size necessarily increases how far back in time I am looking, thus increasing perceived latency. I've found that 4096 samples @ 48khz (aka: 85ms) is the largest sample size before the delay becomes a nuisance.

I have identified some compromises if smearing cannot be overcome, but would much prefer to have cleaner data to work with.

$\endgroup$
5
  • 1
    $\begingroup$ Does this answer your question? Where do we use windowing? $\endgroup$
    – TimWescott
    Jan 12, 2023 at 1:09
  • $\begingroup$ I don't believe so. The sine wave I generated perfectly starts and ends at zero, so I do not believe I need a window filter for my example. That said, I am using the Hann window in my project (prior to interpolation). Is there something particular in that post that you think I should be considering? $\endgroup$ Jan 12, 2023 at 1:17
  • 1
    $\begingroup$ If you send an integer number of complete sinusoidal cycles to the DFT, you will have no smearing. You should have discrete spikes in two bins and the rest of the bins should be zero. $\endgroup$ Jan 12, 2023 at 6:40
  • 1
    $\begingroup$ I like to differentiate between frequency resolution ($f_s/N$, $N$ being the number of samples given to the FFT with no zero-padding. Resolution can only be increased by using longer sequences to compute the FFT) and frequency precision ($f_s/\texttt{Nfft}$, $\texttt{Nfft}$ being the length of the input sequence with zero-padding. This can be artificially increased at-will by zero-padding, but won't actually increase your ability to resolve frequencies that are closer together than your frequency resolution. See this. $\endgroup$
    – Jdip
    Jan 12, 2023 at 10:43
  • $\begingroup$ Related $\endgroup$ Jan 12, 2023 at 12:00

2 Answers 2

1
$\begingroup$

As you correctly noted, zero-padding doesn't really increase the resolution in the frequency domain, it just interpolates the spectrum. Fundamentally, to increase true resolution in the frequency domain you need to record for longer in the time domain ($\Delta f \approx 1/T$).

As Tim noted in the comments, it's important to choose your window function carefully, as different windows trade peak width for sidelobe level (up to a point!). If the main thing you care about is peak width and you're not worried about sidelobes, choose your window accordingly (some, e.g. Taylor, allow you to specify a desired sidelobe level; the lower the sidelobe level, the wider the peak). There's no window that will enable you to compensate for a short record time, but still worth considering.

Other than that, you could look at sparse frequency estimation, which uses iterative (not great for latency!) L1 techniques (e.g., basis pursuit denoising) to constrain the estimated spectrum to be "spikey." Here's a MATLAB example.

$\endgroup$
3
  • $\begingroup$ I honestly don't know what a Taylor window is. I guess Google will tell me. But I had always thought that the window class that allows you to optimally dial in the tradeoff between size of sidelobes and width of main lobe is the Kaiser window. Does the Taylor window improve upon that? $\endgroup$ Jan 12, 2023 at 22:18
  • $\begingroup$ Might be, I'm not an expert on windows. Taylor is just one example. I usually just use a Hamming window and forget about it, unless the application calls for some care. $\endgroup$
    – Gillespie
    Jan 14, 2023 at 17:53
  • $\begingroup$ Wow. I think you're right. I always thought that Kaiser was the optimal window in that tradeoff. But I went to the scipy definitions and Taylor looks better than Kaiser in that regard. $\endgroup$ Jan 15, 2023 at 6:26
0
$\begingroup$

You can reduce the lumpiness in the spectral leakage by using the Gaussian window:

$$ w[n] = e^{-\pi \frac{n^2}{L^2}} $$

Where $L$ is the effective width of the window. The Fourier Transform of the Gaussian window is the same Gaussian function with reciprocal width in the frequency domain.

$$ W(e^{j\omega}) = L e^{-L^2 \frac{\omega^2}{4 \pi}} $$

where

$$ W(z) \triangleq \mathcal{Z}\big\{ w[n] \big\} $$

$\endgroup$
1
  • $\begingroup$ With a Gaussian window, you can even use parabolic interpolation to get a more accurate estimate between two points - ccrma.stanford.edu/~jos/sasp/… $\endgroup$
    – orchi_d
    Jan 14, 2023 at 11:44

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.