-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp
99 lines (73 loc) · 1.75 KB
/
test.cpp
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
#include "./test/test.h"
#include "common.h"
#include<iostream>
using namespace std;
#define ffor(a) for(int i=0;i<a;i++)
void minit(void *a,void *b){
std::cout<<*(float*)a<<"\n"<<*(float*)b<<std::endl;
}
void mminit(void *a,void *b){
std::cout<<*(float*)b<<"\n"<<*(float*)a<<std::endl;
}
/**
test 2d fft
²âÊÔ¶þάfft
*/
void testfft2d(){
int w = 3;
int h = 3;
float arr[6][6] = { { 2, 4, 5, 4, 5, 6 }, { 3, 5, 6, 4, 5, 7 }, { 4, 7, 8, 4, 6, 8 }, { 5, 6, 7, 9, 7, 6 }, { 5, 2, 3, 5, 6, 8 }, { 6, 2, 4, 3, 5, 8 } };
Complexf* cm = (Complexf *)malloc(sizeof(Complexf)* w * h);
for (int i = 0; i<h; i++){
for (int j = 0; j<w; j++){
cm[i*w + j].setReal(arr[i][j]);
cm[i*w + j].setIm(0);
}
}
fft_2d(cm, w, h);
for (int i = 0; i<h; i++){
for (int j = 0; j<w; j++){
std::cout << cm[i*w + j].getReal() << "\t";//<<cm[i*w+j].getIm()<<"\t";
}
std::cout << "\n";
}
std::cout << "\n";
ifft_2d(cm, w, h);
for (int i = 0; i<h; i++){
for (int j = 0; j<w; j++){
//std::cout << cm[i*w + j].abs() << "\t";//<<cm[i*w+j].getIm()<<"\t";
std::cout << cm[i*w + j].getReal() << "\t";
}
std::cout << "\n";
}
}
/*
test*/
void test_dft(Complexf *cm, u_int N){
Complexf *wnk = new Complexf[N];
for (int i = 0; i<N; i++){
wnk[i].setReal(cos(2 * PI * i / N));
wnk[i].setIm(sin(-2 * PI * i / N));
}
u_int *nk = new u_int[N];
for (int i = 0; i<N; i++){
nk[i] = i;
}
Complexf *res = new Complexf[N];
dft(cm, res, wnk, N, nk);
for (int i = 0; i<N; i++){
std::cout << i << " ---- " << res[i].getReal() << "\t" << res[i].getIm() << std::endl;
}
}
int main(){
test_log2();
testPrime();
test_bitReverse();
test_CN_reverse();
test_fft2();
test_fft_CN();
test_fft2d_shift();
testfft2d();
test_normal_fft();
return 0;
}