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

Dependencies:   Array_Matrix mbed UIT_FFT_Real

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Sat Dec 12 03:21:58 2020 +0000
Parent:
3:4ef52c7f5281
Commit message:
5

Changed in this revision

UIT_FFT_Real.lib Show annotated file Show diff for this revision Revisions of this file
dftComplex.hpp Show diff for this revision Revisions of this file
dftReal.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/UIT_FFT_Real.lib	Mon Jan 13 08:57:54 2020 +0000
+++ b/UIT_FFT_Real.lib	Sat Dec 12 03:21:58 2020 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/MikamiUitOpen/code/UIT_FFT_Real/#dc123081d491
+http://developer.mbed.org/users/MikamiUitOpen/code/UIT_FFT_Real/#0b4975fffc90
--- a/dftComplex.hpp	Mon Jan 13 08:57:54 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-//--------------------------------------------------------------
-// DIscrete Fourier transform (DFT)
-// Copyright (c) 2014 MIKAMI, Naoki,  2014/06/28
-//--------------------------------------------------------------
-
-#include "mbed.h"
-#include <complex>  // requisite for complex
-
-typedef complex<float> Complex;     // define "Complex"
-
-void DftComplex(const float x[], Complex y[], int nFft);
-
-// Calculate DFT
-void DftComplex(const float x[], Complex y[], int nFft)
-{
-    Complex j2PiN = Complex(0, -6.28318531f/nFft);
-
-    for (int k=0; k<nFft; k++)
-    {
-        y[k] = 0.0;
-        for (int n=0; n<nFft; n++)
-            y[k] = y[k] + x[n]*exp(j2PiN*(float)(n*k));
-    }
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dftReal.hpp	Sat Dec 12 03:21:58 2020 +0000
@@ -0,0 +1,29 @@
+//--------------------------------------------------------------
+//	離散的フーリエ変換 (DFT)
+//
+//  2020/12/12, Copyright (c) 2020 MIKAMI, Naoki
+//--------------------------------------------------------------
+
+#include "mbed.h"
+#include <complex>  // complex で使用
+
+#ifndef DFT_REAL_HPP
+#define DFT_REAL_HPP
+
+typedef complex<float> Complex;     // "Complex" の定義
+
+void DftReal(const float x[], Complex y[], int nFft);
+
+//  DFT の計算
+void DftReal(const float x[], Complex y[], int nFft)
+{
+    Complex j2PiN = Complex(0, -6.28318531f/nFft);
+
+    for (int k=0; k<nFft; k++)
+    {
+        y[k] = 0.0;
+        for (int n=0; n<nFft; n++)
+            y[k] = y[k] + x[n]*exp(j2PiN*(float)(n*k));
+    }
+}
+#endif	// DFT_REAL_HPP
\ No newline at end of file
--- a/main.cpp	Mon Jan 13 08:57:54 2020 +0000
+++ b/main.cpp	Sat Dec 12 03:21:58 2020 +0000
@@ -1,42 +1,38 @@
 //--------------------------------------------------------------
-// Demo program of FftReal class
+//  FftReal クラスのデモ用プログラム
 //
-// Copyright (c) 2020 MIKAMI, Naoki,  2020/01/13
+//  2020/12/12, Copyright (c) 2020 MIKAMI, Naoki
 //--------------------------------------------------------------
 
-#include "dftComplex.hpp"
+#include "dftReal.hpp"
 #include "fftReal.hpp"
-
 using namespace Mikami;
+#pragma diag_suppress 870   // マルチバイト文字使用の警告抑制のため
 
 int main()
 {
-//    const int N = 16;       // number of date for FFT
-    const int N = 256;       // number of date for FFT
+    const int N = 16;       // FFT のデータ数
+//    const int N = 256;       // FFT のデータ数
 
     float x1[N], x2[N];
     Complex y1[N], y2[N/2+1];
 
-    // Generate random data
+    // 乱数生成
     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");
+    printf("\r\n#### 元のデータ ####\r\n");
     for (int n=0; n<N; n++)
         printf("f[%2d]: %8.4f\r\n", n, x1[n]);
 
-    Timer tm;   // for measurement of execution time
+    Timer tm;   // 実行時間測定のため
 
-    // DFT, for comarison
+    // DFT, 比較のため
     tm.reset();
     tm.start();
-    DftComplex(x1, y1, N);
+    DftReal(x1, y1, N);
     tm.stop();
-    printf("\r\nExecution time (DFT): %d [us]\r\n", tm.read_us());
-    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());
+    printf("\r\n実行時間 (DFT): %d [μs]\r\n", tm.read_us());
 
     // FFT
     FftReal fft(N);
@@ -44,19 +40,22 @@
     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");
+    printf("実行時間 (FFT): %d [μs]\r\n", tm.read_us());
+
+    printf("\r\n#### DFT と FFT による結果 ####\r\n");
+    printf("          実部      虚部      実部      虚部\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());
+        printf("F[%2d]: %8.4f, %8.4f; %8.4f, %8.4f\r\n",
+               n, y1[n].real(), y1[n].imag(), y2[n].real(), y2[n].imag());
     
     // IFFT
     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");
+    printf("\r\n実行時間 (IFFT): %d [μs]\r\n", tm.read_us());
+    printf("\r\n#### IFFT の結果 ####\r\n");
+    printf("        元の値    FFT の IFFT\r\n");
     for (int n=0; n<N; n++)
         printf("f[%2d]: %8.4f, %8.4f\r\n", n, x1[n], x2[n]);
 }
\ No newline at end of file