1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#include <iostream>
#include <fstream>
#include <conio.h>
#include <vector>
#include <string>
#include <cmath>
#include <ctype.h>
#include <math.h>
using namespace std;
int J=6,s;
string nm="db10";
std:: vector<double> sig;
std:: vector<double> vsag;
std:: vector<double> dwt_output, flag;
std:: vector<int> length;
std:: vector<double> output;
double q[1200],q1[1200];
char inp[200000]="H:\\GUI\\simulation\\C-CODE\\vsss\\signal.txt";//voltage
char inp1[200000]="H:\\GUI\\simulation\\C-CODE\\vsss\\vsag.txt";//voltage sag //cin >> inp;
void dwt_sym(<vector>double ,int,string ,<vector>double ,<vector> double & ,<vector>int &);
inline double round(double x)
{
return (floor(x+0.5));
}
using namespace std;
int main()
{
;
ifstream sig_inp(inp); if ( !sig_inp.good()){ //
cout << "The File doesn?t exist"<< endl; }
while (!sig_inp.eof()) {
double temp1;
sig_inp >> temp1;
sig.push_back(temp1); }
sig.pop_back();
vector<double> original;
original = sig;
ifstream vsag_inp1(inp1);
//cout << "The File doesn?t exist"<< endl; }
while (!vsag_inp1.eof()) {
double temp;
vsag_inp1 >> temp;
vsag.push_back(temp); }
vsag.pop_back();
vector<double> original1;
original1 = vsag;
//cout << "Please Enter the Number of DWT Stages J :" << endl;
// perform J-Level DWT
dwt_sym(vsag, J, nm, dwt_output,flag,length);
//dwtout << dwt_output[i] << endl; }
//Perform J-Level IDWT
idwt_sym(dwt_output, flag,nm,output,length);
s=original.size();
for (unsigned int i = 0; i < s; i++){
q[i]=original[i]- output[i];}
//sig2 << output[i] << endl;
//diff <<original[i]- output[i] << endl; }
double q2[1200],qs[1200];
for (unsigned int i = 0; i < s; i++){
qs[i]=original[i]- output[i];
}
for (unsigned int i = 0; i < s;i++){
q1[i]=abs(q[i]);
q2[i]=round(q1[i]);
}
int w;
w=255;
int j=1;
int t1;
while (j<w) {
if ((q2[j]==0) && (q2[j+1]>1))
{
t1=j;
break; }
j++;
}
int start_time;
start_time=j+1;
int t2;
while (j<w)
{
if ((q2[j]>0) && (q2[j+1]==0) && (q2[j+1]==0) && (q2[j+2]==0))
{
t2=j;
break;
}
j++;
}
int end_time;
end_time=j+1;
int p;
double max,q3[1200]; //p=start_time;
for (int i=0;i<s;i++)
{
q3[i]=original1[i];
}
max=original[0];
for (p=start_time;p<end_time;p++)
{
if (q3[p]>max)
max=q3[p];
}
return 0;
}
void dwt_sym(vector<double> &signal, int J,string nm, vector<double> &dwt_output,
vector<double> &flag, vector<int> &length){
unsigned int temp_len = signal.size();
if ( (temp_len % 2) != 0) {
double temp =signal[temp_len - 1];
signal.push_back(temp);
flag.push_back(1);
temp_len++;
} else {
flag.push_back(0);
}
length.push_back(temp_len);
flag.push_back(double(J));
// flag[2] contains symmetric extension length
vector<double> original_copy, appx_sig, det_sig;
original_copy = signal;
// Storing Filter Values for GnuPlot
vector<double> lp1,hp1,lp2,hp2;
filtcoef(nm,lp1,hp1,lp2,hp2);
for (int iter = 0; iter < J; iter++) {
dwt1_sym(nm,signal, appx_sig, det_sig);
dwt_output.insert(dwt_output.begin(),det_sig.begin(),det_sig.end());
int l_temp = det_sig.size();
length.insert(length.begin(),l_temp);
if (iter == J-1 ) {
dwt_output.insert(dwt_output.begin(),appx_sig.begin(),appx_sig.end());
int l_temp = appx_sig.size();
length.insert(length.begin(),l_temp);
}
signal.clear();
signal = appx_sig;
appx_sig.clear();
det_sig.clear();
}
signal = original_copy;
return 0;
}
|