3
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Your question is underspecified in a number of ways. What sample rate do you want on each subband? What do you want their bandwidth to be? One way to channelize a signal uniformly is using the DFT. $\endgroup$ – Jason R Feb 3 '12 at 2:43
  • 1
    $\begingroup$ What kind of result do you want for each bin? 32 sub-band channels of audio, or 32 level dB meters? Or something else? $\endgroup$ – hotpaw2 Feb 3 '12 at 6:28
  • $\begingroup$ For a small calculation like this one, you can use the DFT directly. $\endgroup$ – Phonon Feb 3 '12 at 13:30
  • $\begingroup$ Yeah, you can, with relative ease, run the samples through a "simple" FFT algorithm to generate frequency domain data and then slice the data into your "bins". This is fairly straight-forward and would permit, eg, assigning "levels" to each band. And you can then, in theory, reverse the FFT to get back to time domain, though doing so with any accuracy is quite a bit more difficult. $\endgroup$ – Daniel R Hicks Feb 3 '12 at 18:35
2
$\begingroup$

Depends on what you want to do with it. Some possibilities:

  1. 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.
  2. 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.
  3. 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.

$\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.