![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Application example of FftReal class. FftReal クラスの使用例.
Dependencies: Array_Matrix mbed UIT_FFT_Real
main.cpp@2:03e1399ed9eb, 2015-10-29 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Oct 29 06:33:32 2015 +0000
- Revision:
- 2:03e1399ed9eb
- Parent:
- 1:f070e455cea0
- Child:
- 3:4ef52c7f5281
3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:5bed9d6dc43b | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 1:f070e455cea0 | 2 | // Demo program of FftReal class |
MikamiUitOpen | 2:03e1399ed9eb | 3 | // Copyright (c) 2015 MIKAMI, Naoki, 2015/10/29 |
MikamiUitOpen | 0:5bed9d6dc43b | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:5bed9d6dc43b | 5 | |
MikamiUitOpen | 0:5bed9d6dc43b | 6 | #include "dftComplex.hpp" |
MikamiUitOpen | 0:5bed9d6dc43b | 7 | #include "fftReal.hpp" |
MikamiUitOpen | 0:5bed9d6dc43b | 8 | |
MikamiUitOpen | 0:5bed9d6dc43b | 9 | #include "mbed.h" |
MikamiUitOpen | 0:5bed9d6dc43b | 10 | |
MikamiUitOpen | 0:5bed9d6dc43b | 11 | using namespace Mikami; |
MikamiUitOpen | 0:5bed9d6dc43b | 12 | |
MikamiUitOpen | 0:5bed9d6dc43b | 13 | int main() |
MikamiUitOpen | 0:5bed9d6dc43b | 14 | { |
MikamiUitOpen | 2:03e1399ed9eb | 15 | // const int N = 16; // number of date for FFT |
MikamiUitOpen | 2:03e1399ed9eb | 16 | const int N = 256; // number of date for FFT |
MikamiUitOpen | 0:5bed9d6dc43b | 17 | |
MikamiUitOpen | 0:5bed9d6dc43b | 18 | float x1[N], x2[N]; |
MikamiUitOpen | 0:5bed9d6dc43b | 19 | Complex y1[N], y2[N/2+1]; |
MikamiUitOpen | 0:5bed9d6dc43b | 20 | |
MikamiUitOpen | 1:f070e455cea0 | 21 | // Generate random data |
MikamiUitOpen | 0:5bed9d6dc43b | 22 | srand(1234); |
MikamiUitOpen | 0:5bed9d6dc43b | 23 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 24 | x1[n] = 2.0f*rand()/(float)RAND_MAX - 1.0f; |
MikamiUitOpen | 0:5bed9d6dc43b | 25 | printf("\r\n#### Original data for DFT ####\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 26 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 27 | printf("f[%2d]: %8.4f\r\n", n, x1[n]); |
MikamiUitOpen | 0:5bed9d6dc43b | 28 | |
MikamiUitOpen | 1:f070e455cea0 | 29 | // DFT, for comarison |
MikamiUitOpen | 0:5bed9d6dc43b | 30 | DftComplex(x1, y1, N); |
MikamiUitOpen | 0:5bed9d6dc43b | 31 | printf("\r\n#### Result of direct DFT ####\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 32 | printf(" real imaginary\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 33 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 34 | printf("F[%2d]: %8.4f, %8.4f\r\n", n, y1[n].real(), y1[n].imag()); |
MikamiUitOpen | 0:5bed9d6dc43b | 35 | |
MikamiUitOpen | 1:f070e455cea0 | 36 | Timer tm; // for measurement of execution time |
MikamiUitOpen | 0:5bed9d6dc43b | 37 | |
MikamiUitOpen | 1:f070e455cea0 | 38 | // FFT |
MikamiUitOpen | 0:5bed9d6dc43b | 39 | FftReal fft(N); |
MikamiUitOpen | 0:5bed9d6dc43b | 40 | tm.reset(); |
MikamiUitOpen | 0:5bed9d6dc43b | 41 | tm.start(); |
MikamiUitOpen | 0:5bed9d6dc43b | 42 | fft.Execute(x1, y2); |
MikamiUitOpen | 0:5bed9d6dc43b | 43 | tm.stop(); |
MikamiUitOpen | 0:5bed9d6dc43b | 44 | printf("\r\nExecution time (FFT): %d [us]\r\n", tm.read_us()); |
MikamiUitOpen | 0:5bed9d6dc43b | 45 | printf("\r\n#### Result of DFT using FFT ####\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 46 | for (int n=0; n<=N/2; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 47 | printf("F[%2d]: %8.4f, %8.4f\r\n", n, y2[n].real(), y2[n].imag()); |
MikamiUitOpen | 0:5bed9d6dc43b | 48 | |
MikamiUitOpen | 1:f070e455cea0 | 49 | // IFFT |
MikamiUitOpen | 0:5bed9d6dc43b | 50 | tm.reset(); |
MikamiUitOpen | 0:5bed9d6dc43b | 51 | tm.start(); |
MikamiUitOpen | 0:5bed9d6dc43b | 52 | fft.ExecuteIfft(y2, x2); |
MikamiUitOpen | 0:5bed9d6dc43b | 53 | tm.stop(); |
MikamiUitOpen | 0:5bed9d6dc43b | 54 | printf("\r\nExecution time (IFFT): %d [us]\r\n", tm.read_us()); |
MikamiUitOpen | 0:5bed9d6dc43b | 55 | printf("\r\n#### Result of IFFT ####\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 56 | printf(" original IFFT of FFT\r\n"); |
MikamiUitOpen | 0:5bed9d6dc43b | 57 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:5bed9d6dc43b | 58 | printf("f[%2d]: %8.4f, %8.4f\r\n", n, x1[n], x2[n]); |
MikamiUitOpen | 0:5bed9d6dc43b | 59 | } |