FFTW log-log plot

I am taking a real-time fft of an audio signal using fftw library. I take the output of the fftw signal on $y$-axis and plot it against the linear frequency bins on $x$-axis.

I've noticed that spectrum analyzers use a skewed plot(log plot). I can get my $y$-axis (magnitude) into $\rm dB$ by doing 20*log(magnitude) but I don't know how to get my frequency axis($x$-axis) into log-scale. I need some help in doing that in C/C++ not Matlab.

You interpolate between the bins such that they map to your output grid (you may even need this for any kind of display where your output pixels doesn't match your transform size).

You will get the best result using sinc-interpolation on both the real and imaginary outputs (or just magnitude if you don't care). Look up lanczos interpolation for a smaller, windowed version.

To transform your x-axis into a exponential scale, you can use a mapping function like this:

min * (max/min) ^ x

where x is between 0 and 1, and max is the end of the graph - usually samplerate / 2. The graph starts at min. Here's the inverse function:

log(y/min) / log(max/min)
• the interpolation will be "grainy" down in the low octaves. – robert bristow-johnson Jan 27 '16 at 18:47
• Define 'grainy'. Sinc/lanczos will make it perfectly smooth, although the technical time/frequency resolution will stay constant, of course. – Shaggi Jan 27 '16 at 22:34
• well, the interpolation between widely-spaced points will be smooth, but the points from the FFT are more sparsely-spaced in the log-frequency scale at low frequencies than at high frequencies. a polished craggy landscape is still craggy. otherwise there is nothing preventing one from selecting an FFT length $N$ as small as one wants and just interpolating between the points for whatever resolution they want to think they are getting. – robert bristow-johnson Jan 28 '16 at 0:00
• Well, that's an interpretation of terms. Mathematically, it will be perfectly smooth (and correct). By your definition, all interpolations are grainy. That's implied, when you interpolate. The actual information content ('resolution') will stay bandlimited and constant, as I said. – Shaggi Jan 28 '16 at 1:04
• no, you're not correct. Mathematically it may be "smooth" (given the normal metric for defining "smoothness" of a function), but not necessarily correct. given a consistent scale and resolution in log-frequency (which is the scale that you are viewing the "smoothness" of the output of the FFT), there is an implication in the lower octaves of more resolution than you really have. if you used a longer FFT (with more data) you could get virtual agreement at the high frequencies, but something that looks very different at low frequencies compared to what you have with fewer, sparser points. – robert bristow-johnson Jan 28 '16 at 1:16