Linear to semi-logarithmic scale
I've got some FFT results I want to draw with a log10 scale on the
Ximena Skinner
Answered question
2022-07-01
Linear to semi-logarithmic scale I've got some FFT results I want to draw with a log10 scale on the x axis. Let's call nBins the number of bins (window size / 2) nPixels the total number of pixels We will assume that the frequencies are between 20 Hz and 22050 Hz For each bin, I'd like to find out the corresponding pixel. First, converting between a bin and it's corresponding frequency is easy : freq= nBins/22050* numBin +20 Now I have freq it would be easy to draw it on a linear x scale but how to draw it on a log10 x scale ? My math is really rusty and this doesn't seem trivial (maybe it is ...)]
Answer & Explanation
trantegisis
Beginner2022-07-02Added 20 answers
as I understand your question, when you are at freq = 20Hz, you want to be at pixel 0, and when freq = 22050Hz you want to be at pixel nPixels so that you're using the full amount of space available for the problem at hand. To do this, you need to scale the logarithm of your frequencies to the appropriate size. We do this with a constant scaling multiple in front of the log function. In order to put the origin of the x axis in the right place, we also have to add a constant term. This would look like a linear function , except the in this case is a log function of frequency, so . I am going to shorten this using logarithmic identities to for some constant For your particular problem, we would want to be at pixel 0 for , and the only way to get 0 is to make sure the inside of the logarithm is equal to 1. so in this case, . For we want to be at pixel , so
So , which is approximately . Thus, given a frequency , it should be located at about Hopefully that lines up with the answer you've found empirically