Audio spectrum analyzer on PIC32

This simple audio spectrum analyzer is based on PIC32 proto board on PIC32MX360F512L with 320×240px colour LCD (LVC75Z779 Eval Board).  The analyzer can be connected to unamplified audio source like PC’s sound card, MP3 player and so on.

Audio spectrum analyzer on PIC32

SSD1928 Module Schematic diagram

Audio spectrum analyzer on PIC32
Click to enlarge

The reference voltage of ADC is set to 1V with potentiometer connected to Vref+ pin of PIC32. Voltage of the audio signal could be negative but PIC’s ADC accepts only positive voltages. That’s why another pot is used to add 0.5V DC to audio signal. Finally coupling capacitor is used to isolate DC bias from audio source.

Audio spectrum analyzer Schematic


Software
Here’s basic main loop flowchart:

Audio spectrum analyzer on PIC32: loop flowchart

PIC’s ADC is configured to take samples at ~48kHz frequency. When each sample is converted interrupt is generated and sampled value is placed to the buffer. Sampling is completed when 2048 point buffer is full. It takes about 42ms at 48kHz sampling frequency.

Since sampling is done automatically in background we have enough time to do all calculations to previous samples while sampling new ones. First fast Fourier transform is calculated, then the results of FFT are scaled to volts or decibels and finally spectrum is drawn on LCD. At 80MHz it takes about 35ms to do all calculations and draw image on the screen.

I found FFT algorithm for this project from here. It uses fixed point arithmetic and is written in pure C without any optimisations for PIC32. I have expanded it to be able to calculate 2048 point FFT. It takes about 9ms to calculate 2048 points but I think the performance could be improved by optimizing the code for MIPS architecture.

Here’s some pictures of analyzer in action:


1kHz square wave


FM signal, carrier = 7kHz, modulated = 10kHz


AM signal, carrier = 2kHz, modulated = 5kHz

Finally the video. Frame rate of the analyzer is about 23fps.

PIC24-EVAL Schematic diagram
Here’s source code for this project. The code is written for Microchip MPLAB C32 compiler.

mehilainen.homeip.net

You may have to register before you can post comments and get full access to forum.
Fragments of discussion:Full version of discussion »
  • Hi! Thank You for this project, it's working well for me as well. As I noticed, the lowest frequency begins at about 190 Hz. Is it any possibility it begin at 60 Hz, or 100 Hz? Thank You in advance
EMS supplier