Hi I'm working on a project and got stuck on a part. I want to control led by using an audio signal.
The idea is to produce audio signals with Audacity software. The signals are mixtures of sound frequencies and each LED will be turned on when a certain frequency is present in the audio. For this I need a code that makes the decoding of frequency.
There are several examples of videos and examples that but did not get any full code.
The best I found so far are codes that use fix_fft.h library. I found it very good library and would understand it.

Basically I found several codes that are very similar to this example below.

For the success of my project I cant use the analog frequencies filter and the Processing software. I'd really like to understand this fix_fft.he library and use it, if is possible of course.

Complete code.

Void loop()
{
for (i=0; i < 128; i++){ // We don't go for clean timing here, it's
val = analogRead(0); // better to get somewhat dirty data fast
data = val/4 -128; // than to get data that's lab-accurate
_ im = 0; // but too slow, for this application._ * };* * fix_fft(data,im,7,0);*

* for (i=1; i< 64;i++){ // In the current design, 60Hz and noise* data = sqrt(data * data + im * im*); // in general are a problem. Future designs* TV.draw_line(i+x,lastpass*,i+x,ylim,0); // and code may fix this, but for now, I* TV.draw_line(i+x,ylim,i+x,ylim-data*,1); // skip displaying the 0-500hz band completely. lastpass_=ylim-data; // if you insist, initialize the loop with 0* * }; // rather than 1. };_ _What is the info out in "data"? How to use this output to know what freqs are in it? Some idiot example: If (freq > 200 & freq < 350) // do a thing* .... I already take the hardware, everything is working and I already make the signal turn on one bar of VU Led but no bases on freq just in intensity. So much thanks!_

In order to use the FFT you have to first understand what it is doing. The FFT is just a fast version of the Fourier Transform, explained here: http://www.thefouriertransform.com/

Hello, in the last days I've been studying the fourier transform. I had been studying before but tried to give more attention.
The link is good but does not explain much, so I found the lectures at Stanford University (youtube). I saw 10 classes and learned a lot, 50 minutes each one, still watching.

A differentiable function can be represented by sinusoidal functions and the sinusoidal can be represented by exponential function of e.
And fft can provide the magnitude and frequency, but still could not solve my problem. There is a big gap between the theoretical and mathematical part and codes, including the library fix_fft.h.

I tried reading the documentation but it does not explain much.
What I understand
data = sqrt(data * data + im * im); bring the magnitude but do not know how to use for diferent frequencies.

I saw other codes and now I am in doubt if I have to use the sine wave table or not.
Reading docs about it right now!

So what I mean is that I'm not badass for reading and see the lectures but I'm not lazy. I'm really not know what to do even what to study to solve my problem.
On the other hand there is kids under 12 years who have made a cube with fft and I doubt they know integral calculus.
So do not expect to have to learn all the theoretical to get the result I want. But if it is the only way I'll do.
If you can give me another light.

data = sqrt(data[] * data[] + im[] * im[]);
Data is an array, where "real" part of the complex (output fft is always complex numbers M = re + j * im), and im is an array with imaginary part. Position in this array 0-63 represent a freq. band, 0 to Fsampling/2. Bandwidth = Fsampl. / 2*64
So , if you are sampling input with let say 20 kHz sampling rate, Bandwidth = 156.25 Hz./bin
than your data[63] + j * im[63]) is the magnitude in bands:
data[1] = 156,
data[2] = 312
data[3] = ....
data[63] = 9843.75 Hz

int fix_fft(char fr[], char fi[], int m, int inverse);

Then the array fr[] initially contains your audio samples and the array fi[] is set to zero, initially.

When fix_fft is done, it returns numbers in the arrays fr[] and fi[]. You can interpret those numbers by calculating

amplitude = sqrt(fr[i]*fr[i] + fi[i]*fi[i]);

where amplitude is the "amount" of pure sinewave tone at frequency i, in the original audio sample.

How you interpret "i" as a frequency in Hz depends on your sample rate and the number of points in the sample. There are plenty of examples, as Magician above has done.