openmusiclabs FFT/FHT library

Am i posting here because i don’t see the option to register at Open Music Labs Forums • Index page
(It also says 0 registered users etc. at the bottom?)

Anyway, does anybody have any experience with either of these libaries. I am using Arduino Uno or Nano and this electret mic Electret Microphone Amplifier - MAX4466 with Adjustable Gain : ID 1063 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

http://wiki.openmusiclabs.com/wiki/ArduinoFFT
http://wiki.openmusiclabs.com/wiki/ArduinoFHT

I have read a lot about FFT and admit i don’t fully understand the math behind it, as far I understand the output is a series of amplitudes on the frequency domain. So I read that I have to take the array of magnitudes and calculate the frequency based on these. I already found all kinds of threads and code examples for this.

The only problem is that the FFT library works until i call the fft_mag_lin() function. The example uses C code that i am not at all familiar with. Upon using the function it errors within the library itself.

sketch\FFT_test.ino.cpp.o: In function `fft_mag_lin':

C:\Program Files (x86)\Arduino\libraries\FFT/FFT.h:1119: undefined reference to `fft_lin_out'

C:\Program Files (x86)\Arduino\libraries\FFT/FFT.h:1119: undefined reference to `fft_lin_out'

C:\Program Files (x86)\Arduino\libraries\FFT/FFT.h:1119: undefined reference to `_lin_table'

C:\Program Files (x86)\Arduino\libraries\FFT/FFT.h:1119: undefined reference to `_lin_table'

But as I said I can look at the library code but have no idea what I am looking at. Please note that the normal FFT function works fine and i also get output from these. It’s just this function that throws an error.

Also the FHT library just doesn’t work at all for me, one of the errors it gives is.

C:\Program Files (x86)\Arduino\libraries\FHT/FHT.h:72:10: error: 'prog_int16_t' does not name a type

Maybe this will help with the FFT
FFT Defines

I missed that but it didn't work.
Used #define LIN_OUT 1 but the lib still errors.

You did not post your code. Please read and follow the instructions in "How to use this forum".

jremington:
You did not post your code. Please read and follow the instructions in "How to use this forum".

Oh sorry, I thought it would be obvious I was using the example code provided.

http://wiki.openmusiclabs.com/wiki/Example

What version of the IDE are you using? Which library? There seems to be 3 versions available.

Arduino FHT

Files

Library(2.0): Arduino1.0 (updated for PROGMEM problem - thanks to forum user kirill9617, and added serial example). Should work with older versions of Arduino as well.

Arduino FHT library (new)

Library(2.1): Arduino1.0 (experimental - saved registers removed from clobber list to eliminate "r28"/"r29" compiler error).

Arduino FHT library (experimental)

Library(1.0): Arduino1.0 or Arduino-0022 (should work with both)

Arduino FHT library (old)

Turns out I was using the example code that was just a little bit different somehow but I was previously using another one and that is working again.

So I now have a magnitude array, and I am trying to get the frequency from the magnitude array the fft outputs. But i don’t feel like the output is correct?

I read a human voice can go up to 260hz, on youtube i listened to a 500hz (-3db) sound which didn’t sound like it was a lot of noise.

        float freq_array[FFT_N/2];
        float hz_rate = 1440; //SAMPLING RATE ARDUINO UNO!
        float max_freq = 0;
        
        //Magnitudes to frequencies
        for (byte i = 0 ; i < FFT_N/2 ; i++) { 
          
          freq_array[i] = fft_log_out[i] * hz_rate / FFT_N;
          
          if(freq_array[i] > max_freq) {
            //filter first two (artefacts?)
            if(i >= 2) { max_freq = freq_array[i]; }
          }
        }

Based on;

RIgth now I run this code 5 times, so get 5 arrays with 128 elements (sample rate 256). And then i take the peak frequencies from these.

The output is this.

511.88 540.00 483.75 495.00 495.00 

500.63 511.88 506.25 506.25 506.25 

495.00 483.75 483.75 500.63 472.50

There is somekind of AC unit going on in the background, but when people cough or talk the numbers do go up (because of magnitude?).

I was thinking maybe my hz_rate variable (which is sample rate related to the arduino itself) is not correct?

Which means it would be hard to test is as according to this thread;

I am limited by the serial communication for example I am using 115200 baud rate right now, in their example printing 8 characters each taking 10 bits would mean 115200 / 80 = 1440.

The way to test programs like this, and to learn to understand what the result means, is to generate a known signal and feed it to the program. For the FFT you can quite easily simulate a pure tone signal using the sin() function.

I suggest to avoid youtube and do some actual reading, because this is simply wrong:

I read a human voice can go up to 260hz, on youtube

If you have a smart phone, you can download tone generator apps (Android anyway) that output tones on the phone speaker. Then you can easily test with different frequencies.

download tone generator apps

I was also thinking to suggest using a phone to generate tones, but keep in mind that it is impossible for a phone speaker to generate a pure sine wave. The output signal will be distorted and have harmonics at 2x, 3x, 4x, ... the lowest frequency.