Logo coherent WaveBurst  
Library Reference Guide
Logo
Biorthogonal.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 // Wavelet Analysis Tool
20 //--------------------------------------------------------------------
21 // Implementation of
22 // Bi-othogonal wavelet transforms using lifting scheme
23 // References:
24 // A.Cohen, I.Daubechies, J.Feauveau Bases of compactly supported wavelets
25 // Comm. Pure. Appl. Math. 45, 485-560, 1992
26 // W. Sweldens - Building your own wavelets at home
27 //--------------------------------------------------------------------
28 //$Id: Biorthogonal.hh,v 0.2 2001/08/06 19:37:00 klimenko Exp $
29 
30 #define BIORTHOGONAL_CC
31 
32 #include "Biorthogonal.hh"
33 
34 //namespace datacondAPI {
35 //namespace wat {
36 
37 ClassImp(Biorthogonal<double>)
38 
39 // constructors
40 
41 template<class DataType_t> Biorthogonal<DataType_t>::
43 WaveDWT<DataType_t>(w)
44 {
45  setFilter();
46 }
47 
48 template<class DataType_t> Biorthogonal<DataType_t>::
50 WaveDWT<DataType_t>(w)
51 {
52  setFilter();
53 }
54 
55 template<class DataType_t> Biorthogonal<DataType_t>::
56 Biorthogonal(int m, int tree, enum BORDER border) :
57 WaveDWT<DataType_t>(m,m,tree,border)
58 {
59  setFilter();
60 }
61 
62 // destructor
63 template<class DataType_t>
65 {
66  if(PForward) delete [] PForward;
67  if(PInverse) delete [] PInverse;
68  if(UForward) delete [] UForward;
69  if(UInverse) delete [] UInverse;
70 }
71 
72 // clone
73 template<class DataType_t>
75 {
76  return new Biorthogonal<DataType_t>(*this);
77 }
78 
79 // set filter and wavelet type
80 template<class DataType_t>
82 {
83  int n = this->m_H;
84 
85  n = (n>>1)<<1;
86  if(n < 2) n=4;
87 // if(n > 30) n=30; // limit is due to the unrolled code length
88 
89  PForward=new double[n];
90  PInverse=new double[n];
91  UForward=new double[n];
92  UInverse=new double[n];
93 
94  for(int i=0; i<n; i++)
95  {
96  PForward[i] = Lagrange(n,i,0.);
97  UForward[i] = 0.5*PForward[i];
98  PInverse[i] = -PForward[i];
99  UInverse[i] = -UForward[i];
100 // printf("%8.3e ",PForward[i]);
101  }
102  this->m_H = n;
103  this->m_L = n;
104  this->m_WaveType = BIORTHOGONAL;
105 }
106 
107 // forward function does one step of forward transformation.
108 // <level> input parameter is the level to be transformed
109 // <layer> input parameter is the layer to be transformed.
110 template<class DataType_t>
111 void Biorthogonal<DataType_t>::forward(int level,int layer)
112 {
113  int i;
114  int step = 1<<level;
115  this->predict(level, layer, PForward);
116  this->update(level, layer, UForward);
117  const int nS = this->nWWS>>level; // number of samples in the layer
118  DataType_t *pData = this->pWWS+this->getOffset(level,layer); // pointer to the first sample in the layer
119  if(this->m_Heterodine){
120  for(i=1; i<nS; i+=4) {pData[i*step] *= -1;} // heterodine detailes coefficients
121  }
122 }
123 
124 // inverse function does one step of inverse transformation.
125 // <level> input parameter is the level to be reconstructed
126 // <layer> input parameter is the layer to be reconstructed.
127 template<class DataType_t>
128 void Biorthogonal<DataType_t>::inverse(int level,int layer)
129 {
130  int i;
131  int step = 1<<level;
132  const int nS = this->nWWS>>level; // number of samples in the layer
133  DataType_t *pData = this->pWWS+this->getOffset(level,layer); // pointer to the first sample in the layer
134 
135  if(this->m_Heterodine){
136  for(i=1; i<nS; i+=4) {pData[i*step] *= -1;} // heterodine detailes coefficients
137  }
138 
139  this->update(level, layer, UInverse);
140  this->predict(level, layer, PInverse);
141 }
142 
143 
144 // instantiations
145 
146 #define CLASS_INSTANTIATION(class_) template class Biorthogonal< class_ >;
147 
148 CLASS_INSTANTIATION(float)
149 CLASS_INSTANTIATION(double)
150 //CLASS_INSTANTIATION(std::complex<float>)
151 //CLASS_INSTANTIATION(std::complex<double>)
152 
153 #undef CLASS_INSTANTIATION
154 
155 //template Biorthogonal<float>::
156 //Biorthogonal(const Biorthogonal<float> &);
157 //template Biorthogonal<double>::
158 //Biorthogonal(const Biorthogonal<double> &);
159 
160 //} // end namespace wat
161 //} // end namespace datacondAPI
162 
163 
164 
165 
166 
167 
168 
169 
170 
TTree * tree
Definition: TimeSortTree.C:20
double * PInverse
Definition: Biorthogonal.hh:46
#define CLASS_INSTANTIATION(class_)
void setFilter()
Definition: Biorthogonal.cc:81
int n
Definition: cwb_net.C:28
BORDER
Definition: Wavelet.hh:36
int m
Definition: cwb_net.C:28
DataType_t * pWWS
Definition: WaveDWT.hh:141
i drho i
void inverse(int level, int layer)
double * PForward
Definition: Biorthogonal.hh:44
wavearray< double > w
Definition: Test1.C:27
int m_L
Definition: Wavelet.hh:124
void forward(int level, int layer)
double Lagrange(const int n, const int i, const double x)
Definition: watfun.hh:38
bool m_Heterodine
Definition: Wavelet.hh:126
virtual void update(int, int, const double *)
Definition: WaveDWT.cc:831
virtual Biorthogonal * Clone() const
return: Wavelet* - duplicate of *this, allocated on heap
Definition: Biorthogonal.cc:74
virtual void predict(int, int, const double *)
Definition: WaveDWT.cc:651
virtual ~Biorthogonal()
Definition: Biorthogonal.cc:64
unsigned long nWWS
pointer to wavelet work space
Definition: WaveDWT.hh:142
virtual int getOffset(int, int)
Definition: Wavelet.cc:69
Biorthogonal(const Wavelet &)
Definition: Biorthogonal.cc:42
enum WAVETYPE m_WaveType
Definition: Wavelet.hh:106
double * UInverse
Definition: Biorthogonal.hh:50
int m_H
Definition: Wavelet.hh:121
double * UForward
Definition: Biorthogonal.hh:48