Mercurial > hg > qm-dsp
comparison ext/kissfft/test/testcpp.cc @ 184:76ec2365b250
Bring in kissfft into this repo (formerly a subrepo, but the remote is not responding)
author | Chris Cannam |
---|---|
date | Tue, 21 Jul 2015 07:34:15 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
183:7ab3539e92e3 | 184:76ec2365b250 |
---|---|
1 #include "kissfft.hh" | |
2 #include <iostream> | |
3 #include <cstdlib> | |
4 #include <typeinfo> | |
5 | |
6 #include <sys/time.h> | |
7 static inline | |
8 double curtime(void) | |
9 { | |
10 struct timeval tv; | |
11 gettimeofday(&tv, NULL); | |
12 return (double)tv.tv_sec + (double)tv.tv_usec*.000001; | |
13 } | |
14 | |
15 using namespace std; | |
16 | |
17 template <class T> | |
18 void dotest(int nfft) | |
19 { | |
20 typedef kissfft<T> FFT; | |
21 typedef std::complex<T> cpx_type; | |
22 | |
23 cout << "type:" << typeid(T).name() << " nfft:" << nfft; | |
24 | |
25 FFT fft(nfft,false); | |
26 | |
27 vector<cpx_type> inbuf(nfft); | |
28 vector<cpx_type> outbuf(nfft); | |
29 for (int k=0;k<nfft;++k) | |
30 inbuf[k]= cpx_type( | |
31 (T)(rand()/(double)RAND_MAX - .5), | |
32 (T)(rand()/(double)RAND_MAX - .5) ); | |
33 fft.transform( &inbuf[0] , &outbuf[0] ); | |
34 | |
35 long double totalpower=0; | |
36 long double difpower=0; | |
37 for (int k0=0;k0<nfft;++k0) { | |
38 complex<long double> acc = 0; | |
39 long double phinc = 2*k0* M_PIl / nfft; | |
40 for (int k1=0;k1<nfft;++k1) { | |
41 complex<long double> x(inbuf[k1].real(),inbuf[k1].imag()); | |
42 acc += x * exp( complex<long double>(0,-k1*phinc) ); | |
43 } | |
44 totalpower += norm(acc); | |
45 complex<long double> x(outbuf[k0].real(),outbuf[k0].imag()); | |
46 complex<long double> dif = acc - x; | |
47 difpower += norm(dif); | |
48 } | |
49 cout << " RMSE:" << sqrt(difpower/totalpower) << "\t"; | |
50 | |
51 double t0 = curtime(); | |
52 int nits=20e6/nfft; | |
53 for (int k=0;k<nits;++k) { | |
54 fft.transform( &inbuf[0] , &outbuf[0] ); | |
55 } | |
56 double t1 = curtime(); | |
57 cout << " MSPS:" << ( (nits*nfft)*1e-6/ (t1-t0) ) << endl; | |
58 } | |
59 | |
60 int main(int argc,char ** argv) | |
61 { | |
62 if (argc>1) { | |
63 for (int k=1;k<argc;++k) { | |
64 int nfft = atoi(argv[k]); | |
65 dotest<float>(nfft); dotest<double>(nfft); dotest<long double>(nfft); | |
66 } | |
67 }else{ | |
68 dotest<float>(32); dotest<double>(32); dotest<long double>(32); | |
69 dotest<float>(1024); dotest<double>(1024); dotest<long double>(1024); | |
70 dotest<float>(840); dotest<double>(840); dotest<long double>(840); | |
71 } | |
72 return 0; | |
73 } |