Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
B4Me
PostPosted: Oct 10, 2007 - 06:35 PM
Hangaround


Joined: Jul 14, 2005
Posts: 261
Location: Denmark (Sønderborg)

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
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 10, 2007 - 06:47 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 23958
Location: Orlando Florida

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
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
RES
PostPosted: Oct 10, 2007 - 07:11 PM
Resident


Joined: Dec 31, 2005
Posts: 710


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

_________________
RES - http://www.attiny.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
jayjay1974
PostPosted: Oct 10, 2007 - 07:23 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5765
Location: The Netherlands

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?
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Oct 10, 2007 - 07:33 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 28939
Location: Wisconsin USA

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
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Oct 10, 2007 - 08:42 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5765
Location: The Netherlands

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 Smile

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.
 
 View user's profile Send private message  
Reply with quote Back to top
Kleinstein
PostPosted: Oct 10, 2007 - 08:51 PM
Resident


Joined: Sep 22, 2007
Posts: 980
Location: Germany

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.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 10, 2007 - 09:56 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 23958
Location: Orlando Florida

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
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
jgrunt
PostPosted: Oct 11, 2007 - 02:24 AM
Hangaround


Joined: Mar 14, 2005
Posts: 453


http:/

_________________
JChristoff
Illinois


Last edited by jgrunt on Jan 06, 2011 - 06:00 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
B4Me
PostPosted: Oct 12, 2007 - 05:20 PM
Hangaround


Joined: Jul 14, 2005
Posts: 261
Location: Denmark (Sønderborg)

Okay Very Happy
Thanks for the many replyes.

_________________
uC's: Atmega16, 32, 64, 128 and Attiny13
Lang.: C
Interests: Small scale robots AND sensor monitoring system
 
 View user's profile Send private message  
Reply with quote Back to top
metron9
PostPosted: Oct 12, 2007 - 07:55 PM
Resident


Joined: Aug 25, 2005
Posts: 911
Location: U.S.A

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.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 12, 2007 - 08:00 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 23958
Location: Orlando Florida

I think that's exactly what the original Fourier frequency analyzer was... a bunch of tuned strings

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
B4Me
PostPosted: Oct 12, 2007 - 08:07 PM
Hangaround


Joined: Jul 14, 2005
Posts: 261
Location: Denmark (Sønderborg)

Hehe Wink

plz correct me if I'm wrong, but all I have to do is like .... sample at ex. 1kHz...
and if I will se how much 500 Hz there is.. I shall just take every second sample and divide the sum with the number of samples ?

_________________
uC's: Atmega16, 32, 64, 128 and Attiny13
Lang.: C
Interests: Small scale robots AND sensor monitoring system
 
 View user's profile Send private message  
Reply with quote Back to top
John_A_Brown
PostPosted: Oct 12, 2007 - 09:13 PM
Raving lunatic


Joined: Sep 20, 2003
Posts: 4992
Location: Surrey, England

I think you might be over simplifying things a bit... Have you thought about what would happen if "every second sample" happened to coincide with the zero crossings? You'd be led to believe that there was "not much" 500Hz there.
If it was that easy, why would anyone bother with Fourier?
(You did say "plz correct me if I'm wrong)
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 12, 2007 - 09:25 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 23958
Location: Orlando Florida

You can make a freq analyzer using hw or sw. Prev msg suggested a bank of analog filters, just scan the outputs and draw graph in dB. My approach was to fill buf with samples, run thru one filter at 20hz, plot db of avg filter out. Set filter to 40 hz, run same samples thru this filter. Repeat for 80,160,320,640,1280,2500,5K,10K,20K, you're done. Except the filter only works up to about 1/6 the samp freq, so to get the 10k filter to work, I need to sample at 60k... thats a prob.... there are some articles that speak of 'double sampling', but that slows it down, and its already pretty slow. Then there's the FFT approach... take samples at twice the highest freq of interest for one period of the lowest freq of interest then start crunching. Go out and get a cup of coffee... there's you spectra! But they are all linearly spaced, and you probably want to see 20-20k log spaced... well, do you take the avg of a bunch of the spectral magnitudes, or the magnitude of the average of a bunch of spectra? (2nd one I think).

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Jepael
PostPosted: Oct 12, 2007 - 09:37 PM
Raving lunatic


Joined: May 24, 2004
Posts: 6275
Location: Tampere, Finland

B4me:

No that would not work. Imagine every sample is say +42, this is clearly DC, no 500Hz sine at all, and your calculation is nonsense.

If you are interested in single frequencies, you could speed things up by doing DCT for just that frequency, but for a full band, FFT is a high speed special case of DCT.

- Jani
 
 View user's profile Send private message  
Reply with quote Back to top
B4Me
PostPosted: Oct 13, 2007 - 11:33 AM
Hangaround


Joined: Jul 14, 2005
Posts: 261
Location: Denmark (Sønderborg)

Uh can see I was wrong Razz
bobgardner:
I would make this so I have ... ex. 10 rows of LEDs, and they should show all freq. from 20~100 Hz to 20 kHz...
I don't know the correct name for that ?

And it would be best if I don't have to have a lot of HW... (little space on the PCB)

_________________
uC's: Atmega16, 32, 64, 128 and Attiny13
Lang.: C
Interests: Small scale robots AND sensor monitoring system
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Oct 13, 2007 - 11:43 AM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5765
Location: The Netherlands

Spectrum analyzer with octave spaced bands, as usually the center frequency is the twice the previous one.
 
 View user's profile Send private message  
Reply with quote Back to top
B4Me
PostPosted: Oct 13, 2007 - 11:51 AM
Hangaround


Joined: Jul 14, 2005
Posts: 261
Location: Denmark (Sønderborg)

so like ?
20, 40, 80, 160 and so on ?

_________________
uC's: Atmega16, 32, 64, 128 and Attiny13
Lang.: C
Interests: Small scale robots AND sensor monitoring system
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Oct 13, 2007 - 02:12 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5765
Location: The Netherlands

Yes.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits