MSGEQ7-Based DIY Audio Spectrum Analyzer: Construction

Here's a step-by-step guide to constructing a simple 14-band (2 x 7) audio spectrum analyzer using two MSGEQ7s and a chipKIT or Arduino microcontroller development platform.

I recently used a pair of MSGEQ7 seven-band audio spectrum analyzer chips to construct a rather cool display. In this first incarnation, we end up driving 14 LEDs -- seven each for the left and right audio channels.

To set the scene before we leap into the fray, let's take a look at this short video to get an idea of where we will end up.

Since I think this will be of interest to beginners, as well as practicing engineers, I will go slowly and take the time to explain some basic concepts here and there. In these cases, I'll kindly ask anyone who already knows this stuff to bear with me.

Let's start with the fact that my music source is my iPad. Since I want to keep things as simple as possible, I intend to drive everything from the iPad's headphone socket. The problem is that plugging anything into the headphone socket disables the internal speakers. Similarly, if you are using the iPad to drive a Bluetooth boom box, for example, plugging something into the iPad's headphone socket will terminate the Bluetooth audio feed. Thus, my first step was to purchase a stereo splitter cable on Amazon. This allows me to use the output from my headphone socket to drive both an external speaker system and my spectrum analyzer.

Choosing a microcontroller
We can construct this audio spectrum analyzer project using pretty much any microcontroller that supports the required set of features. Assuming we wish to display the left and right audio channels separately, we need at least two analog inputs, two regular digital outputs, and 14 pulse-width modulated (PWM) outputs. You could get by with just one analog input and seven PWM outputs if you merged the two channels (this will be discussed later).

If you wish, you could process the audio data using an eight-bit Arduino Mega microcontroller development platform with 256 Kbytes of Flash and 8 Kbytes of SRAM running at 16 MHz. You could also use an Arduino Uno (which supports only six PWM outputs) if you would be happy combining the left and right channels and losing one of the frequency bands. I decided to use a chipKIT MAX32 platform to process the audio data stream. This little beauty boasts a 32-bit processor running at 80 MHz, along with 512 Kbytes of Flash and 128 Kbytes of RAM.

The chipKIT MAX32 has the same physical footprint and the same input/output (I/O) pins as the Arduino Mega. Also, the integrated development environments (IDEs) for these two platforms are almost identical, which makes our lives a lot easier. The main thing to note is that the chipKIT MAX32 employs a 3.3V supply, while an Arduino Mega uses a 5V supply. This will affect some of the component values, but this will be noted at the appropriate points in the following discussions.

Introducing the MSGEQ7
The MSGEQ7 is a seven-band graphic equalizer chip you can buy for $4.95 from SparkFun. It will work with a 5V supply (like the Arduino Mega) or a 3.3V supply (like the chipKIT MAX32).

Inside the MSGEQ7 are seven band-pass filters tuned to 63 Hz, 160 Hz, 400 Hz, 1,000 Hz, 2,500 Hz, 6,250 Hz, and 16,000 Hz. Each filter has an associated peak detector, as illustrated below. The clever thing is that the outputs from the seven peak detectors are multiplexed together, which explains how everything fits into a teenie-weenie eight-pin package.

Everything is controlled by two digital signals called RESET and STROBE. As shown in the waveform diagram below, a positive-going pulse on the RESET signal kicks everything off. Though the data sheet doesn't say so, my impression is that this pulse takes a copy of the current peak detector outputs and stores (latches) the values. We then apply seven negative-going pulses to the STROBE input. Every time the STROBE input goes low, we can read the value of one of the bands on the DATA_OUT signal, starting with 63 Hz and working out to 16,000 Hz.

The DATA_OUT is an analog value whose magnitude reflects the value from the corresponding peak detector. This value can be read using one of your microcontroller's analog inputs.

Actually, I recreated the timing diagram shown above from the original datasheet. If you read the comments at the bottom of this column, you will see a question by David Ashton. David points out that, as the minimum strobe pulse width of 18µs is less than the minimum output settling time of 36µs, this implies that you can read the data even after the STROBE signal has returned to its HIGH state. Based on this, David notes that you could actually read the data during the "purple times" in the above diagram.

If this were to prove to be correct, then -- based on the timing specifications in the datasheet -- a better representation of the timing relationships and waveforms would be as illustrated below.

Since it's not possible to make a definitive decision based on the existing datasheet, I talked to John Ambrose at Mixed Signal Integration -- the company that makes the MSGEQ7 (along with many other interesting products). John confirmed that applying a positive-going pulse to the RESET signal does indeed latch the current frequency values.

John went on to explain that the DATA_OUT signal is clamped to 0V when the STROBE signal is HIGH. This has several implications, including the fact that you cannot read the data when the STROBE signal is in its HIGH state. Also, this means that the minimum strobe pulse width ("ts") really isn't 18µs; instead, it's equal to the output settling time ("to") plus however long it takes for you to actually read the sample (let's call this "tsr" for "sample read time"). Based on this, the definitive timing diagram is actually as shown below.

With all that behind us, the following illustration reflects the additional components we need to make things work. The resistors are all 1/4 watt, and the capacitors are 50V ceramics. (These components are of the lead-through-hole variety.) In the original data sheet, the value of C2 is shown at 0.01µF, but I ran across an application note somewhere that said it was better to use 0.1µF, so that's what I did.

I decided to use two MSGEQ7s -- one for each audio channel (left and right). If you wish to use a single device for both channels, you can employ the circuit variation that's shown at the bottom of the above illustration.

Even worse, when I first saw the Deja Vu album cover when I was a lad -- with all the arty-farty caligraphy, I read it as "Crosby Stills Nash & Donny" (instead of "Crosby Stills Nash & Young") ... so that's how I always think of them LOL

I'm puzzled by your vocals problem -- I've played "out house" by Crosby Stills & Nash -- which is lagely vocals -- and it works great -- have you put a 'scope' on the input signal to see what's going in?

If you email me at max@clivemaxfield.com -- I'll send you the Arduino code I'm using to drive my BADASS display -- this includes the part that reads the data from the MSGEQ7s with the correct delays in it).

MaxThanks for your quick response and all the info. I just watched your BADASS display and I have to say it discouraged me from building my own analyzer :(, I know I'll never get close to that (just kidding! Baby steps).About the function generator and the shield, I live in Mexico, so it's kind of hard for me to try to get any of those (I barely got the MSGEQ7, I envy you and the way you get everything practically from around the corner :( ) I'll take a deeper look at the posts when I get home.When it is done I'll share some photos or video on what you've helped to build :)Thanks a lot.jreza

@Jreza: What is the input level required by the MSGEQ7? Is it enough with just the output signal from a regular portable player? (from your tutorial it seems it does). Is it enough with the output level of a regular mic?

Hi there -- I think you're going to really enjoy playing with this chip. Take a look at This YouTube Video showing two of these chips driving my BADASS Display.

I'm using the output from the headphone jack from my iPod (sometimes my iPad) with no problems at all -- typically I set the iPad to about 3/4 full volume to drive this chip -- then I control the actual sound volume using the amplifier driving the speakers.

I started off by creating a prototype using a breadboard (see This YouTube Video), but later my chum Duane Benson took my circuit and generated a special printed circuit board (PCB) for an Arduino Shield (this uses two MSGEQ7 chips -- one for each channel).

You can buy one of these boards from Duane from his SteelPuppet.com website if you wish.

Are you using an Arduino? If so, one of the things I do when I've just built a new sound analyzer card (I've now constructed three using Duane's shield for different projects) is to use the Serial I/O to display the numerical values on the screen so I can see what's happening -- you could use this technique to see how your microphone was working.

If you want to see some example Arduino code for this, email me at max@clivemaxfield.com and I'll send it to you.

Hi there.I'm getting all the components to start this proyect. Thanks for the tutorial. I have a question though, What is the input level required by the MSGEQ7? Is it enough with just the output signal from a regular portable player? (from your tutorial it seems it does). Is it enough with the output level of a regular mic?Thanksjreza