Application example of FftReal class. FftReal クラスの使用例.

Dependencies:   Array_Matrix mbed UIT_FFT_Real

Revision:
0:5bed9d6dc43b
Child:
1:f070e455cea0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Dec 19 12:12:12 2014 +0000
@@ -0,0 +1,54 @@
+//--------------------------------------------------------------
+// Test of FftReal class
+// Copyright (c) 2014 MIKAMI, Naoki,  2014/12/19
+//--------------------------------------------------------------
+
+#include "dftComplex.hpp"
+#include "fftReal.hpp"
+
+#include "mbed.h"
+
+using namespace Mikami;
+
+int main()
+{
+    const int N = 256;//16;       // number of date for FFT
+
+    float x1[N], x2[N];
+    Complex y1[N], y2[N/2+1];
+
+    srand(1234);
+    for (int n=0; n<N; n++)
+        x1[n] = 2.0f*rand()/(float)RAND_MAX - 1.0f;
+    printf("\r\n#### Original data for DFT ####\r\n");
+    for (int n=0; n<N; n++)
+        printf("f[%2d]: %8.4f\r\n", n, x1[n]);
+
+    DftComplex(x1, y1, N);
+    printf("\r\n#### Result of direct DFT ####\r\n");
+    printf("          real    imaginary\r\n");
+    for (int n=0; n<N; n++)
+        printf("F[%2d]: %8.4f, %8.4f\r\n", n, y1[n].real(), y1[n].imag());
+
+    Timer tm;
+
+    FftReal fft(N);
+    tm.reset();
+    tm.start();
+    fft.Execute(x1, y2);
+    tm.stop();
+    printf("\r\nExecution time (FFT): %d [us]\r\n", tm.read_us());
+    printf("\r\n#### Result of DFT using FFT ####\r\n");
+    for (int n=0; n<=N/2; n++)
+        printf("F[%2d]: %8.4f, %8.4f\r\n", n, y2[n].real(), y2[n].imag());
+    
+    tm.reset();
+    tm.start();
+    fft.ExecuteIfft(y2, x2);
+    tm.stop();
+    printf("\r\nExecution time (IFFT): %d [us]\r\n", tm.read_us());
+    printf("\r\n#### Result of IFFT ####\r\n");
+    printf("        original  IFFT of FFT\r\n");
+    for (int n=0; n<N; n++)
+        printf("f[%2d]: %8.4f, %8.4f\r\n", n, x1[n], x2[n]);
+}