Sound spectrum analyzer in a AVR ?

28 posts / 0 new
Last post
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey
I'm very soon going to play with a big LED matrix I'm about to build...
And was thinking, if it is possible to use a AVR like mega32 or 64 to analyze a sinus wave from a mic. and turn it in to something I could show on the matrix...like the spectrum analyze thing in Winamp.. ??

Have any of you guys done this before ?

//B4Me

uC's: Atmega16, 32, 64, 128 and Attiny13
Lang.: C
Interests: Small scale robots AND sensor monitoring system

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can do an FFT but its sort of slow. How many updates per sec you want to see? 3? 4? I've been trying to do something like this.... for 'hi fi' you might want 20-20k... 40khz sampling freq.... cant quite get there with the internal a/d, even in 8 bit mode. Might could at 20mhz, but then you need to sample for at least one period of the lowest freq you want... 20hz... 50ms.... So you need to be able to grab 2000 samples... ok on a mega128, but not so good on a mega32. I was trying to do a simulation of the 3 opamp BP filter, and change the filter freq to step up in octaves, and resample the inputs for ea freq and post the avged ampl in db. It gave about a band per sec... dink dink dink dink.... needs some speedup tricks.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Instead of a FFT you could use a bandpass filter for each band. A single biquad isn't too complicated but isn't steep enough, so you would need to cascade a few. For each band you want. Involves a lot of multiplications and additions.

See here what a digital biquad filter is.

Maybe an 8 or 16 point FFT is faster.

I think it's not possible to reach a reasonable refresh rate.

Let's do some maths:

A sample is needed every 1/40Khz=25uS. All the filters need to be updated in this time. At 16Mhz each instruction takes 62.5ns. So the time available is 400 instructions before the next sample is due. At 10 bands that leaves 40 instructions to do each band. Then you still need to sample, average and multiplex.

Maybe use 'real old-fashioned' analogue electronics?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Maybe use 'real old-fashioned' analogue electronics?

Nah, it will never catch on.

Quote:

A sample is needed every 1/40Khz=25uS.

Agreed; let's start with that.

Quote:

All the filters need to be updated in this time.

Now here I don't necessarily agree. Even if one got all this "stuff", where are you going to put it and what are you going to do with it?

I'd guess that for most purposes it is like displaying a value on an LCD. No matter how fast you sample and recalculate it makes no sense to do more than a few re-displays of the now value each second. As a speculation on this app, perhaps 10 updates per second or so would be fine?

Lee

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Now here I don't necessarily agree. Even if one got all this "stuff", where are you going to put it and what are you going to do with it?

Average the outputs of the filters over a display frame period :)

I don't think this device will be a certified and calibrated scientific instrument, so maybe a few shortcuts could be made. Likely only the visual effect counts.

I don't know how many input samples for a filter are needed for a reasonable output. You need some kind of windowing to prevent all kinds of artifacts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a slightly better link:

http://elm-chan.org/works/akilcd/report_e.html

From this page I would conclude that the FFT soluton gives some usefull results.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My mega128 will do 128 sample FFTs really fast, but 1024 or 2048 point FFTs are sloooow, so you could do a 'speech band' FFT real time no prob. (I got the MixFFT pc example stuff to compile on the mega128)

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http:/

JChristoff
Illinois

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay :D
Thanks for the many replyes.

uC's: Atmega16, 32, 64, 128 and Attiny13
Lang.: C
Interests: Small scale robots AND sensor monitoring system

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Maybe use 'real old-fashioned' analogue electronics?

How about go further back that analogue electronics.

I play drums, when a frequency for example on a bass guitar is at the same resonent frequency of the snares on my snare drum , it vibrates big time. Suppose you use wires tuned to vibrate at the specific frequencies you are looking for and measure the vibration of all the wires? Perhaps connect the wires to a piezo device to give you a the amplitude of the vibration as an sine wave.

Pages