Go Down

Topic: VU meter audio signal break up (Read 2721 times) previous topic - next topic

Paranemertes

I have this RGB table I am making that is going to have a lot of different functions, one of which is a VU meter. Unfortunately I have no idea how to break up music into 12 different frequencies, I think I could handle the mapping and everything after that, but breaking it up? Im not sure... the table is a 12x24 grid of RGB leds. I am going to display it with the 12 being vertical and 24 being horizontal, then use 2 of the 24 squares for each column, and THEN map it for 12 also. (sorry wish I has a camera of scanner, SO much easier to describe with pictures) but anyway does anyone know how to break up an audio signal into 12 frequencies? I tried interpreting the code from the LOL shield's VU meter, but, yeah....
http://www.instructables.com/id/LoL-Shield-Audio-Spectrum-VU-Meter/
it says it uses a fast fourier transform algorithm library...hmmm....
here is the library they talk about in the instructible
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155.
OH im multiplexing, not charlieplexing by the way.
so yeah any help would be much appreciated.
"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

retrolefty

Well using FFT is a little over the pay grade of this old hardware guy. For a hardware solution, or at least learning how such a solution would work, SparkFun sells a nice chip to play with that breaks the audio spectrum into 7 bands.

Here is the chip:   http://www.sparkfun.com/products/10468

And here is a shield they have that uses a couple of those chips:

http://www.sparkfun.com/products/10306

Which they have an example sketch

Lefty

Nick Gammon

Well I just tried that and it is pretty cool. I'm not totally convinced about the output, but it changes with frequency at any rate.

As far as I can see the relevant part is:

Code: [Select]
#include <fix_fft.h>
#define AUDIOPIN 5

char im[128], data[128];

int i=0,val;

// ...

void loop()
  {

  // sample audio data
  for (i=0; i < 128; i++){
    val = analogRead(AUDIOPIN);
    data[i] = val;
    im[i] = 0;
  };

  // transform it
  fix_fft(data,im,7,0);

  // display data in data now ...

  }  // end of loop


I can't help feeling as I read that, that the data (input) should be converted to a single byte (after all, it comes in as an int).

Changing one line seems to give better results:

Code: [Select]
    val = analogRead(AUDIOPIN) >> 2;
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics


Nick Gammon

Is that the same code? I couldn't see the link to the library, but it's late here ...
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Magician

I did not create a library, origin of the code, probably the same.
I download it from http://www.jjj.de/fft/fftpage.html My version is 16-bit, source doesn't work with 8-bit samples w/o extra efforts, and I've never read successful application of the library based on http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155.

Paranemertes

Thanks for all the responses, can anyone tell me how to use the library and where to download it? I tried the link posted by Magician, but I dont know which one to download... (sorry about all the newb questions, this is my first big project and there is A LOT of learning on my part)
"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Nick Gammon

The one I actually got to work was the one you linked above:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Magician

To OP: code linked for downloading from Google Docs:
https://docs.google.com/leaf?id=0Bw4tXXvyWtFVZTgxZTVmYTEtNmRhMy00NGM5LTg1MjUtZTgxYmM3MDU5MTJh&hl=en_US
To Nick:  I should correct myself, it's not like it doesn't work at all in 8-bit format, it "Practically" doesn't work. It could identify 1 single tone about -40 dB (I mark absolute maximum 5V peak-to-peak as 0 dB) , but it would failed to "see" a tone -20 dB in presence 3-4 others , stronger "interfering"  frequencies. That makes it useless for any practical application, including musical , where dynamic range at least 60 dB is bare minimum.  

Nick Gammon

Now I'm confused. (That's pretty normal).

The code you linked is a 16-bit FFT, is that right? And the one I tried was 8-bit? And the other one again was an assembler one?

So this one (the link above) would be the best to play with? -  I don't want to litter up my sketches with assembler code.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Magician

Quote
The code you linked is a 16-bit FFT, is that right?
Yes, on the Google Docs.
Quote
And the one I tried was 8-bit?
Yes, on old forum.
Quote
And the other one again was an assembler one?
This is not clear, do you mean FFT library in assembler (Elm-Chan) ? Or you against any assembler in the code, including some direct port/register manipulation?
I used assembler instruction instead of analogRead, as IMHO, they provide more consistent  readings, but it's not mandatory.

DVDdoug

Paranemertes, what you are trying to build is called a spectrum analyzer.

I'm not sure, but i really doubt that the Arduino is fast enough for audio FFT.   I don't think it can sample at 40kHz, which is the minimum if you want to digitize audio up to 20kHz audio.  And, then you have to process the data (the FFT calculations).

The chip sold by SparkFun (which I didn't know about) looks like the way to go, although it won't do 12 frequency bands.  (They call it a graphic equalizer display chip...  I assume it's not precise enough to be used in a "real" spectrum analyzer.)   With this chip, you should be able to sample the inputs as slowly as 10 times per second and still get a good display with very little programming or processing.  That special chip isn't doing FFT, it's got digitally-controlled analog filters.

The chip manufacturer MSI has some other chips, and maybe there's a way to get 12 (or more) frequency bands.   Or, you could build 12 bandpass filters, but that's a lot of electronics.  OR, since I assume this is an "effect", rather than a measuring device, you could use the 7 real bands, and interpolate, and randomize, and otherwise "fake-out" the other bands.

Nick Gammon


Quote
And the other one again was an assembler one?
This is not clear, do you mean FFT library in assembler (Elm-Chan) ? Or you against any assembler in the code...


I'm referring to this sort of thing, using assembler to send serial data:

Code: [Select]
; Transmit a byte in serial format of N81
;
;Prototype: void xmit (uint8_t data);
;Size: 16 words

.global xmit
.func xmit
xmit:
in r0, _SFR_IO_ADDR(SREG) ;Save flags

com r24 ;C = start bit
ldi r25, 10 ;Bit counter
cli ;Start critical section

1: ldi r23, BPS-1 ;----- Bit transferring loop
2: dec r23      ;Wait for a bit time
brne 2b ;/
brcs 3f ;MISO = bit to be sent
cbi TXREG, TXBIT ;
3: brcc 4f ;
sbi TXREG, TXBIT ;/
4: lsr r24      ;Get next bit into C
dec r25      ;All bits sent?
brne 1b       ;  no, coutinue

out _SFR_IO_ADDR(SREG), r0 ;End of critical section
ret
.endfunc


It's just unnecessarily obscure IMHO.

Plus this particular FFT library was written for the Mega, so it's hard to say whether, or not, it will work on the Atmega328. The documentation, such as it is, doesn't really help.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Paranemertes

@DVDdoug, what i am trying to build is a VU meter, what i am trying to code is a spectrum analyzer. If you look at the instructibles link you will see that arduino is indeed fast enough for fft.
@Nick, which one is the library, and how do I use it and get it on my computer? (sorry never worked with librarys before) Should i use the .h or .cpp? I thought that librarys were always .h.
@Magician, I tried your google docs download, where do I put it? in my library's folder?
"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Magician

To OP: file with extension .pde is an arduino sketch, so you copy/paste it or rename/change extension - it's now different in IDE version 1.0
Last time I compiled a sketch with IDE v. 0.18, AFAIR.
To Nick: it's me , who confused this time, which library written for mega? Can you post a link?

Go Up