Hello all,

I am a novice and I am trying to implement FFT (Fast Fourier Transform) on Arduino. I am using this shield

http://www.openmusiclabs.com/projects/codec-shield/I uploaded the following example code on Arduino and tried to get the spectrum of an audio file. I played the file in my computer and sent the signal from the headphone jack to the line_in using a male-male audio cable. Could this be the problem?

Then I opened the serial monitor, set the baud rate to the one specified in the code, but I did not see any data except some characters flashing across. After a while the IDE froze.

I am inexperienced so I will appreciate it if you could tell me where I am making a mistake. Thanks in advance.

The following code is provided by the manufacturer along with the necessary libraries on their website

`#define SAMPLE_RATE 44 // 44.1Khz`

#define ADCS 0 // no ADCs are being used

#define LOG_OUT 1 // use the log output function

#define FFT_N 256 // set to 256 point fft

// include necessary libraries

#include "FFT.h"

#include <Wire.h>

#include <SPI.h>

#include <AudioCodec.h>

// create data variables for audio transfer

int left_in = 0x0000;

int left_out = 0x0000;

int right_in = 0x0000;

int right_out = 0x0000;

unsigned int count = 0;

volatile byte flag = 1;

void setup() {

Serial.begin(115200); // use serial port

AudioCodec_init();

}

void loop() {

while(1) { // reduces clock jitter

while(flag); // wait for samples to be collected

fft_window(); // window the data

fft_reorder(); // reorder for fft input

fft_run(); // process fft

fft_mag_log(); // take output of fft

Serial.write(255); // send out a start byte

Serial.write(fft_log_out, FFT_N/2); // send out data bytes

flag = 1; // tell the codec that processing is done

}

}

// timer1 interrupt routine - data collected here

ISR(TIMER1_COMPA_vect) { // store registers (NAKED removed)

// &'s are necessary on data_in variables

AudioCodec_data(&left_in, &right_in, left_out, right_out);

left_out = left_in; // pass audio through

right_out = right_in;

if (flag) { // check if the fft is ready for more data

fft_input[count] = left_in; // put real data into even bins

fft_input[count + 1] = 0; // put zeros in odd bins

count += 2; // increment to next bin

if (count >= FFT_N*2) { // check if all bins are full

flag = 0; // tell the fft to start running

count = 0; // reset the bin counter

}

}

}