Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:099f1a4c5fc8
- Parent:
- 0:8c128e047ec9
--- a/main.cpp Tue Mar 28 08:48:23 2017 +0000
+++ b/main.cpp Wed Mar 29 08:42:31 2017 +0000
@@ -1,18 +1,20 @@
#include "mbed.h"
-#include "DFT.h"
+#include "FFT.h"
#include "LookupTables.h"
#include "complexmath.h"
#include <math.h>
-//TODO right values for the twiddle factors LUT equalizer LUT bitreverse LUT in LookupTables
+//TODO right values for the LUT equalizer
//TODO Build all functions in FFT.cpp
//TODO fix main for a test wave and communication to serial
Serial pc(USBTX, USBRX);
-float sampleDataIn [512];
+float sampleDataIn[512];
float sampleDataOut[512];
+complex_num freqValues[512];
+complex_num reordereddata[512];
int datalength = 512;//uitrekenen?
int main()
@@ -22,15 +24,51 @@
for (int i=0; i<511; i++){
if (i%128<64){
sampleDataIn[i]=1000;
- pc.printf ("%f,\t",sampleDatain[i]);
+ pc.printf ("%f,\t",sampleDataIn[i]);
}
else{
sampleDataIn[i]=0;
- pc.printf ("%f,\t",sampleDatain[i]);
+ pc.printf ("%f,\t",sampleDataIn[i]);
}
+ }
sampleDataIn[511]=0;
- pc.printf("%f]\r\n",sampleDataOut[511]);
- performEqualizer(&sampleDataIn, &sampleDataOut,datalength);
+ pc.printf("%f]\r\n",sampleDataIn[511]);
+ //dont performEqualizer(&sampleDataIn, &sampleDataOut, &freqValues, datalength); but seperate functions for testing purposes
+ // - Calculating and substracting the mean -
+ subMean(sampleDataIn, datalength);
+ pc.printf ("zero meaned:[");
+ for (int i=0; i<511; i++){
+ pc.printf ("%f,\t",sampleDataIn[i]);
+ }
+ pc.printf("%f]\r\n",sampleDataIn[511]);
+ // - Applying a hanning window - N multiplications
+ applyHanningTable(sampleDataIn, datalength);
+ pc.printf ("hanned:[");
+ for (int i=0; i<511; i++){
+ pc.printf ("%f,\t",sampleDataIn[i]);
+ }
+ pc.printf("%f]\r\n",sampleDataIn[511]);
+ // It then applies a radix-2 Cooley Tukey FFT to create a fourier transform
+ reverseCooleyTukeyRadix2(sampleDataIn, freqValues, datalength);
+
+ for (int i = 0; i < datalength; i++){
+ reordereddata[reversebit_lut_i[i]].real = freqValues[i].real;
+ reordereddata[reversebit_lut_i[i]].imaginary = freqValues[i].imaginary;
+ }
+ pc.printf ("real part of freqValues:[");
+ for (int i=0; i<511; i++){
+ pc.printf ("%f,\t",reordereddata[i].real);
+ }
+ pc.printf("%f]\r\n",reordereddata[511].real);
+ pc.printf ("imaginary part of freqValues:[");
+ for (int i=0; i<511; i++){
+ pc.printf ("%f,\t",reordereddata[i].imaginary);
+ }
+ pc.printf("%f]\r\n",reordereddata[511].imaginary);
+ // It gets equalized
+ //equalizer(complex_num* freqdata);
+ // back to time domain
+ cooleyTukeyBack(sampleDataOut, freqValues, datalength);
pc.printf ("Equalized data :[");
for (int i=0; i<511; i++) {
pc.printf ("%f,\t",sampleDataOut[i]);