int main() { /******************************* [ signal ] ******************************/ Type a = 0; Type b = Ls-1; Vector<Type> t = linspace(a,b,Ls) / Type(Fs); Vector<Type> s = sin( Type(400*PI) * pow(t,Type(2.0)) ); /******************************** [ widow ] ******************************/ a = 0; b = Type(Lg-1); Type u = (Lg-1)/Type(2); Type r = Lg/Type(8); t = linspace(a,b,Lg); Vector<Type> g = gauss(t,u,r); g = g/norm(g); /********************************* [ WFT ] *******************************/ Type runtime = 0; Timing cnt; cout << "Taking windowed Fourier transform." << endl; cnt.start(); Matrix< complex<Type> > coefs = wft( s, g ); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (ms)" << endl << endl; /******************************** [ IWFT ] *******************************/ cout << "Taking inverse windowed Fourier transform." << endl; cnt.start(); Vector<Type> x = iwft( coefs, g ); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (ms)" << endl << endl; cout << "The relative error is : " << "norm(s-x) / norm(s) = " << norm(s-x)/norm(s) << endl << endl; return 0; }
int main() { /******************************* [ signal ] ******************************/ Vector<double> t = linspace( 0.0, (Ls-1)/fs, Ls ); Vector<double> st = sin( 200*PI*pow(t,2.0) ); st = st-mean(st); /******************************** [ CWT ] ********************************/ Matrix< complex<double> > coefs; CWT<double> wavelet("morlet"); wavelet.setScales( fs, fs/Ls, fs/2 ); Timing cnt; double runtime = 0.0; cout << "Taking continuous wavelet transform(Morlet)." << endl; cnt.start(); coefs = wavelet.cwtC(st); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (ms)" << endl << endl; /******************************** [ ICWT ] *******************************/ cout << "Taking inverse continuous wavelet transform." << endl; cnt.start(); Vector<double> xt = wavelet.icwtC(coefs); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (ms)" << endl << endl; cout << "The relative error is : " << endl; cout << "norm(st-xt) / norm(st) = " << norm(st-xt)/norm(st) << endl; cout << endl << endl; /******************************* [ signal ] ******************************/ Vector<float> tf = linspace( float(0.0), (Ls-1)/float(fs), Ls ); Vector<float> stf = sin( float(200*PI) * pow(tf,float(2.0) ) ); stf = stf-mean(stf); /******************************** [ CWT ] ********************************/ CWT<float> waveletf("mexiHat"); waveletf.setScales( float(fs), float(fs/Ls), float(fs/2), float(0.25) ); runtime = 0.0; cout << "Taking continuous wavelet transform(Mexican Hat)." << endl; cnt.start(); Matrix<float> coefsf = waveletf.cwtR(stf); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (ms)" << endl << endl; /******************************** [ ICWT ] *******************************/ cout << "Taking inverse continuous wavelet transform." << endl; cnt.start(); Vector<float> xtf = waveletf.icwtR(coefsf); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (ms)" << endl << endl; cout << "The relative error is : " << endl; cout << "norm(st-xt) / norm(st) = " << norm(stf-xtf)/norm(stf) << endl << endl; return 0; }