1
$\begingroup$

I'm trying to program a spectrum analyser in C++ but I'm faced with a conceptual problem : how to map the results of the FFT to an image ?

Let me detail : I'm doing all this in a dynamic way.

  • I have chunks of audio data as float [-1;1] arriving to my class.
  • I put them in a circular buffer which has the same size as my FFT window
  • I apply a Hann(ing) windowing function
  • I apply an FFT to the result.

This part works great.

Now the result of my FFT is a two dimensional array (my library automatically does the sqrt(re^2 + im^2) part) with bin indexes and amplitudes.

My goal is to draw this result from time to time into a window. The problem is, the window has way less pixels than there are bins (if my buffer size is 65536, I have 32768 bins), so I have to do some kind of "averaging". I could do a mean, a root square mean, take the maximum, etc etc ... I have no idea what is the best method to use ? The application of this will be music, more specifically, detect frequency masking by plotting several semi-transparent sepectrums on the top of each other.

Any advice on a good way to do that would be much appreciated

$\endgroup$
2
  • $\begingroup$ You've already hit on the ways to compress the spectrum to fit the aperture that you have to visualize it in (average, maximum, minimum, etc.). There really isn't a "best solution" for this problem, as what you would want to do is likely application-specific. $\endgroup$
    – Jason R
    Commented Feb 25, 2014 at 13:31
  • $\begingroup$ Thanks Jason. I agree with the fact it's application specific. My goal is to have a reasonably accurate draw for musicians to interpret the results in a helpful way. It must be fast and accurate $\endgroup$
    – Dinaiz
    Commented Feb 25, 2014 at 13:59

2 Answers 2

1
$\begingroup$

Actually, what do the squared magnitude FFT result represent? They represent the total energy in a given frequency bin. So to downscale your results to less bands, you can sum them. It's not even necessary to average the results - however it would have the same effect, as you map the results to an image, thus rescaling them.

However, note that if you need to rescale by something else than an power of two, you'll need to do it using supersampling, as the results won't map directly to your new bins.

$\endgroup$
2
  • $\begingroup$ Is supersampling adapted to sound applications as well ? When you say average, you're talking about standard average, i.e. : sum of values divided by number of values ? $\endgroup$
    – Dinaiz
    Commented Feb 25, 2014 at 13:59
  • $\begingroup$ I edited my answer ; what you need is actually not an average but a sum. But I was indeed talking about this standard average. You are supersampling your data to reduce its resolution. It is adapted for your application ; however note that we're doing it on the squared magnitude FFT results, not on the audio signal itself. $\endgroup$ Commented Feb 25, 2014 at 14:07
1
$\begingroup$

There are many ways to map an FFT spectrum to an image for musicians. Weighted sums of FFT magnitudes based on the frequency response or frequency discrimination bandwidths of the human ear. MIDI note width overlapping triangular windows (logarithmic with frequency in size). Etc. Usually of the log magnitude, but other scales are used as being better mappings to human loudness perception curves. Books and research papers on audiology and the psychology of music or hearing publish tons of these curves.

$\endgroup$

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.