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

Thread: FFT draw in display

  1. #1
    Member
    Join Date
    Nov 2020
    Location
    Czech Republic
    Posts
    45

    FFT draw in display

    Hey,
    I have code for FFT and I want to draw frequency range 500-10000Hz on display 800px.
    I apply FFT on 16384 samples.
    In my FFT are many peaks in all spectrum and I want to see them all on display.

    My code:

    Code:
    fft_config_t *real_fft_plan = fft_init(16384, FFT_REAL, FFT_FORWARD, fft_input, fft_output);
    for (int k = 0 ; k < 16384 ; k++)
      real_fft_plan->input[k] = (float) vReal[k];
    fft_execute(real_fft_plan);
    Then I make some calculations for values and save to array vReal.
    Now I need to draw it on display:

    Code:
    for(int i= 10;i < 795; i++) // draw from 10 to 795 px - but I have 8192 (nFFT/2) values
       { 
        tft.drawLine(i,25, i, 155,RA8875_BLACK);  
        tft.drawLine(i,155, i, 155 - vReal_G[i],RA8875_YELLOW); 
       }
    In this case I can see on display just frequency from 10 to approx 800Hz.
    I need somehow average it or zoom it to see 500-10000 Hz with main peaks.
    Any idea how to do it?

    Thanks!

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    This would be a quick and dirty start which will average every 8 samples up to sample 6360:
    Code:
    for(int i = 10; i < 795*8; i += 8) // draw from 10 to 795 px - but I have 8192 (nFFT/2) values
      {
        int sum = 0;
        for(int j = 0;j < 8;j++) {
          sum += vReal_G[i+j];
        }
        sum /= 8;
        tft.drawLine(i,25, i, 155,RA8875_BLACK);
        tft.drawLine(i,155, i, 155 - sum,RA8875_YELLOW);
      }
    Another way to tackle it would be to just reduce the size of the FFT - unless you need the 8192 samples for something else.

    Either way, one thing you can do to speed up the display is remember the previously displayed value and only draw a line if the value changes.

    Pete

Posting Permissions

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