Simplest music/audio spectrum analyzer - Arduino? - Page 1
Forum section: electronics / projects

author: kalel
author_rank: Frequent Contributor
timestamp: September 11, 2017, 06:49:02 pm
content: This might have been asked before, and I have a feeling that it should be in beginners section. Sometimes it's hard to tell which one is right. This is not a project in progress, just a few questions about how a particular project could be made.To be clear, I probably don't have the parts, or possibly the skill so I'm not looking to make one just yet. A simple few LED VU meter is a nice and cheap point to start with, I'm just curious for future reference so that if I do decide to make one, I know which parts to get.If more resolution is exponentially more expensive or complex, for me more than a few points to be analyzed would not be needed. So, very limited resolution/accuracy. For example, a few LEDs flashing depending on whether or not there's more bass, mid or treble in the current part of the song.Obviously I'm not looking for exact specifics or someone to make one for me, just curious about which parts might be needed and how complex it would be to do (possibly it's way out of my reach). I'm not sure that Arduino itself can analyze input audio in real time to get values for each frequency segment/band. Would an external IC be used to analyze the audio input and communicate with Arduino? The audio input would be music/sound produced from an MP3 player or a computer.I assume that there's a way to apply some analog filtering to the sound for each segment, but I'm not sure if that's the simplest (or the cheapest) way to address the point.

author: Richard Crowley
author_rank: Super Contributor
timestamp: September 11, 2017, 06:55:43 pm
content: Audio "spectrum analysis" back in the analog days was done with an array of notch filters spaced at octave or 1/2 octave or 1/3 octave (etc) apart. But these days it is pretty easy to do with Arduino-level microcontrollers and a mathematical trick called Fast Fourier Transform (FFT).Go to YouTube and search on: Arduino spectrum FFTThere are a variety of different projects demonstrated along the lines of your inquiry.

author: DaJMasta
author_rank: Super Contributor
timestamp: September 11, 2017, 08:32:34 pm
content: The notch filters is what you normally see on those LED display rack mount equalizers and such - each line of LEDs is a VU meter, but it's restricted to a narrow frequency band with filters. You can get much more resolution without tons and tons of tuned hardware with an FFT analysis, and micros can do that, they are just limited on speed. Something like a 128 or 256 bin FFT would happen reasonably fast on an arduino, but over the entire audio band its resolution would be very coarse at low frequencies. Faster micros, especially those with DSP extensions, can do this much faster, and with more speed and memory, you can get a resolution more like what you'd imagine from a spectrogram plot.The easiest way to just see the info with high resolution is to use a computer with a sound card and some software (I'd recommend the free SpectrumLab), but doing in hardware as project, you have some options. If you don't want to go the FFT route, there are LED bar graph display drivers that are meant to take audio levels as input which could be convenient to use on a display, and if you don't need too many frequency bands, there are chips that will give you 4 to about a dozen frequency bands with in-built filters, preventing you from having to design and tune your own filters (though since it's not particularly high frequency, it is a very doable task and will teach you a lot about dealing with analog signals).

author: David_AVD
author_rank: Super Contributor
timestamp: September 12, 2017, 02:09:17 am
content: Take a look at the MSGEQ7P chip. Lots of examples for Arduino out there and can be bought on eBay for a couple of dollars.

author: kalel
author_rank: Frequent Contributor
timestamp: September 12, 2017, 10:22:16 am
content: Thanks for all of the suggestions so far. Regarding the chip, I found a similarly named one which does that for ~$1, so it's available/affordable.Regarding FFT:I have found these two libraries:http://wiki.openmusiclabs.com/wiki/ArduinoFFThttp://wiki.openmusiclabs.com/wiki/ArduinoFHTI assume that FHT is probably better for what I need, but lacking the complete knowledge here, I would have to experiment my way into some results.QuoteThat tells me it's at least possible to use the ADC and get some results, but if it works well for things like Audio, I don't know.Search result for sample rate (https://arduino.stackexchange.com/questions/699/how-do-i-know-the-sampling-frequency):QuoteI guess I should look into the Audio Codec Shield too - just to see what it is and how much it costs, but thinking of a cheap (and not so much accurate) solution, the less extra components - the better.- There's thishttps://www.sparkfun.com/products/retired/11290Seems retired.I wouldn't be surprised if there's a cheap Chinese module with decent audio capabilities also.

author: b_force
author_rank: Super Contributor
timestamp: September 12, 2017, 11:03:44 am
content: Is it just for showing stuff (a LED or something) or do you want to actually measure something?Because if it's the last I would just use a PC and a soundcard.

author: kalel
author_rank: Frequent Contributor
timestamp: September 12, 2017, 12:03:41 pm
content: Quote from: b_force on September 12, 2017, 11:03:44 amIt's the first, actually just to have some LEDs that respond to sound frequency.Probably 4-5 points is enough, 3 might be a bit too little - too broad frequency wise to show much.No real/accurate measurements are needed.

author: senso
author_rank: Frequent Contributor
timestamp: September 12, 2017, 03:29:51 pm
content: A long time ago I made a simple spectrum analyzer using an atmega, a 16x2 display, and some op-amp to center audio at 2.5v, to feed into the atmega adc.I used ElmChan FFT lib, and custom chars going from 0 to 7 bars so it had 15 "states" on each column for a bit more resolution, it was fast-ish(around 14Hz), but every now and then it would kinda hiccup and take a bit longer, never understood why.

author: cstratton
author_rank: Regular Contributor
timestamp: September 13, 2017, 03:23:59 am
content: An ATmega-based Arduino is a bad fit for this task, on both the ADC and computational axis.You really want something else - especially when looking in the frequency domain you start to see the benefit of having real dynamic range, so you probably want an Audio class ADC, and if not a DSP (as would have been used for this 20 years ago when it was in fact a common DSP eval board demo), then at least a fairly fast MCU core for processing.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: September 13, 2017, 04:44:08 am
content: Quote from: kalel on September 12, 2017, 12:03:41 pmAs Richard suggested, a few LED 'VU' meters with filters for each band is the easiest way to do this.

author: kalel
author_rank: Frequent Contributor
timestamp: September 13, 2017, 10:26:42 am
content: Quote from: DrGeoff on September 13, 2017, 04:44:08 amThat method makes sense, especially for just a few bands. I'm not sure if getting a DSP and powerful MCU is a simple or cheap way to do so (although there might be something cheap available by now, I'm not sure).

author: senso
author_rank: Frequent Contributor
timestamp: September 13, 2017, 03:27:27 pm
content: Quote from: cstratton on September 13, 2017, 03:23:59 amIf the intended use case is for visual effects and nothing else, a 20Mhz Atmega with decent code will achieve that with horse power to spare.

author: kalel
author_rank: Frequent Contributor
timestamp: September 13, 2017, 08:33:06 pm
content: Quote from: senso on September 13, 2017, 03:27:27 pmYes, visual effects. So, something like Arduino mega? There are also some cheap and possibly powerful Cortex ARM boards, but I have no idea how complicated they are for coding. Probably better to stick to something like an Arduino.Of course, it's questionable if I can invest in a more expensive board just for that project, but still good to know what is needed.

author: rstofer
author_rank: Super Contributor
timestamp: September 13, 2017, 09:47:48 pm
content: Quote from: kalel on September 13, 2017, 08:33:06 pmC is C so it doesn't matter what board you use. The difference will be in the libraries and that's where Arduino shines. But there's nothing special about the libraries either. C is C so copy what you need and modify it to fit the different hardware.You can Google for 'ARM FFT' and you will find that ARM (the company) provides a DSP library that contains an FFT function for the Cortex M3.You will also find this:https://stratifylabs.co/embedded%20design%20tips/2013/10/13/Tips-FFT-on-the-ARM-Cortex-M3/Try Google for this: 'arm cortex m3 fft library'The code is all over the place!And a 60-100 MHz 32 bit ARM is going to be a LOT faster than a 16 MHz 8 bit processor.Even better: The Arduino Due uses a Cortex M-3 and is programmable with the standard Arduino toolchain.https://www.arduino.cc/en/Guide/ArduinoDue

author: kalel
author_rank: Frequent Contributor
timestamp: September 14, 2017, 10:03:36 am
content: Searching for development boards, for under $2 there's a small development board with this:STM32F103C8T6 ARM STM32From the sellers:QuoteSo those (well at least the mini package) seem to be really affordable these days, and for a few dollars more there are larger boards with built in headers. Still, convenience of using Arduino may pay off depending on the purpose.

author: Richard Crowley
author_rank: Super Contributor
timestamp: September 14, 2017, 12:37:00 pm
content: This is probably my favorite "eye candy" audio spectrum toy...https://youtu.be/DE3mBtQlpyg

author: kalel
author_rank: Frequent Contributor
timestamp: September 14, 2017, 12:48:18 pm
content: Quote from: Richard Crowley on September 14, 2017, 12:37:00 pmLooks neat, I like such "screens" too (they are affordable). Interesting to see Python also (makes sense for Pi), but could get moderately expensive as an experiment. Of course, people don't get a Pijustfor that single project, so the price is not calculated that way.