Build an Arduino Audio Spectrum Analyzer!

Try This Example at YOUR OWN RISK, It may resulting in burning of your arduino board or any other device if wrongly connected. We in anyway are not responsible for any damage incurred to you or your device. 

The TV-out (http://code.google.com/p/arduino-tvout/) library of Arduino, allows us to have NTSC monochrome (Black & White) video with only 2 pins & 2 resistors.  Generally on leaving the resolution at its default value i.e., 128x96, which there by translates to 16x12 text with default 8x8 font.  This code/example has been developed using version 0019 of Arduino IDE.  There should actually be virtually no difference, as long as Arduino operates on 5V DC power supply, i.e, no configuration changes. Older versions of Arduino which are using ATmega168 instead of   ATmega328 will not be able to run this, because the amount of memory they have is not enough!

So how to collect and process audio, so we have something to display on our little display.

The data collection process is a simple standard one. Useing an electret microphone (which will produce only a few milli Volts of output voltage, too low for Arduino to detect it) with an amplifier as the source of signal, which is then converted to digital form via the ADC of Analog pin 0 of the Arduino board.
For a spectrum analysis , we need to capture signal over the time, then process that data through discrete Fourier Transform. This will take an analog signal & convert to a Digital/Discrete Valued Signal. This will produce a remarkably good picture of the signal and if visual spectrum analyzer if looped over and over.
In this project, we have used code posted by a user to the Arduino forums
The above mentioned library will performs both the sampling and the Fast Fourier Transformation completely in C under 8 bit resolution.


Arduino Code: [Code Courtsey :radiolocman.com]

#include "TVout.h"
#include "fix_fft.h"                                               // This will perform 8 bit FFT
TVout TV;                                                             // Using Class TVout
char in[128], d[128], lpass[64];
char x=32, ylimit=90;
int i=0,v;
void setup()
    {                                         
    TV.begin(_NTSC,128,96);                             //To Init. the TV output, with a resolution 128x96.
    TV.print_str(2,2,"Realtime Printing");           // TVout library being used for x,y printing
    TV.print_str(2,11,"Spectrum Analyzer");      // printing statements in 8x8 default font value
    analogReference(DEFAULT);                       // Use default (5v) "aref"(analog reference) voltage.
    for (int z=0; z<64; z++) {lpass[z]=80;};       // fill the lpass[] array with all dummy data
    };
void loop()
    {
    for (i=0; i < 128; i++){                                   // not going for a accurate processing
      v = analogRead(0);                                      // as that will take time or too slow for this purpose
      d[i] = v/4 -128;                                            
       in[i] = 0;                                                     
      };

    fix_fft(d,in,7,0);
   
    for (i=0; i< 64;i++){                                          // for , 60Hz output
      d[i] = sqrt(d[i] * d[i] + in[i] * in[i]);         
      TV.draw_line(i+x,lpass[i],i+x,ylimit,0);         
       TV.draw_line(i+x,ylimit,i+x,ylimit-d[i],1);        
       lpass[i]=ylimit-d[i];                                   
       };                                                                   
     };
 The circuit required is a simple microphone and amplifier, as well as two resistors connected to D8 and D9 to provide video signal.


 Arduino Spectrum Analyzer with TV-Video Out - Schematic
Required Components:
(one)  "2n3904" NPN Transistor as Q1
(three)  1k Ohm Resistor as R2,R4 & R5
(one)  330 Ohm Resistor as R6
(one)  10k Ohm Resistor as R1
(one) 100k Ohm Resistor as R3
(one) Capacitor (Electrolytic), 3.3MFas C1
(one) Electret Mic as MIC1

If gain is not enough, try replacing Q1 (2n3904) with higher gain transistor or a darlington pair or even OP-AMPS can be used as they are readily available in the market, but then we have to modify the circuit a little bit. Video output is NTSC/PAL Composite, if it is necessary, a coupling capacitor & diode can be added.
Build an Arduino Audio Spectrum Analyzer
Build an Arduino Audio Spectrum Analyzer, Circuit Connection