Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: display spectrum with logarithmically horizontal scale

  1. #1
    Member
    Join Date
    Jan 2021
    Location
    France
    Posts
    44

    display spectrum with logarithmically horizontal scale

    Hello,
    I made my first spectrum analyzer displayed on the ILI9341 using AudioAnalyzeFFT1024.
    I would like to display the frequency axis logarithmically.
    Here, for example, are the graduations:
    0 - 50 - 100 - 200 - 500 - 1K - 2K - 5K - 10k - 20khz

    (And in a second time the vertical axis in dB).

    Here is an example of these axes taken from an IOS application (spectrum anaylser):

    Click image for larger version. 

Name:	IMG_1481(1).PNG 
Views:	34 
Size:	707.9 KB 
ID:	23292

    Thank you in advance for your help
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	IMG_1481.PNG 
Views:	26 
Size:	201.8 KB 
ID:	23291  

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    692
    Then you'll need to map your x coord to frequency through an exponential function, and use that to decide which FFT bin corresponds
    to that frequency. And you'll probably want to interpolate between bins at the low frequencies for a smoother curve there, and
    average multiple bins at the higher frequencies.

  3. #3
    Member
    Join Date
    Jan 2021
    Location
    France
    Posts
    44
    for the x axis I thought to force the values ​​that interest me in an array because if I use an exponential function to draw the axes because I think that I will not have the precision between 0 and 1Khz as in my example (1 khz is at half of the axis).

    For interpolation and averaging, how will I go about it?

    thank you

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    692
    Quote Originally Posted by fred_france View Post
    for the x axis I thought to force the values ​​that interest me in an array because if I use an exponential function to draw the axes because I think that I will not have the precision between 0 and 1Khz as in my example (1 khz is at half of the axis).
    The FFT output is always equally spaced frequency bins, nothing you can do to change that, you simply want
    to present that information recscaled logarithmically. For each x position map to an actual frequency (exponential
    conversion as I said), then lookup the value in the FFT bins. Simple.

    For interpolation and averaging, how will I go about it?

    thank you
    Standard mathematical operations, thousands of online tutorials about this kind of thing, you'll probably find some
    code examples too if you search.

    You could stat just by taking the nearest bin reading - the curve will end up rather steppy at the start, but it would
    be a starting point for refinement.

  5. #5
    Member
    Join Date
    Jan 2021
    Location
    France
    Posts
    44
    thank you

    I realize that if I want to put 1 khz roughly half of the screen (x = 320/2 = 160px), the precision will not be good because of the insufficient number of bins (512 for 22Khz, so 23 for 1khz).
    So if I want to display 23 bins on 160px, that's a maximum of 7 bars that can be displayed on this half of the screen.

    I guess I need to increase the sample rate (base at 44100Hz)
    What can be done on the Teensy 4 to enhance this sampling?

  6. #6
    Member
    Join Date
    Jan 2021
    Location
    France
    Posts
    44
    I try the library fft4096 found here : https://forum.pjrc.com/threads/42221...-on-Teensy-3-6
    this seems good to me for my application, I will now think about your advice

  7. #7
    Senior Member
    Join Date
    Jul 2020
    Posts
    692
    Quote Originally Posted by fred_france View Post
    thank you

    I realize that if I want to put 1 khz roughly half of the screen (x = 320/2 = 160px), the precision will not be good because of the insufficient number of bins (512 for 22Khz, so 23 for 1khz).
    So if I want to display 23 bins on 160px, that's a maximum of 7 bars that can be displayed on this half of the screen.

    I guess I need to increase the sample rate (base at 44100Hz)
    What can be done on the Teensy 4 to enhance this sampling?
    No, you want to reduce the sampling rate or increase the number of FFT bins or both.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •