Trybotics Logo

DIY FFT Audio Spectrum Analyzer © GPL3+

DESCRIPTION


FFT spectrum analyzer is a test equipment that uses Fourier analysis and digital signal processing techniques to provide spectrum analysis. Using Fourier analysis it is possible for one value in, for example, the continuous time domain to be converted into the continuous frequency domain, in which both magnitude and phase information are included.

The described device is exactly such a Spectral Analyzer that is made with the help of an Arduino microcontroller. Аs you can see the device is very simple and contains only a few components :

- Arduino Nano

- LCD display with a resolution of 128 by 64 pixels (ST7920 128x64 LCD)

- Two resistors (10KOhm)

- Potentiometer (10KOhm) and

- Capacitor (1 microF)

The audio input to the Arduino is on A0, with bias at the mid point by 10K to Ground and 10K to +5V. At the input we can also set a potentiometer to control the amplitude of the input signal.

Code is also simple and it uses "fix_fft" libray which was created for this purpose

The video describes several cases where different types of signals have been analyzed:

When analyzing a sinusoidal input signal, the carrier is clearly visible and By changing the frequency of the signal generator, the position of the carrier also changes.

If we bring a rectangular signal to the input, on the spectral analyzer is clearly visible the fundamental signal, as well as the three odd harmonics x3, x5 & x7.

If we bring an audio music signal to the input, this device is actually a graphics audio analyzer that can be found in more expensive audio equipments

Finally, the entire assembly is housed in a suitable box. This is not a professional tool because it has low resolution and frequency range, but can serve as a great educational tool.

Description:

09507 01
Soldering iron (generic)

Description:

Description:


FFT spectrum analyzer is a test equipment that uses Fourier analysis and digital signal processing techniques to provide spectrum analysis. Using Fourier analysis it is possible for one value in, for example, the continuous time domain to be converted into the continuous frequency domain, in which both magnitude and phase information are included.

The described device is exactly such a Spectral Analyzer that is made with the help of an Arduino microcontroller. Аs you can see the device is very simple and contains only a few components :

- Arduino Nano

- LCD display with a resolution of 128 by 64 pixels (ST7920 128x64 LCD)

- Two resistors (10KOhm)

- Potentiometer (10KOhm) and

- Capacitor (1 microF)

The audio input to the Arduino is on A0, with bias at the mid point by 10K to Ground and 10K to +5V. At the input we can also set a potentiometer to control the amplitude of the input signal.

Code is also simple and it uses "fix_fft" libray which was created for this purpose

The video describes several cases where different types of signals have been analyzed:

When analyzing a sinusoidal input signal, the carrier is clearly visible and By changing the frequency of the signal generator, the position of the carrier also changes.

If we bring a rectangular signal to the input, on the spectral analyzer is clearly visible the fundamental signal, as well as the three odd harmonics x3, x5 & x7.

If we bring an audio music signal to the input, this device is actually a graphics audio analyzer that can be found in more expensive audio equipments

Finally, the entire assembly is housed in a suitable box. This is not a professional tool because it has low resolution and frequency range, but can serve as a great educational tool.

Description:

CodeC/C++
#include "U8glib.h"
#include "fix_fft.h"


// LCD SPI SCK-EN, MOSI-RW & SS-CS

#define EN 6
#define RW 5
#define CS 4
// display set up, bar, line position L & R
#define LINEY 50
#define LINEXL 0
#define LINEXR 128

#define SAMPLES 128

#define AUDIO A0

U8GLIB_ST7920_128X64_1X lcd(EN, RW, CS); // serial use, PSB = GND

char im[SAMPLES];
char data[SAMPLES];
int barht[SAMPLES];

void setup()
{
  lcd.begin(); // inti display
  
}

void loop()
{
  static int i, j;
  int val;
  

  // get audio data
  for(i = 0; i < SAMPLES; i++)
  {
    val = analogRead(AUDIO); // 0-1023
    data[i] = (char)(val/4 - 128); // store as char
    im[i] = 0; // init all as 0
  }


  // run FFT
  fix_fft(data, im, 7, 0);

  // extract absolute value of data only, for 64 results
  for(i = 0; i < SAMPLES/2; i++)
  {
    barht[i] = (int)sqrt(data[i] * data[i] + im[i] * im[i]);
  }
  
  for(i = 0, j = 0; i < SAMPLES/2; i++, j += 2)
  {
    barht[i] = barht[j] + barht[j + 1];
  }
  
  // display barchart
  barchart(SAMPLES/4, barht); // plot SAMPLES / 4 = 32 as barchart gen cannot handle 128 bars
} 

// plot line and bar at position and height
void barchart(int n, int bh[])
{
  int i, s, w; // bars, spacing and width
  
  s = (LINEXR - LINEXL) / n;
  w = s / 2;
  
  lcd.firstPage();
  do
  {
    lcd.setFont(u8g_font_helvR08);
    lcd.drawStr(20, 10, "FFT Audio Spectrum");
    lcd.drawLine(LINEXL, LINEY, LINEXR, LINEY);
    lcd.drawStr(0, LINEY + 10, "0");
    lcd.drawStr(29, LINEY + 10, "1k");
    lcd.drawStr(59, LINEY + 10, "2k");
    lcd.drawStr(91, LINEY + 10, "3k");
    lcd.drawStr(115, LINEY + 10, "Hz");
    
    for(i = 0; i < n; i++)
    {
      lcd.drawBox(LINEXL + s * i, LINEY - bh[i], w, bh[i] + 1); // u8glib doesn't accept box height of 0
    }
      
  }while(lcd.nextPage()); 
}
LibraryC/C++
No preview (download only).

Description:

Schematic
Untitled sketch bb uptnl1prtx


YOU MIGHT ALSO LIKE