int main() { wave_object obj; wt_object wt; double *inp,*out,*diff; int N, i,J; FILE *ifp; double temp[1200]; char *name = "db4"; obj = wave_init(name);// Initialize the wavelet ifp = fopen(FILE_SIGNAL, "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = 256; inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } J = 3; wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option setWTConv(wt, "direct"); dwt(wt, inp);// Perform DWT //DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients for (i = 0; i < wt->outlength; ++i) { // printf("%g ",wt->output[i]); } idwt(wt, out);// Perform IDWT (if needed) // Test Reconstruction for (i = 0; i < wt->siglength; ++i) { diff[i] = out[i] - inp[i]; } printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value. wt_summary(wt);// Prints the full summary. wave_free(obj); wt_free(wt); free(inp); free(out); free(diff); return 0; }
void ReconstructionTest() { wave_object obj; wt_object wt; double *inp,*out; int N, i,J; double epsilon = 1e-15; char *type = (char*) "dwt"; N = 79926; //N = 256; inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = (rand() / (double)(RAND_MAX)); } std::vector<std::string > waveletNames; for (unsigned int j = 0; j < 36; j++) { waveletNames.push_back(std::string("db") + patch::to_string(j + 1)); } for (unsigned int j = 0; j < 17; j++) { waveletNames.push_back(std::string("coif") + patch::to_string(j + 1)); } for (unsigned int j = 1; j < 20; j++) { waveletNames.push_back(std::string("sym") + patch::to_string(j + 1)); } waveletNames.push_back("bior1.1"); waveletNames.push_back("bior1.3"); waveletNames.push_back("bior1.5"); waveletNames.push_back("bior2.2"); waveletNames.push_back("bior2.4"); waveletNames.push_back("bior2.6"); waveletNames.push_back("bior2.8"); waveletNames.push_back("bior3.1"); waveletNames.push_back("bior3.3"); waveletNames.push_back("bior3.5"); waveletNames.push_back("bior3.7"); waveletNames.push_back("bior3.9"); waveletNames.push_back("bior4.4"); waveletNames.push_back("bior5.5"); waveletNames.push_back("bior6.8"); waveletNames.push_back("rbior1.1"); waveletNames.push_back("rbior1.3"); waveletNames.push_back("rbior1.5"); waveletNames.push_back("rbior2.2"); waveletNames.push_back("rbior2.4"); waveletNames.push_back("rbior2.6"); waveletNames.push_back("rbior2.8"); waveletNames.push_back("rbior3.1"); waveletNames.push_back("rbior3.3"); waveletNames.push_back("rbior3.5"); waveletNames.push_back("rbior3.7"); waveletNames.push_back("rbior3.9"); waveletNames.push_back("rbior4.4"); waveletNames.push_back("rbior5.5"); waveletNames.push_back("rbior6.8"); for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++) { for (unsigned int sym_per = 0; sym_per < 2; sym_per++) { for (unsigned int j = 0; j < waveletNames.size(); j++) { char * name = new char[waveletNames[j].size() + 1]; memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1); obj = wave_init(name);// Initialize the wavelet for (J = 1; J < 3; J++) { //J = 3; wt = wt_init(obj,(char*) "dwt", N, J);// Initialize the wavelet transform object if (sym_per == 0) setDWTExtension(wt, (char*) "sym");// Options are "per" and "sym". Symmetric is the default option else setDWTExtension(wt, (char*) "per"); if (direct_fft == 0) setWTConv(wt, (char*) "direct"); else setWTConv(wt, (char*) "fft"); dwt(wt, inp);// Perform DWT idwt(wt, out);// Perform IDWT (if needed) // Test Reconstruction if (direct_fft == 0) epsilon = 1e-8; else epsilon = 1e-10; //BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value. //printf("%g ",RMS_Error(out, inp, wt->siglength)); if (RMS_Error(out, inp, wt->siglength) > epsilon) { printf("\n ERROR : DWT Reconstruction Unit Test Failed. Exiting. \n"); exit(-1); } wt_free(wt); } wave_free(obj); delete[] name; } } } free(out); free(inp); }