From 37a0296f4bdf637e314a5fbff9e2ab9d4094cce5 Mon Sep 17 00:00:00 2001 From: "rafat.hsn@gmail.com" Date: Wed, 27 Apr 2011 00:35:46 +0000 Subject: [PATCH] 1D DWT Demo using symmetric extension dwt_sym and idwt_sym --- demo/wavedemo_sym1.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 demo/wavedemo_sym1.cpp diff --git a/demo/wavedemo_sym1.cpp b/demo/wavedemo_sym1.cpp new file mode 100644 index 0000000..0a4632d --- /dev/null +++ b/demo/wavedemo_sym1.cpp @@ -0,0 +1,83 @@ +//============================================================================ +// Name : wavedemo_sym1.cpp +// Author : Rafat Hussain +// Version : +// Copyright : +// Description : 1D DWT Demo using symmetric extension dwt_sym and idwt_sym +//============================================================================ + +#include +#include +#include "wavelet.h" +#include +#include +#include +using namespace std; + +int main() { + cout << "********J- LEVEL DISCRETE WAVELET TRANSFORM IMPLEMENTATION*********" << endl; // prints + cout << "This program accepts signal from the user in a file format " << endl; + cout << "and performs Discrete Wavelet Transform with specified " << endl; + cout << "wavelet. " << endl; + cout << " " << endl; + cout << " The Following Wavelets are in the Database: " << endl; + cout << " haar, db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, " << endl; + cout << " db11, db12, db13, db14, db15. " << endl; + cout << " bior1.1, bio1.3, bior1.5, bior2.2, bior2.4,bior2.6,bior2.8, " << endl; + cout << " bior3.1, bior3.3, bior3.5, bior3.7, bior3.9, bior4.4," << endl; + cout << " bior5.5, bior6.8." << endl; + cout << " coif1, coif2, coif3, coif4, coif5." << endl; + cout << "Please Enter the Wavelet Name at the Prompt( No quotes) :" << endl; + + string nm; // nm will store the name of Wavelet Family + cin >> nm; + cout << "Enter the name of signal file at the Prompt eg., signal.txt :" << endl; + char inp[50]; + cin >> inp; + vector sig; + ifstream sig_inp(inp); + if ( !sig_inp.good()){ + cout << "The File doesn't exist"<< endl; + exit(1); + } + while (sig_inp) { + double temp; + sig_inp >> temp; + sig.push_back(temp); + } + sig.pop_back(); + vector original; + original = sig; + cout << "Please Enter the Number of DWT Stages J :" << endl; + + int J; + cin >> J ; + + vector dwt_output, flag; + + // perform J-Level DWT using symmetric extension. This function accepts two more + //arguments vector length , a vector that stores lengths of approximation and details + // as the lengths will be different at each stage, and an integer value that corresponds + // to length of symmetric extension + + vector length; + int ext = 2; + dwt_sym(sig, J, nm, dwt_output,flag, length, ext ); + + + //Perform J-Level symmetric extension IDWT + vector output; + idwt_sym(dwt_output, flag,nm,output,length); + + ofstream sig1("recon.txt"); + ofstream diff("diff.txt"); + + cout <<" Recon signal size" << output.size() << endl; + for (unsigned int i = 0; i < output.size(); i++){ + sig1 << output[i] << endl; + diff << output[i] - original[i] << endl; + + } + gnudwtplot(J); + return 0; +}