It still doesn't seem to be working. I replaced all the lines of code with the new good ones. Here is the new and full code:
#define FFTSIZE 8
#define _PI 6.28
float input[FFTSIZE];
float output[FFTSIZE];
const float sina[FFTSIZE] = {
0, 0.71, 1, 0.71, 0, -0.71, -1, -0.71
};
const float cosa[FFTSIZE] = {
1, 0.71, 0, -0.71, -1, -0.71, 0, 0.71
};
void setup() {
Serial.begin(9600);
}
void loop() {
for(int count = 1; count <= 4; count++) {
for(int counter = 0; counter < FFTSIZE; counter++) {
input[counter] = sin(_PI * count * counter / FFTSIZE);
}
Serial.println();
FFT();
Serial.println("FFT Values Return:");
for(int counter = 0; counter < FFTSIZE; counter++) {
Serial.println(output[counter]);
}
}
while(1);
}
void FFT() {
float C[FFTSIZE];
float S[FFTSIZE];
float X[FFTSIZE];
float Y[FFTSIZE];
float Z[FFTSIZE];
// buterfly 2
C[0] = (input[0] * cosa[0]);
C[1] = (input[0] * cosa[4]);
C[2] = (input[1] * cosa[0]);
C[3] = (input[1] * cosa[4]);
C[4] = (input[2] * cosa[0]);
C[5] = (input[2] * cosa[4]);
C[6] = (input[3] * cosa[0]);
C[7] = (input[3] * cosa[4]);
S[0] = (input[4] * sina[0]);
S[1] = (input[4] * sina[4]);
S[2] = (input[5] * sina[0]);
S[3] = (input[5] * sina[4]);
S[4] = (input[6] * sina[0]);
S[5] = (input[6] * sina[4]);
S[6] = (input[7] * sina[0]);
S[7] = (input[7] * sina[4]);
X[0] = C[0] + S[0];
X[1] = C[1] - S[1];
X[2] = C[2] + S[2];
X[3] = C[3] - S[3];
X[4] = C[4] + S[4];
X[5] = C[5] - S[5];
X[6] = C[6] + S[6];
X[7] = C[7] - S[7];
// butterfly 4
Y[0] = (X[0] * cosa[0]) + (X[2] * sina[0]);
Y[1] = (X[1] * cosa[2]) + (X[3] * sina[2]);
Y[2] = (X[0] * cosa[0]) - (X[2] * sina[0]);
Y[3] = (X[1] * cosa[2]) - (X[3] * sina[2]);
Y[4] = (X[4] * cosa[0]) + (X[6] * sina[0]);
Y[5] = (X[5] * cosa[2]) + (X[7] * sina[2]);
Y[6] = (X[4] * cosa[0]) - (X[6] * sina[0]);
Y[7] = (X[5] * cosa[2]) - (X[7] * sina[2]);
// final butterfly 8
output[0] = (Y[0] * cosa[0]) + (Y[4] * sina[0]);
output[1] = (Y[1] * cosa[1]) + (Y[5] * sina[1]);
output[2] = (Y[2] * cosa[2]) + (Y[6] * sina[2]);
output[3] = (Y[3] * cosa[3]) + (Y[7] * sina[3]);
output[4] = (Y[0] * cosa[0]) - (Y[4] * sina[0]);
output[5] = (Y[1] * cosa[1]) - (Y[5] * sina[1]);
output[6] = (Y[2] * cosa[2]) - (Y[6] * sina[2]);
output[7] = (Y[3] * cosa[3]) - (Y[7] * sina[3]);
}
I get these results from the serial terminal, each time the loop repeats the input sinewave increases by 1 cycle over the 8 samples:
FFT Values Return:
0.00
-1.00
1.00
0.00
0.00
0.00
-1.00
-1.00
FFT Values Return:
0.00
-0.00
0.00
-1.42
0.00
-1.42
-0.00
-0.00
FFT Values Return:
0.00
-1.00
-1.00
-0.00
0.00
-0.00
1.00
-1.00
FFT Values Return:
0.00
-0.00
-0.00
0.00
0.00
0.00
0.00
-0.00
What's wrong with this?! Again, it seems as though it is working with some values, and not for others, specifically try #2.
Thanks,
Judd