Page 1 of 1

Saving the Spectrum of an Audio Signal, FFT Example

PostPosted: Mon Jan 21, 2013 3:11 pm
by lore52

I am a novice and I am trying to save the spectrum of a signal after running the FFT example code. I have sent an audio signal from my computer's headphone jack to line_in jack of the Audio Codec Shield using a male-male audio cable.

Then I opened the serial monitor and set the appropriate baud rate. I saw some characters flashing across the window and after a while the IDE froze.

Is there a method that I can implement to save the data in a human-readable format? I tried to use Processing and the Graph example given here

I will appreciate it if someone can point me to the right direction. Thanks in advance.

Re: Saving the Spectrum of an Audio Signal, FFT Example

PostPosted: Tue Jan 22, 2013 1:18 am
by guest
it might be that too much data is coming in too fast for the computer to handle it, and then it overflows the buffer on the ide. try putting a delay(100) after you call the fft_run() function. the data will probably also not be in a human readable form, so you can try using serial.println() instead of the serial.write() that the example code uses.

Re: Saving the Spectrum of an Audio Signal, FFT Example

PostPosted: Wed Jan 23, 2013 12:36 am
by guest
i just remembered that you said you are using the codecshield with this. delay() wont work, as it will mess up the data transfer to the codec. instead, only send out data every so often. change your loop code to this:

Code: Select all
void loop() {
  while(1) { // reduces clock jitter
    while(flag); // wait for samples to be collected
    if (counter == 0) {
      fft_window(); // window the data
      fft_reorder(); // reorder for fft input
      fft_run(); // process fft
      fft_mag_log(); // take output of fft
      Serial.println(255); // send out a start byte
      // used for alignment, may not be needed
      for (byte i = 0; i < FFT_N/2; i++) {
        Serial.println(fft_log_out[i], DEC); // send out data bytes
      counter = 256; // this adjusts the update rate
    flag = 1; // tell the codec that processing is done

note that the serial.write() has been changed to serial.println() so its human readable, and the counter variable is added. you can change how often the data is sent by change what you set it to at the end of the loop. be sure to declare counter at the beginning of your sketch

int counter = 0;