Arduino: Compensating for a Logarithmic Curve
Did you know that the scale of acoustic pitches is logarithmic? This means that, even though we perceive the scale of notes as increasing or decreasing linearly, the actual frequencies are doubling or halving with each octave.
In my Deconspectrum installation, I’m mapping acoustic frequencies to color. If I mapped them linearly, the colors would change very rapidly in the low frequencies, and then stop changing as obviously as the pitch gets higher. This is not the effect you would expect, since you want each pitch to be represented by another color.
The solution is to map frequency to color (hue) logarithmically instead of linearly. Thankfully, AVR C gives us a handy base-10 log function:
int hueFreq = log10(frequency - FREQ_MIN) * hueScale;
If we graph this, we get:
Here’s the same graph with a logarithmic frequency axis:
Handy, and highly effective!