Created
November 21, 2013 08:50
-
-
Save shurru/7578087 to your computer and use it in GitHub Desktop.
FFT on Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <math.h> | |
| int Voice = A0; // select the input pin for the potentiometer | |
| int sensorValue=0; | |
| void setup() { | |
| Serial.begin(115200); | |
| pinMode(Voice, INPUT); | |
| } | |
| void loop() { | |
| // read the value from the sensor: | |
| fourier(); | |
| delay(2000); | |
| } | |
| void fourier() | |
| { | |
| int var= 0; | |
| while (var<1){ | |
| int h= 64; | |
| double f[h]; | |
| double F[h]; | |
| double Y[h]; | |
| double Real[h]; | |
| double Imag[h]; | |
| double Final[8]; | |
| for (int i=0; i<h; i=i+1) | |
| { | |
| Real[i]=0; | |
| } | |
| for (int i=0; i < h; i=i+1){ | |
| Imag[i]=0; | |
| } | |
| for (int i=0; i < h; i=i+1){ | |
| f[i]=analogRead(Voice)*(5/1024); //Reads the voltage from the sensor and feeds into f[] | |
| } | |
| for (int i=0; i < 7; i=i+1){ | |
| Final[i]=0; | |
| } | |
| for(int j=0; j<h;j=j++){ | |
| for(int u=0; u<h;u=u+1){ | |
| Real[j]=Real[j]+ f[u]*sin((2*3.14*u*j/h)); // Real part of the vector | |
| Imag[j]=Imag[j]+ f[u]*cos(-2*3.14*u*j/h); // Imaginary part of the vector | |
| } | |
| F[j]=sqrt(pow(Real[j],2)+pow(Imag[j],2)); | |
| } | |
| for (int i=0; i < 31; i=i+1){ | |
| Y[i]=F[32+i]; | |
| } | |
| for (int i=0; i < 30; i=i+1){ | |
| Y[i+31]=F[i+1]; | |
| Serial.println(Y[i]); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment