forked from Mic92/fft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
113 lines (87 loc) · 2.72 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//main.c
#include "dit.h"
#include "dit-org.h"
#include "dif.h"
#include "dif-org.h"
#include <stdio.h>
#include <math.h>
//defined by Compile Target
//#define M 3
//number of points
#define N (1<<M)
//#define DEBUG
fixed real[N], imag[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++)
{
#ifdef DEBUG
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");
#else
if (real[i] != real_org[i] || imag[i] != imag_org[i])
printf("got (%d, %d), expected (%d, %d)\n", real[i], imag[i], real_org[i], imag_org[i]);
#endif
}
}
int main()
{
int i;
printf("DIT:\n\n");
for(i=0; i<N; i++)
{
real[i] = 1000*cos(i*2*3.1415926535/N);
real_org[i] = real[i];
imag[i] = 0;
imag_org[i] = 0;
}
int scale, scale_org;
//FFT
scale = fix_dit_fft(real, imag, M, 0);
scale_org = fix_dit_fft_org(real_org, imag_org, M, 0);
printf("\nFFT\n");
show_result(real, real_org, imag, imag_org, N);
if (scale != scale_org) {
printf("got scale: %d, expected: %d\n", scale, scale_org);
}
//IFFT
scale = fix_dit_fft(real, imag, M, 1);
scale_org = fix_dit_fft_org(real_org, imag_org, M, 1);
printf("\nIFFT\n");
show_result(real, real_org, imag, imag_org, N);
if (scale != scale_org) {
printf("got scale: %d, expected: %d\n", scale, scale_org);
}
// -----------------------------------------------------------------
printf("\n\n---------------------------------------------------------------\nDIF:\n\n");
for(i=0; i<N; i++)
{
real[i] = 1000*cos(i*2*3.1415926535/N);
real_org[i] = real[i];
imag[i] = 0;
imag_org[i] = 0;
}
//FFT
scale = fix_dif_fft(real, imag, M, 0);
scale_org = fix_dif_fft_org(real_org, imag_org, M, 0);
printf("\nFFT\n");
show_result(real, real_org, imag, imag_org, N);
if (scale != scale_org) {
printf("got scale: %d, expected: %d\n", scale, scale_org);
}
//IFFT
scale = fix_dif_fft(real, imag, M, 1);
scale_org = fix_dif_fft_org(real_org, imag_org, M, 1);
printf("\nIFFT\n");
show_result(real, real_org, imag, imag_org, N);
if (scale != scale_org) {
printf("got scale: %d, expected: %d\n", scale, scale_org);
}
printf("done\n");
return 0;
}