New and slightly modified Code. (Output dwtout.txt added)

This commit is contained in:
rafat.hsn@gmail.com 2011-08-20 09:45:14 +00:00
parent a657292131
commit a05f0ccd87

View File

@ -1,78 +1,83 @@
//============================================================================ //============================================================================
// Name : wavedemo1.cpp // Name : wavedemo1.cpp
// Author : Rafat Hussain // Author : Rafat Hussain
// Version : // Version :
// Copyright : // Copyright :
// Description : 1D DWT Demo // Description : 1D DWT Demo
//============================================================================ //============================================================================
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "wavelet2d.h" // Include wavelet2s.h if you are working with static library #include "wavelet2d.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include <cmath> #include <cmath>
using namespace std; using namespace std;
int main() { int main() {
cout << "********J- LEVEL DISCRETE WAVELET TRANSFORM IMPLEMENTATION*********" << endl; // prints cout << "********J- LEVEL DISCRETE WAVELET TRANSFORM IMPLEMENTATION*********" << endl; // prints
cout << "This program accepts signal from the user in a file format " << endl; cout << "This program accepts signal from the user in a file format " << endl;
cout << "and performs Discrete Wavelet Transform with specified " << endl; cout << "and performs Discrete Wavelet Transform with specified " << endl;
cout << "wavelet. " << endl; cout << "wavelet. " << endl;
cout << " " << endl; cout << " " << endl;
cout << " The Following Wavelets are in the Database: " << endl; cout << " The Following Wavelets are in the Database: " << endl;
cout << " haar, db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, " << endl; cout << " haar, db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, " << endl;
cout << " db11, db12, db13, db14, db15. " << 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 << " 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 << " bior3.1, bior3.3, bior3.5, bior3.7, bior3.9, bior4.4," << endl;
cout << " bior5.5, bior6.8." << endl; cout << " bior5.5, bior6.8." << endl;
cout << " coif1, coif2, coif3, coif4, coif5." << endl; cout << " coif1, coif2, coif3, coif4, coif5." << endl;
cout << "Please Enter the Wavelet Name at the Prompt( No quotes) :" << endl; cout << "Please Enter the Wavelet Name at the Prompt( No quotes) :" << endl;
string nm; // nm will store the name of Wavelet Family string nm; // nm will store the name of Wavelet Family
cin >> nm; cin >> nm;
cout << "Enter the name of signal file at the Prompt eg., signal.txt :" << endl; cout << "Enter the name of signal file at the Prompt eg., signal.txt :" << endl;
char inp[50]; char inp[50];
cin >> inp; cin >> inp;
vector<double> sig; vector<double> sig;
ifstream sig_inp(inp); ifstream sig_inp(inp);
if ( !sig_inp.good()){ if ( !sig_inp.good()){
cout << "The File doesn't exist"<< endl; cout << "The File doesn't exist"<< endl;
} }
while (sig_inp) { while (sig_inp) {
double temp; double temp;
sig_inp >> temp; sig_inp >> temp;
sig.push_back(temp); sig.push_back(temp);
} }
sig.pop_back(); sig.pop_back();
vector<double> original; vector<double> original;
original = sig; original = sig;
cout << "Please Enter the Number of DWT Stages J :" << endl; cout << "Please Enter the Number of DWT Stages J :" << endl;
int J; int J;
cin >> J ; cin >> J ;
vector<double> dwt_output, flag; vector<double> dwt_output, flag;
// perform J-Level DWT // perform J-Level DWT
vector<int> length; vector<int> length;
dwt_sym(sig, J, nm, dwt_output,flag,length); dwt_sym(sig, J, nm, dwt_output,flag,length);
ofstream dwtout("dwtout.txt");
for (unsigned int i = 0; i < dwt_output.size(); i++){
//Perform J-Level IDWT dwtout << dwt_output[i] << endl;
vector<double> output;
idwt_sym(dwt_output, flag,nm,output,length); }
ofstream sig1("recon.txt");
ofstream diff("diff.txt"); //Perform J-Level IDWT
vector<double> output;
cout <<" Recon signal size" << output.size() << endl; idwt_sym(dwt_output, flag,nm,output,length);
for (unsigned int i = 0; i < output.size(); i++){
sig1 << output[i] << endl; ofstream sig1("recon.txt");
diff << output[i] - original[i] << endl; ofstream diff("diff.txt");
} cout <<" Recon signal size" << output.size() << endl;
//gnudwtplot(J); for (unsigned int i = 0; i < output.size(); i++){
return 0; sig1 << output[i] << endl;
} diff << output[i] - original[i] << endl;
}
//gnudwtplot(J);
return 0;
}