Assume I have an array of floating points that contain the last 8192 samples played. How would I convert that array to 32 frequency bins that are spaced from 0Hz - Nqyst?
Depends on what you want to do with it. Some possibilities:
- Short Time Fourier Transform with a 64 FFT length will give you 33 bins as a function of time. These are actually 31 "normal" bins (with amplitude and phase) and 2 "half" bins that only have amplitude (DC and Nyquist) and half the bandwidth. If your input vector is complex, you can use an FFT length of 32 and you get 32 "normal" bins.
- Do an FFT over the whole sequence, create any bins you want in the frequency domain and simply integrate the energy in each bin. However this will discard all phase information.
- If you really need 32 bit equally spaced complex frequency bins for a real valued input signal you can do "half bin rotation" of the frequency sampling grid. You basically multiply your sequence with a exp(-jw/N * (n/2)) before the FFT grid. YOur first bin would then go from 0Hz to 1378Hz instead from -689Hz to 689 Hz.
It really depends on how you want to do your frequency binning. Do you care about the location of center frequencies or the band edges? Do you need sharp edges or overlaps? Do you need amplitude and phase? Is the input real or complex? All this factors into the correct binning procedure.
Let's look at the example of calculating the A-weighted sound pressure level from a time domain microphone signal. Your input is real valued, i.e. you can ignore the negative frequencies. You care about center frequencies but you need a log spaced grid. You want some overlap between the bands so that frequencies that are close to a band edge have some contribution in both bands. However the overlap should conserve energy, so the overall energy is frequency independent. We don't care about phase, so we can simply integrate energy inside a band to get a single number.
As this example shows, frequency binning is application dependent on not as trivial as one might initially think.