![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Application example of FftReal class. FftReal クラスの使用例.
Dependencies: Array_Matrix mbed UIT_FFT_Real
main.cpp@4:8248d5b5cdc9, 2020-12-12 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Dec 12 03:21:58 2020 +0000
- Revision:
- 4:8248d5b5cdc9
- Parent:
- 3:4ef52c7f5281
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:5bed9d6dc43b | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 4:8248d5b5cdc9 | 2 | // FftReal クラスのデモ用プログラム |
MikamiUitOpen | 3:4ef52c7f5281 | 3 | // |
MikamiUitOpen | 4:8248d5b5cdc9 | 4 | // 2020/12/12, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:5bed9d6dc43b | 5 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:5bed9d6dc43b | 6 | |
MikamiUitOpen | 4:8248d5b5cdc9 | 7 | #include "dftReal.hpp" |
MikamiUitOpen | 0:5bed9d6dc43b | 8 | #include "fftReal.hpp" |
MikamiUitOpen | 0:5bed9d6dc43b | 9 | using namespace Mikami; |
MikamiUitOpen | 4:8248d5b5cdc9 | 10 | #pragma diag_suppress 870 // マルチバイト文字使用の警告抑制のため |
MikamiUitOpen | 0:5bed9d6dc43b | 11 | |
MikamiUitOpen | 0:5bed9d6dc43b | 12 | int main() |
MikamiUitOpen | 0:5bed9d6dc43b | 13 | { |
MikamiUitOpen | 4:8248d5b5cdc9 | 14 | const int N = 16; // FFT のデータ数 |
MikamiUitOpen | 4:8248d5b5cdc9 | 15 | // const int N = 256; // FFT のデータ数 |
MikamiUitOpen | 0:5bed9d6dc43b | 16 | |
MikamiUitOpen | 0:5bed9d6dc43b | 17 | float x1[N], x2[N]; |
MikamiUitOpen | 0:5bed9d6dc43b | 18 | Complex y1[N], y2[N/2+1]; |
MikamiUitOpen | 0:5bed9d6dc43b | 19 | |
MikamiUitOpen | 4:8248d5b5cdc9 | 20 | // 乱数生成 |
MikamiUitOpen | 0:5bed9d6dc43b | 21 | srand(1234); |
MikamiUitOpen | 0:5bed9d6dc43b | 22 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 23 | x1[n] = 2.0f*rand()/(float)RAND_MAX - 1.0f; |
MikamiUitOpen | 4:8248d5b5cdc9 | 24 | printf("\r\n#### 元のデータ ####\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 25 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 26 | printf("f[%2d]: %8.4f\r\n", n, x1[n]); |
MikamiUitOpen | 0:5bed9d6dc43b | 27 | |
MikamiUitOpen | 4:8248d5b5cdc9 | 28 | Timer tm; // 実行時間測定のため |
MikamiUitOpen | 3:4ef52c7f5281 | 29 | |
MikamiUitOpen | 4:8248d5b5cdc9 | 30 | // DFT, 比較のため |
MikamiUitOpen | 3:4ef52c7f5281 | 31 | tm.reset(); |
MikamiUitOpen | 3:4ef52c7f5281 | 32 | tm.start(); |
MikamiUitOpen | 4:8248d5b5cdc9 | 33 | DftReal(x1, y1, N); |
MikamiUitOpen | 3:4ef52c7f5281 | 34 | tm.stop(); |
MikamiUitOpen | 4:8248d5b5cdc9 | 35 | printf("\r\n実行時間 (DFT): %d [μs]\r\n", tm.read_us()); |
MikamiUitOpen | 0:5bed9d6dc43b | 36 | |
MikamiUitOpen | 1:f070e455cea0 | 37 | // FFT |
MikamiUitOpen | 0:5bed9d6dc43b | 38 | FftReal fft(N); |
MikamiUitOpen | 0:5bed9d6dc43b | 39 | tm.reset(); |
MikamiUitOpen | 0:5bed9d6dc43b | 40 | tm.start(); |
MikamiUitOpen | 0:5bed9d6dc43b | 41 | fft.Execute(x1, y2); |
MikamiUitOpen | 0:5bed9d6dc43b | 42 | tm.stop(); |
MikamiUitOpen | 4:8248d5b5cdc9 | 43 | printf("実行時間 (FFT): %d [μs]\r\n", tm.read_us()); |
MikamiUitOpen | 4:8248d5b5cdc9 | 44 | |
MikamiUitOpen | 4:8248d5b5cdc9 | 45 | printf("\r\n#### DFT と FFT による結果 ####\r\n"); |
MikamiUitOpen | 4:8248d5b5cdc9 | 46 | printf(" 実部 虚部 実部 虚部\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 47 | for (int n=0; n<=N/2; n++) |
MikamiUitOpen | 4:8248d5b5cdc9 | 48 | printf("F[%2d]: %8.4f, %8.4f; %8.4f, %8.4f\r\n", |
MikamiUitOpen | 4:8248d5b5cdc9 | 49 | n, y1[n].real(), y1[n].imag(), y2[n].real(), y2[n].imag()); |
MikamiUitOpen | 0:5bed9d6dc43b | 50 | |
MikamiUitOpen | 1:f070e455cea0 | 51 | // IFFT |
MikamiUitOpen | 0:5bed9d6dc43b | 52 | tm.reset(); |
MikamiUitOpen | 0:5bed9d6dc43b | 53 | tm.start(); |
MikamiUitOpen | 0:5bed9d6dc43b | 54 | fft.ExecuteIfft(y2, x2); |
MikamiUitOpen | 0:5bed9d6dc43b | 55 | tm.stop(); |
MikamiUitOpen | 4:8248d5b5cdc9 | 56 | printf("\r\n実行時間 (IFFT): %d [μs]\r\n", tm.read_us()); |
MikamiUitOpen | 4:8248d5b5cdc9 | 57 | printf("\r\n#### IFFT の結果 ####\r\n"); |
MikamiUitOpen | 4:8248d5b5cdc9 | 58 | printf(" 元の値 FFT の IFFT\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 59 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 60 | printf("f[%2d]: %8.4f, %8.4f\r\n", n, x1[n], x2[n]); |
MikamiUitOpen | 3:4ef52c7f5281 | 61 | } |