2
$\begingroup$

I was trying to combine output of a $2n$ point Real FFT to generate custom FFT bins.

For example the FFT generates components at equally spaced frequencies $f_0,f_1,f_2 ...f_{n-1}$

$f_0$ = $0$ Hz
$f_{n-1}$ = SamplingFrequency/2

Instead of generating a linearly distributed bins, I want to create custom bins. For example: How do I create a bin for frequency $(f_0+f_1)/2$. Can simply average $bin_0$ and $bin_1$ ?

  • 0
    If you write out words like "sampli$n$g freque$n$cy" and "bin", they get interpreted as a juxtaposition of variables names and formatted accordingly (e.g. italicized). You can include text in formulas using the `\text{...}` command. (Also you forgot to convert several of the indices to subscripts.)2012-12-18

2 Answers 2

2

Certainly nothing keeps you from avergaging bin $0$ and bin $1$; the question is what you're trying to calculate. The FFT calculates a discrete Fourier transform, and you're trying to interpret it as something continuous. That's possible, but it requires a careful interpretation.

One interpretation goes like this: The data you transform represent samples taken over a finite interval with equal spacing. The Fourier coefficients that the FFT computes are the discrete Fourier transform of the data, which you can interpret as the Fourier sum for the unique periodic function that interpolates the sampled values and is band-restricted by the Nyquist frequency. You can view these Fourier coefficients as the coefficients of delta peaks at the corresponding frequencies in a continuous Fourier integral. Now if you restrict the periodic function to a single period, you effectively multiply it by a rectangular window, and in Fourier space that corresponds to convoluting it with the $\operatorname{sinc}$ function. Thus each of the delta peaks gets replaced by a copy of the $\operatorname{sinc}$ function centred at the corresponding frequency. Since these $\operatorname{sinc}$ functions are $1$ at their central frequency and $0$ at the frequencies corresponding to all other coefficients, this gives rise to a continuous function that interpolates between the discrete Fourier coefficients. It's this function that has a well-defined interpretation, namely as the Fourier transform of a single period of the band-limited interpolation of your data.

Thus, to get something meaningful, you'd have to interpolate with $\operatorname{sinc}$ functions, so you'd need a full sum over all the coefficients to get a single interpolated value, not just a combination of the two adjacent coefficients. However, if your data are sufficienly well-behaved, it will often be a good approximation to do linear interpolation instead as you suggested.

  • 0
    Thanks for pointing out. I missed the last paragraph of his answer!2012-12-21
1

Just to add to add to joriki's answer: if what you are trying to do is a "resampling" of the discrete Fourier transform, and if the resampling factor is near one, a linear or cuadratic interpolation is often enough.

If you have a large and-or varying resampling factor, (in particular if you want to do some remapping to a logarithmic scale), where several bins of the original FFT are roughly mapped to a new single bin, a simple average of the original bins can suffice.

But, just as with other general resampling procedures, it's usually better to employ some "window function" to minimize aliasing effects (which amounts to performing a weighted average; the plain average would correspond to a rectangular window). Typically, in linear FFT to MEL-scale (or MEL -like, i.e., logarithmic frequency scale) a varying triangular window (with overlaping) is applied, which is often called a "filter bank"; don't let the name intimidate you, it's just a weighted average. See eg here or here or here.