Buggington
Posts: 14
Joined: Sat Aug 11, 2012 8:52 pm

Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 10:18 am

Hi :)

In my A Level Electronics class I have created an LED Audio Spectrum Analyser, where you plug your iPod (or other generic MP3 player) into the 3.5mm jack, and as you play the music it lights up five lines of LEDs in the traditional way. Image below :)

Image
Image

What I want to do is to add this to my Raspberry Pi, which sits on my desk. The Pi's running ShairPort, which allows me to AirPlay music over to it and out to the 3.5mm headphone jack.

So far I can think of two ways to do this:
1. Somehow shrink the original circuit down (as in the diagrams below), and mount it on a breadboard compatible case.
2. Using some sort of display, take the audio output from the Pi, and display the output on some sort of external LCD display, or use some LEDs, á la previous project.

http://i1002.photobucket.com/albums/af1 ... 80555f.jpg
http://i1002.photobucket.com/albums/af1 ... 8dff2b.jpg

About all I can do at this stage is a sort of pro/con list, so here goes.

Option 1:
Pros:

Most of the work is done
Simple (ish) system
Cons
Very large circuit
Amplifiers require a -5V supply, which the Pi can't supply

Option 2:
Pros:

Potentially looks much neater
No -5V supply required
Cons:
I have no idea how to use an external display
If I used LEDs, there wouldn't be enough GPIO ports to power them.
I haven't got a clue how to extract the audio output via software, or take the frequency bands.

Is anyone able to point me in the right direction? Any help is much appreciated :)

Thanks

User avatar
Burngate
Posts: 5870
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 1:19 pm

Don't know about the rest, but in option 1:
Cons
Very large circuit
Amplifiers require a -5V supply, which the Pi can't supply
Where on your circuit you have the +inputs to the opamps connected to ground, could you not create a half-rail point using a couple of 10k resistors (and capacitor)?
As long as the opamps are happy with 5v, you would only lose headroom.

chris217
Posts: 10
Joined: Sat Aug 25, 2012 10:24 am
Location: Hampshire, UK

Re: Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 3:10 pm

You could consider something like a MAX1720 plus a couple of capacitors to generate the -5V supply.

User avatar
MrBunsy
Posts: 185
Joined: Mon Feb 20, 2012 1:48 pm
Location: Southampton, UK
Contact: Website

Re: Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 3:45 pm

A suggestion: You could use a fast Fourier transform (FFT) in software on the Pi, then use an LED driver to display what you want on the LEDs. The number of GPIOs won't be a problem - you can get serially-fed LED drivers where you shift in all the values you want, then enable the output, so 2 GPIOs could run a very large number of LEDs. Rinse and repeat at whatever framerate you want - a smooth display will need to be in the 10s of Hz, and the Pi is running in the Mhzs range so that shouldn't be a problem for responsiveness.

A (very) quick search for serial led driver reveals a chip - http://www.farnell.com/datasheets/52446.pdf which would easily fit the bill. Getting the audio stream into a form you could run an FFT on it would probably be the fiddly bit.

Buggington
Posts: 14
Joined: Sat Aug 11, 2012 8:52 pm

Re: Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 5:29 pm

Burngate wrote:Don't know about the rest, but in option 1:
Cons
Very large circuit
Amplifiers require a -5V supply, which the Pi can't supply
Where on your circuit you have the +inputs to the opamps connected to ground, could you not create a half-rail point using a couple of 10k resistors (and capacitor)?
As long as the opamps are happy with 5v, you would only lose headroom.
How would that work? Are you suggesting that I could run the op-amp off 5V and 0V? Otherwise I don't really understand what you mean by a half rail point, sorry :(

Chris: I like the idea of that chip - I might end up using that :)

MrBunsy: (great name) I've never heard of FFT - I'll do some research into that :) Like you say, I don't know quite how to intercept the output. I could possible use a splitter on the 3.5mm output and then back to a GPIO input, but I don't think the Pi could work with something at 44.1kHz, or at least 16kHz
as 8kHz was the fastest I had for the A2 project.

Thanks to all of you for the ideas :D

User avatar
Burngate
Posts: 5870
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 7:42 pm

Buggington wrote:How would that work? Are you suggesting that I could run the op-amp off 5V and 0V? Otherwise I don't really understand what you mean by a half rail point, sorry :(
OK
Run the op-amp off 5v and 0v.
Connect two resistors, as a potential devider from 5v to 0v, so that the junction will be at 2v5. Connect a capacitor from there to 0v to keep that voltage stable.

Then all the + inputs on the op-amps that in your diagram are connected to 0v - all four of those, the other two being biased from their outputs - you can connect to your newly-created 2v5 point

This means that, in true op-amp fashion, they will settle such that their - inputs and therefore their outputs are at 2v5.
Provided they're not asked to swing their outputs beyond the rails, they'll act linearly.

You'll have to change the way the rectifier circuits work - at the moment you're having them swing positive from 0v, but my change would raise everything by 2v5, and I've no idea how to change your picaxe bit.

But I was merely showing you that -5v isn't necessarily required for just the op-amps

Buggington
Posts: 14
Joined: Sat Aug 11, 2012 8:52 pm

Re: Raspberry Pi Spectrum Analyser

Sun Jan 13, 2013 7:56 pm

Burngate wrote:
Buggington wrote:How would that work? Are you suggesting that I could run the op-amp off 5V and 0V? Otherwise I don't really understand what you mean by a half rail point, sorry :(
OK
Run the op-amp off 5v and 0v.
Connect two resistors, as a potential devider from 5v to 0v, so that the junction will be at 2v5. Connect a capacitor from there to 0v to keep that voltage stable.

Then all the + inputs on the op-amps that in your diagram are connected to 0v - all four of those, the other two being biased from their outputs - you can connect to your newly-created 2v5 point

This means that, in true op-amp fashion, they will settle such that their - inputs and therefore their outputs are at 2v5.
Provided they're not asked to swing their outputs beyond the rails, they'll act linearly.

You'll have to change the way the rectifier circuits work - at the moment you're having them swing positive from 0v, but my change would raise everything by 2v5, and I've no idea how to change your picaxe bit.

But I was merely showing you that -5v isn't necessarily required for just the op-amps
Ah, neat solution. Thanks! I would have to modify the PICAXE to ignore the 2.5V, which would make things a little bit awkward, given that the pre-amp has a gain of -5 (because my iPhone has an RMS of 1.1V) and I'm not sure how everything would work with only 2.5V to play with. Hmmm...food for thought :)

drugoimir
Posts: 1
Joined: Thu Jan 10, 2013 4:54 pm

Re: Raspberry Pi Spectrum Analyser

Wed Jan 16, 2013 2:07 am

t is a good idea to use any voltage inverter such as the MAX1720 previously mentioned or the something like the good old ICL7660.
But also you could think to use some rail to rail I/O opamps, such LMC6482, MAXIM's MCP6001, LMC7101 to list some.
The sequent filter/rectifier should be ac coupled (the high-pass part of the bandpass filter
just realized this) so it can correctly out 0 volts when no signal is present.
Regarding this rectifier/filter assembly, i don't know picaxe, but i succeeded in giving a raw audio signal to a VCC/2 biased ADC input on an AVR, then rectifying it internally once acquired: this would simplify your circuit very much giving also some improvements, one in accuracy since that unbiased diodes used as rectifiers are somewhat far from ideal, another in attack/decay management so you can code these times in software so you can choose between different "fallout" speeds.

Last but not least, you can then multiply the converted value to the value you need to light the whole led bar, so you 'll don't need to have a 5V input (so the +/- 5V question will be less a concern).

but...after looked your diagram...why you need opamps, why you need the picaxe?
Why don't you use the rPI to synthesize the whole system?
If you have access to the input audio on the pi, you are done.

You can simply use any fft (very good one is FFTW) or code a bunch of iir filters to
make the band cuts, then send the computed data to the gpio.
I'm pretty new to the linux world, but i know that every output stream can be diverted to any other
input, that is ShairPlay output might be directed to your spectrum analyzer program, but for this i cannot help you because i never did it and i don't know how is done.

Ok, gpio has not many pins as you need: most oled display have, along with parallel interface, a spi interface which can connect the display with just 3 wires: raspberry has a nice spi port (which have to be "unchained", have a look around on how to do it) and you can connect the display there.
The pro is that an oled display is very nice to see, the con is that you 'll have to develop some sort of driver yourself in order to have it working.
Other solution could be a MAX7219 or similiar. It can drive up to 64 leds from an spi input.
If you cannot find a 7219 or something like and are a "solder hero", then you could try to stack several 74LV595 to maxe your 8xN (N=the number of 595 you 'll use) leds array.
Driving this latter will be very simple: clock (shift register clock on 595) and cs (storage transition on 595) signals will be shared by all ICs on the chain, the mosi will go to the first IC input then its output will go to the input of the next and the next' output to the subsequent input and so on.

bye

texy
Forum Moderator
Forum Moderator
Posts: 5154
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Raspberry Pi Spectrum Analyser

Fri Jan 18, 2013 7:00 pm

Buggington wrote:
Burngate wrote:
Buggington wrote:How would that work? Are you suggesting that I could run the op-amp off 5V and 0V? Otherwise I don't really understand what you mean by a half rail point, sorry :(
OK
Run the op-amp off 5v and 0v.
Connect two resistors, as a potential devider from 5v to 0v, so that the junction will be at 2v5. Connect a capacitor from there to 0v to keep that voltage stable.

Then all the + inputs on the op-amps that in your diagram are connected to 0v - all four of those, the other two being biased from their outputs - you can connect to your newly-created 2v5 point

This means that, in true op-amp fashion, they will settle such that their - inputs and therefore their outputs are at 2v5.
Provided they're not asked to swing their outputs beyond the rails, they'll act linearly.

You'll have to change the way the rectifier circuits work - at the moment you're having them swing positive from 0v, but my change would raise everything by 2v5, and I've no idea how to change your picaxe bit.

But I was merely showing you that -5v isn't necessarily required for just the op-amps
Ah, neat solution. Thanks! I would have to modify the PICAXE to ignore the 2.5V, which would make things a little bit awkward, given that the pre-amp has a gain of -5 (because my iPhone has an RMS of 1.1V) and I'm not sure how everything would work with only 2.5V to play with. Hmmm...food for thought :)
...some of the picaxe chips have +Vref option, so you could offset +2.5v that way perhaps. You haven't stated which picaxe you are using, could you post your code? I think the FFT option with software on the Pi sounds a nicer option though ;) ;)

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Buggington
Posts: 14
Joined: Sat Aug 11, 2012 8:52 pm

Re: Raspberry Pi Spectrum Analyser

Fri Jan 18, 2013 11:34 pm

Texy (apparently I can only embed three quotes, so I'm starting afresh):

You're right, the FFT option does sound good. I'm using a PICAXE 18M2; I didn't code it, but used a flow chart, which I'll post when I'm next at my desk. I didn't know the PICAXEs could do the offset voltage thing, but that would still only leave me with 2.5V to play with?

FFT is beginning o look quite good now :D

Buggington
Posts: 14
Joined: Sat Aug 11, 2012 8:52 pm

Re: Raspberry Pi Spectrum Analyser

Fri Jan 18, 2013 11:50 pm

drugoimir wrote:t is a good idea to use any voltage inverter such as the MAX1720 previously mentioned or the something like the good old ICL7660.
But also you could think to use some rail to rail I/O opamps, such LMC6482, MAXIM's MCP6001, LMC7101 to list some.
The sequent filter/rectifier should be ac coupled (the high-pass part of the bandpass filter
just realized this) so it can correctly out 0 volts when no signal is present.
Regarding this rectifier/filter assembly, i don't know picaxe, but i succeeded in giving a raw audio signal to a VCC/2 biased ADC input on an AVR, then rectifying it internally once acquired: this would simplify your circuit very much giving also some improvements, one in accuracy since that unbiased diodes used as rectifiers are somewhat far from ideal, another in attack/decay management so you can code these times in software so you can choose between different "fallout" speeds.

Last but not least, you can then multiply the converted value to the value you need to light the whole led bar, so you 'll don't need to have a 5V input (so the +/- 5V question will be less a concern).

but...after looked your diagram...why you need opamps, why you need the picaxe?
Why don't you use the rPI to synthesize the whole system?
If you have access to the input audio on the pi, you are done.

You can simply use any fft (very good one is FFTW) or code a bunch of iir filters to
make the band cuts, then send the computed data to the gpio.
I'm pretty new to the linux world, but i know that every output stream can be diverted to any other
input, that is ShairPlay output might be directed to your spectrum analyzer program, but for this i cannot help you because i never did it and i don't know how is done.

Ok, gpio has not many pins as you need: most oled display have, along with parallel interface, a spi interface which can connect the display with just 3 wires: raspberry has a nice spi port (which have to be "unchained", have a look around on how to do it) and you can connect the display there.
The pro is that an oled display is very nice to see, the con is that you 'll have to develop some sort of driver yourself in order to have it working.
Other solution could be a MAX7219 or similiar. It can drive up to 64 leds from an spi input.
If you cannot find a 7219 or something like and are a "solder hero", then you could try to stack several 74LV595 to maxe your 8xN (N=the number of 595 you 'll use) leds array.
Driving this latter will be very simple: clock (shift register clock on 595) and cs (storage transition on 595) signals will be shared by all ICs on the chain, the mosi will go to the first IC input then its output will go to the input of the next and the next' output to the subsequent input and so on.

bye
First of all, thanks for the massively long post!

Secondly: I think I might look into all those things, thanks. I'm new to all this too, especially making my own video display driver. I haven't heard of the SPI thingy, so I'll have a look later. Thanks again :D

Return to “Media centres”