# VU meter audio signal break up

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.

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

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:

``````#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++){
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:

``````    val = analogRead(AUDIOPIN) >> 2;
``````

Is that the same code? I couldn't see the link to the library, but it's late here ...

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.

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)

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

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.

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.

The code you linked is a 16-bit FFT, is that right?

And the one I tried was 8-bit?

Yes, on old forum.

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.

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 [u]MSI[/u] 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.

Magician:

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:

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

.global xmit
.func xmit
xmit:

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.

@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.

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?

@Magician, ok got the thing downloaded and opened in arduino, how do i convert it to a library? do i just create a new folder inside the libraries folder and save it there?

Magician:
To Nick: it’s me , who confused this time, which library written for mega? Can you post a link?

Er … … this one:

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

In particular:

http://elm-chan.org/works/akilcd/akilcd.zip

To OP: there is a link:http://www.arduino.cc/en/Hacking/Libraries and more info in General section: http://arduino.cc/playground/Main/TutorialList It's not necessary to create a library, it's only simplify navigation in the huge programs, and doesn't change functionality at all. To Nick:

Plus this particular FFT library was written for the Mega,

I thought you mean arduino Mega board, but itr's not the case, as Chan's softaware written for

The microcontroller is an Atmel ATmega8

which is even smaller uCPU than AtMega328 on arduino Uno.

OK, so i can just keep this code chillin at the bottom of the sketch? no need to get the .cpp or header file? And could someone please explain in very basic terms how to use this library?!!? thanks

one more thing, say i want to turn it into a library, how do i convert the text from the link that has the header and .cpp files into those actual files? right now they are just text...