Go Down

Topic: Music Labs FFT Library (Read 1 time) previous topic - next topic


Has anybody tried to use the music labs FFT library? The one on the following link http://wiki.openmusiclabs.com/wiki/ArduinoFFT

The example code they have given won't compile and just wondering why. Does anybody else have the same issues?

Code: [Select]
guest openmusiclabs.com 8.18.12
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.  there is a pure data patch for
visualizing the data.

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

void setup() {
  Serial.begin(115200); // use the serial port
  TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0

void loop() {
  while(1) { // reduces jitter
    cli();  // UDRE interrupt slows this way down on arduino1.0
    for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
      while(!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fft_input[i] = k; // put real data into even bins
      fft_input[i+1] = 0; // set odd bins to 0
    fft_window(); // window the data for better frequency response
    fft_reorder(); // reorder the data before doing the fft
    fft_run(); // process the data in the fft
    fft_mag_log(); // take the output of the fft
    Serial.write(255); // send a start byte
    Serial.write(fft_log_out, 128); // send out the data


The example code they have given won't compile

Using what version of the IDE? What errors?


I have tried IDE 1.0, 1.0.5 and 1.5.2.

I get the following errors:
fft_adc.pde: In function 'void loop()':
fft_adc:35: error: 'fft_input' was not declared in this scope
fft_adc:38: error: 'fft_window' was not declared in this scope
fft_adc:39: error: 'fft_reorder' was not declared in this scope
fft_adc:40: error: 'fft_run' was not declared in this scope
fft_adc:41: error: 'fft_mag_log' was not declared in this scope
fft_adc:44: error: 'fft_log_out' was not declared in this scope

I can get rid of the first error by defining the variable fft_input in the sketch however, the other errors are functions/methods and should be in the header file.


You may not have installed the library properly. The FFT directory in the zip file must be installed in your libraries directory.




Did you ever figure out why you were getting this error? I am getting the same one.

Blue Eyes

The folder structure is incorrect in the downloaded library.  Put the folder named "FFT" in the Arduino libraries folder and the example will compile (you don't need to add a variable).


What do you mean that the structure is incorrect in the downloaded library? I unzipped the FFT library in the arduino library folder like it was suggested above. I did not add anything to the code, I just attempted to compile it.

Blue Eyes

Sorry, I was not clear.  If you download the library you get a folder named "ArduinoFFT2-1".  Inside that folder is a folder named "FFT".  The latter needs to be in the top level of the Arduino libraries folder.  

I copied "ArduinoFFT2-1" to the libraries folder, renaming it to "ArduinoFFT2" because of an error message and got the same results as you.  After moving the "FET" folder up one level, so that it is directly under the"libraries" folder I could open the example sketch through file=>examples=>FFT and it compiles.


Fantastic! Thank you for that clear explanation blue eyes, I will give that a go after getting some more class work done.  :)


Ah, still the same issue. My computer organizes it alphabetically so I changed the name of the folders a bit to get them where you suggested. It goes libraries folder --> AArduinoFFT2 folder --> FFT folder but same results.

Blue Eyes

Nov 10, 2015, 04:51 am Last Edit: Nov 10, 2015, 05:03 am by Blue Eyes
It should be ibraries folder  --> FFT folder..

You'll know you have it correct when you choose Sketch=>Import Library and you see FFT on the list.

Don't forget that you have to quit and restart the IDE if it is running when you move files around.


I guess the name of that folder does not really matter too much more than being able to identify it. I just labeled it with a double A to put it at the top like you suggested. I can see the library and examples in the arduino IDE and reset the IDE after each change. Did you get the same error as me or was it something different? Im on another forum post that I created (http://forum.arduino.cc/index.php?topic=358314.new#new). I am thinking the #define is not working. the .h file is in my library. The FFT library has been installed correctly in two different ways --> only one FFT folder is in the library, I just tried two different ways. It seems it just is not including the .h file.

Blue Eyes

I think you misunderstood because I was not suggesting that you rename anything.

From the top:  you download the file ArduinoFFT2.zip.  Unzip and inside ArduinoFFT2 you see two folders:  FFT and reorder_table_creator plus a file named arduinofft_display.pd.

Drag JUST THE FFT folder into the Arduino libraries folder.

So on my computer FFT.h is at Documents/Arduino/libraries/FFT/FFT.h.


BLUE EYES! YES! solution found. I separated the FFT folder from the main folder and no compiling errors. Thank you very much for your help.  ;D I would give you Karma but I have to wait an hour.. not a big fan of waiting 10min (which I had to do to post this after trying to help another out) nor am I a fan of waiting to give karma points. Probably people misused their freedom and clogged up the system or something. I wish I could buy you a beer or glass of wine buddy.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131