So I am trying to understand the fft library for arduino
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155.
and i am currrently trying to base my code off of the LOL shields example code to create a VU meter with 12 columns with an intensity of 12(mapped to 12).
I am having trouble figuring out what to do after i break up the signal and map it accourdingly, are there returns that i can use? Any help would be greatly appreciated.
Here is the original unmodified for the LOL shield:
/*
FFT for LoL Shield v0.9
by Andy Doro
http://andydoro.com/
based on FFT library and code from the Arduino forums and
the Charlieplexing library for the LoL Shield.
*/
#include <Charliplexing.h>
#include <fix_fft.h>
#define AUDIOPIN 5
char im[128], data[128];
char data_avgs[14];
int i=0,val;
void setup() {
LedSign::Init(); //Initilizes the LoL Shield
}
void loop() {
for (i=0; i < 128; i++){
val = analogRead(AUDIOPIN);
data[i] = val;
im[i] = 0;
};
fix_fft(data,im,7,0);
for (i=0; i< 64;i++){
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); // this gets the absolute value of the values in the array, so we're only dealing with positive numbers
};
// average bars together
for (i=0; i<14; i++) {
data_avgs[i] = data[i*4] + data[i*4 + 1] + data[i*4 + 2] + data[i*4 + 3]; // average together
data_avgs[i] = map(data_avgs[i], 0, 30, 0, 9); // remap values for LoL
}
// set LoLShield
for (int x=0; x < 14; x++) {
for (int y=0; y < 9; y++) {
if (y < data_avgs[13-x]) { // 13-x reverses the bars so low to high frequences are represented from left to right.
LedSign::Set(x,y,1); // set the LED on
} else {
LedSign::Set(x,y,0); // set the LED off
}
}
}
}
Here it is with what i have figured out:
/*
FFT for LoL Shield v0.9 //nope, for Omnomni Table
by Andy Doro //kinda
http://andydoro.com/
*/
#include <fix_fft.h>
#define AUDIOPIN 5
char im[128], data[128];
char data_avgs[12]; //changed to 12 cause 12 columns???
int i=0,val;
void setup() {
Serial.begin(9600); //is this baud rate to slow? can i print the values of the 12 columns?
}
void loop() {
for (i=0; i < 128; i++){
val = analogRead(AUDIOPIN);
data[i] = val;
im[i] = 0;
};
fix_fft(data,im,7,0); // does this need changing? What is it for?
for (i=0; i< 64;i++){
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); // this gets the absolute value of the values in the array, so we're only dealing with positive numbers
};
// average bars together
for (i=0; i<12; i++) {
data_avgs[i] = data[i*4] + data[i*4 + 1] + data[i*4 + 2] + data[i*4 + 3]; // average together, but for 12 not 14
data_avgs[i] = map(data_avgs[i], 0, 30, 0, 12); // remap values for my application, so 12
}
// set LoLShield, this is where i am confused, i need to be able to see the values in a serial moniter, anyone??
for (int x=0; x < 14; x++) {
for (int y=0; y < 9; y++) {
if (y < data_avgs[13-x]) { // 13-x reverses the bars so low to high frequences are represented from left to right.
LedSign::Set(x,y,1); // set the LED on
} else {
LedSign::Set(x,y,0); // set the LED off
}
}
}
}