add more reference curves

This commit is contained in:
Jörg Thalheim 2015-03-03 08:20:13 +01:00
parent c6ee251c46
commit 29fada95b1
2 changed files with 43 additions and 21 deletions

2
fft.h
View File

@ -21,4 +21,4 @@ extern fixed Sinewave[N_WAVE];
fixed fix_mpy(fixed a, fixed b); fixed fix_mpy(fixed a, fixed b);
int fix_fft(fixed *fr, fixed *fi, int m, int inverse); int fix_fft(fixed *fr, fixed *fi, int m, int inverse);
#endif //FFT_H #endif //FFT_H

62
main.c
View File

@ -1,8 +1,8 @@
//main.c //main.c
#include "fft.h" #include "fft.h"
#include "fft-org.h" #include "fft-org.h"
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
@ -12,9 +12,25 @@
//number of points //number of points
#define N (1<<M) #define N (1<<M)
#define M2 100
#define N2 (3<<M)
fixed real[N], imag[N]; fixed real[N], imag[N];
fixed real_org[N], imag_org[N]; fixed real_org[N], imag_org[N];
void show_result(fixed* real, fixed* real_org, fixed* imag, fixed* imag_org, int n)
{
int i;
for (i=0; i<n; i++)
{
printf("%d: %d, %d", i, real[i], imag[i]);
if (real[i] != real_org[i] || imag[i] != imag_org[i]) {
printf(" expected (%d, %d)", real_org[i], imag_org[i]);
}
printf("\n");
}
}
int main() int main()
{ {
int i; int i;
@ -22,7 +38,7 @@ int main()
for(i=0; i<N; i++) for(i=0; i<N; i++)
{ {
real[i] = 1000*cos(i*2*3.1415926535/N); real[i] = 1000*cos(i*2*3.1415926535/N);
real_org[i] = 1000*cos(i*2*3.1415926535/N); real_org[i] = real[i];
imag[i] = 0; imag[i] = 0;
imag_org[i] = 0; imag_org[i] = 0;
} }
@ -37,33 +53,39 @@ int main()
//FFT //FFT
fix_fft(real, imag, M, 0); fix_fft(real, imag, M, 0);
fix_fft(real_org, imag_org, M, 0); fix_fft_org(real_org, imag_org, M, 0);
printf("\nFFT\n"); printf("\nFFT\n");
for (i=0; i<N; i++) show_result(real, real_org, imag, imag_org, N);
{
printf("%d: %d, %d", i, real[i], imag[i]);
if (real[i] != real_org[i] || imag[i] != imag_org[i]) {
printf(" expected (%d, %d)", real_org[i], imag_org[i]);
}
printf("\n");
}
//IFFT //IFFT
fix_fft(real, imag, M, 1); fix_fft(real, imag, M, 1);
fix_fft(real_org, imag_org, M, 1); fix_fft_org(real_org, imag_org, M, 1);
printf("\nIFFT\n"); printf("\nIFFT\n");
for (i=0; i<N; i++) show_result(real, real_org, imag, imag_org, N);
for(i=0; i<N; i++)
{ {
printf("%d: %d, %d", i, real[i], imag[i]); real[i] = 1000*(cos(i*2*3.1415926535/N) + sin(i*2*3.1415926535/N));
if (real[i] != real_org[i] || imag[i] != imag_org[i]) { real_org[i] = real[i];
printf(" expected (%d, %d)", real_org[i], imag_org[i]); imag[i] = 0;
} imag_org[i] = 0;
printf("\n");
} }
//FFT
fix_fft(real, imag, M, 0);
fix_fft_org(real_org, imag_org, M, 0);
printf("\nFFT2\n");
show_result(real, real_org, imag, imag_org, N);
//IFFT
fix_fft(real, imag, M, 1);
fix_fft_org(real_org, imag_org, M, 1);
printf("\nIFFT2\n");
show_result(real, real_org, imag, imag_org, N);
return 0; return 0;
} }