» Circuits » Audio · Video · Measurement · MCU Open-Source Platforms · Microcontrollers usage · Arduino
Arduino Realtime Audio Spectrum Analyzer with Video out!
Once again, I decided to put the old travel DVD player's screen to good use by using as an output device for the Arduino. Though the DVD mechanism is broken, the screen allows for standard NTSC composite video input.. runs on an attached rechargeable battery pack (can also power the Arduino.)
I make no guarantees, and you do so AT YOUR OWN RISK, but it should work with any TV or device that allows NTSC Video In. I am in no way responsible if you damage yourself or your equipment. This is a prototype built by an amateur, keep that in mind.
A brilliant bit of code, the TVout library for Arduino, allows you to generate composite NTSC monochrome video with only two pins and two resistors. I generally leave the resolution at the default 128×96, which translates to 16×12 text with the default 8×8 font. Running under the defaults seems to give the least amount of trouble with this library, which is a work in progress. Note that due to this library being actively worked on, there's no guarantee the code I am using will work with other IDE or Library versions. This has been developed using version 0019, though I will be testing shortly on the most recent releases. In addition, though it should not matter, I am using a 5v Adafruit Boarduino. There should be no differences, as long as your Arduino is a 5v device. Also note that old versions of Arduino which use an Atmel ATmega168 won't be able to run this, they don't have enough memory.
The other piece of the puzzle is collecting and processing audio, so we have something to display on our little display.
The first piece- data collection- is fairly standard. I use an electret microphone (which alone only produces a few mV output, far too low for our Arduino to use directly) with a transistor amplifier as the signal source, which is then sampled via the ADC on the Analog 0 pin of the Arduino.
To do spectrum analysis however, you need to capture signal over time, then process that data with what is known as a Fourier Transformation. This magical process takes a signal and breaks it down into buckets based upon frequencies found within the sample. This produces a remarkably good picture of the signal and if displayed, functions as a visual spectrum analyzer if looped over and over.
In this project, I've used code posted by a user to the Arduino forums
This post contains a library which performs both the sampling and the Fast Fourier Transformation completely in C in 8 bits, amazing fast considering that fact, and uses a few tricks to be really stingy on memory, which is at a premium on Arduino- especially with the TVout data space eating up quite a bit. Since the Atmega328 only has 2k of RAM, every byte counts. Matrix math done like this is nothing short of awesome. Best of all, it's usable as a library. Cut and paste the .cpp and .h into a new folder named "FFT" in the Libraries directory. My Arduino project code is adapted from the original code from the forum-posted Arduino program.
So, to produce our desired outcome, we just need to get the whole show together and hope it can perform. With only a handful of cheap components (a few dollars at most), it produces a perfectly usable and quite entertaining realtime 64-band video spectrum analyzer. Though not really "useful" for any real purposes, it makes an entertaining party display out of any television with a video input...
There are a lot of improvements which can be made- the first being the amplifier gain to make it a bit more responsive, and optimization of the FFT code. In reality, it's the drawing of the bars which takes the most time per sample/display cycle..not the matrix math!
The circuit required is a simple microphone and transistor amplifier, as well as two resistors connected to D8 and D9 to provide video signal.. drawing is a much bigger pain than you'd think!
Source code (Arduino)
#include TVout.h #include fix_fft.h TVout TV;
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw
News on theme: