forked from Refridgerator/FHT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
46 lines (39 loc) · 1.07 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
#include <tchar.h>
#include <iostream>
#include "FHT.h"
void show(double* data, int size)
{
for(int i=0;i<size;i++)
std::cout << floor(data[i]*1000.+.5)/1000. << "\t";
std::cout << std::endl << std::endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
double fir[]= {11,22,33,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
double data[]={1,0,1,0,0,0,3,0, 0,0,0,0,0,0,0,0, 10,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
int size = 32;
FHT fht(size);
FHT fht2(size);
FHT fht3(size/2);
std::cout.precision(3);
// convolution
std::cout << "Convolution test using FHT." << std::endl << std::endl;
std::cout << "fir:" << std::endl;
show(fir, size);
std::cout << "source:" << std::endl;
show(data, size);
//
fht.transform(fir, false);
fht.transform(data);
fht.hartley_multiply(data, fir);
fht.back_transform(data);
//
std::cout << "result of convolution:" << std::endl;
show(data, size);
// spectrum
std::cout << "spectrum of fir:" << std::endl;
for(int i=0;i<=size/2;i++)
std::cout << std::abs(fht.get_frequency(fir, i)) << "\t";
std::cin.get();
return 0;
}