OpendTect  6.6
ceemdalgo.h
Go to the documentation of this file.
1 #pragma once
2 /*+
3  * (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
4  * AUTHOR : Paul
5  * DATE : April 2013
6 -*/
7 
8 #include "ceemdattribmod.h"
9 #include "commondefs.h"
10 #include "gendefs.h"
11 #include "arrayndimpl.h"
12 #include "mathfunc.h"
13 #include "manobjectset.h"
14 #include "interpol1d.h"
15 
16 #define mDecompModeEMD 0
17 #define mDecompModeEEMD 1
18 #define mDecompModeCEEMD 2
19 
20 #define mDecompOutputFreq 0
21 #define mDecompOutputPeakFreq 1
22 #define mDecompOutputPeakAmp 2
23 #define mDecompOutputIMF 3
24 
25 
26 mExpClass(CEEMDAttrib) IMFComponent
27 {
28 public:
29  IMFComponent( int nrsamples )
30  : values_( new float[nrsamples] )
31  , size_( nrsamples )
32  { OD::memValueSet(values_,0.f,nrsamples); }
33 
34  IMFComponent( const IMFComponent& comp )
35  : values_( new float[comp.size_] )
36  , size_( comp.size_ )
37  , name_( comp.name_ )
38  , nrzeros_( comp.nrzeros_ )
39  {
40  for ( int idx=0; idx<size_; idx++ )
41  values_[idx] = comp.values_[idx];
42  }
43 
44  ~IMFComponent() { delete [] values_; }
46  int nrzeros_;
47  int size_;
48  float* values_;
49 
50 };
51 
53 {
54 public:
55 
60  :PointBasedMathFunction( t, e ){};
61 
62  void replace(int idx, float x, float y)
63  {
64  x_[idx]=x;
65  y_[idx]=y;
66  }
67  float myGetValue(float x) const
68  { return itype_ == Snap ? snapVal(x) : myInterpVal(x); }
69 
70  float myInterpVal( float x ) const
71  {
72  const int sz = x_.size();
73  if ( sz < 1 ) return mUdf(float);
74 
75  if ( x < x_[0] || x > x_[sz-1] )
76  return myOutsideVal(x);
77  else if ( sz < 2 )
78  return y_[0];
79 
80  const int i0 = baseIdx( x );
81  const float v0 = y_[i0];
82  if ( i0 == sz-1 )
83  return v0;
84 
85  const float x0 = x_[i0];
86  const int i1 = i0 + 1;
87  const float x1 = x_[i1];
88  const float v1 = y_[i1];
89  const float dx = x1 - x0;
90  if ( dx == 0 ) return v0;
91 
92  const float relx = (x - x0) / dx;
93  if ( mIsUdf(v0) || mIsUdf(v1) )
94  return relx < 0.5 ? v0 : v1;
95 
96  // OK - we have 2 nearest points and they:
97  // - are not undef
98  // - don't coincide
99 
100  if ( itype_ == Linear )
101  return v1 * relx + v0 * (1-relx);
102 
103  const int im1 = i0 > 0 ? i0 - 1 : i0;
104  const float xm1 = im1 == i0 ? x0 - dx : x_[im1];
105  const float vm1 = mIsUdf(y_[im1]) ? v0 : y_[im1];
106 
107  const int i2 = i1 < sz-1 ? i1 + 1 : i1;
108  const float x2 = i2 == i1 ? x1 + dx : x_[i2];
109  const float v2 = mIsUdf(y_[i2]) ? v1 : y_[i2];
110 
111  if ( mIsEqual(xm1,x0,1e-6) || mIsEqual(x0,x1,1e-6)
112  || mIsEqual(x1,x2,1e-6) )
113  return mUdf(float);
114 
115  return Interpolate::poly1D( xm1, vm1, x0, v0, x1, v1,
116  x2, v2, x );
117  }
118 
119  float myOutsideVal( float x ) const
120  {
121  if ( extrapol_==None ) return mUdf(float);
122 
123  const int sz = x_.size();
124 
125  if ( extrapol_==EndVal || sz<2 )
126  {
127  return x-x_[0] < x_[sz-1]-x ? y_[0] : y_[sz-1];
128  }
129 
130  if ( x<x_[0] )
131  {
132  const float gradient =
133  mIsZero(x_[1]-x_[0], 1e-3 ) ?
134  mUdf(float) : (y_[1]-y_[0])/(x_[1]-x_[0]);
135  return y_[0]+(x-x_[0])*gradient;
136  }
137 
138  const float gradient =
139  mIsZero(x_[sz-1]-x_[sz-2], 1e-3 ) ?
140  mUdf(float) : (y_[sz-1]-y_[sz-2])/(x_[sz-1]-x_[sz-2]);
141  return y_[sz-1] + (x-x_[sz-1])*gradient;
142  }
143 };
144 
146 {
147 public:
148  OrgTraceMinusAverage( int nrsamples )
149  : values_( new float[nrsamples] )
150  , size_( nrsamples )
151  { OD::memValueSet(values_,0.f,nrsamples); }
152  ~OrgTraceMinusAverage() { delete [] values_; }
155  float stdev_;
156  int size_;
157  float* values_;
158 };
159 
160 mExpClass(CEEMDAttrib) Setup
161  {
162  public:
163  Setup();
164 
165  mDefSetupMemb(int, method); // 0=EMD, 1=EEMD, 2=CEEMD
166  // 0=Freq, 1=Peak Freq, 2= Peak Amp, 3=IMF
167  mDefSetupMemb(int, attriboutput);
168  // Number of realizations for EEMD and CEEMD
169  mDefSetupMemb(int, maxnoiseloop);
170  // Maximum number of intrinsic Mode Functions
171  mDefSetupMemb(int, maxnrimf);
172  // Maximum number of sifting iterations
173  mDefSetupMemb(int, maxsift);
174  // stop sifting if st.dev res.-imf < value
175  mDefSetupMemb(float, stopsift);
176  // stop decomp. when st.dev imf < value
177  mDefSetupMemb(float, stopimf);
178  // noise percentage for EEMD and CEEMD
179  mDefSetupMemb(float, noisepercentage);
180  // boundary extension symmetric or periodic
181  mDefSetupMemb(bool, symmetricboundary);
182  // use synthetic trace in ceemdtestprogram.h
183  mDefSetupMemb(bool, usetestdata);
184  // output frequency.
185  mDefSetupMemb(bool, outputfreq);
186  // step output frequency.
187  mDefSetupMemb(bool, stepoutfreq);
188  // output IMF component.
189  mDefSetupMemb(bool, outputcomp);
190  };
191 
192 mExpClass(CEEMDAttrib) DecompInput
193 {
194 public:
195  DecompInput( const Setup& setup, int nrsamples )
196  : values_( new float[nrsamples] )
197  , size_( nrsamples )
198  , setup_(setup)
199  , halflen_(30) // Hilbert Halflength
200  { OD::memValueSet(values_,0.f,nrsamples); }
201  ~DecompInput() { delete [] values_; }
202 
203  bool doDecompMethod(int nrsamples , float refstep,
204  Array2DImpl<float>* output, int outputattrib,
205  float startfreq, float endfreq, float stepoutfreq,
206  int startcomp, int endcomp);
207 
209  int size_;
210  int halflen_;
211  float* values_;
212  static const char* transMethodNamesStr(int);
213 
214 protected:
215  void computeStats(float&, float&) const;
216  void createNoise(float stdev) const;
217  void addDecompInputs(const DecompInput* arraytoadd) const;
218  void rescaleDecompInput(float scaler) const;
219  void subtractDecompInputs(const DecompInput*) const;
220  void replaceDecompInputs(const DecompInput*) const;
222  const ManagedObjectSet<IMFComponent>& components,
223  int comp) const;
225  int comp, int nrzeros) const;
227  ManagedObjectSet<IMFComponent>& components,
228  int comp ) const;
229  void findExtrema(int& nrmax, int& nrmin, int& nrzeros ,
230  bool symmetricboundary ,
231  MyPointBasedMathFunction& maxima ,
232  MyPointBasedMathFunction& minima) const;
233  void testFunction(int& nrmax, int& nrmin, int& nrzeros ,
234  MyPointBasedMathFunction& maxima ,
235  MyPointBasedMathFunction& minima) const;
236  void resetInput(const OrgTraceMinusAverage*) const;
238  int maxnrimf , float stdevinput) const;
241  & realizations,
242  ManagedObjectSet<IMFComponent>& stackedcomponents)
243  const;
246  & currentrealizations,
248  currentstackedcomponents,
249  int nrimf ) const;
250  bool dumpComponents(OrgTraceMinusAverage* orgminusaverage,
252  & realizations) const;
255  realizations ) const;
256  bool doHilbert(
258  & realcomponents,
259  ManagedObjectSet<IMFComponent>& imagcomponents) const;
262  & realcomponents,
263  const ManagedObjectSet<IMFComponent>& imagcomponents,
264  ManagedObjectSet<IMFComponent>& frequencycomponents,
265  const float refstep) const;
268  & realcomponents,
269  const ManagedObjectSet<IMFComponent>& imagcomponents,
271  frequencycomponents,
273  amplitudecomponents) const;
276  & realizations,
277  Array2DImpl<float>* output, int outputattrib,
278  float startfreq, float endfreq, float stepoutfreq,
279  int startcomp, int outputcomp, float average) const;
282  & realizations,
283  Array2DImpl<float>* output, float startfreq,
284  float endfreq, float stepoutfreq) const;
287  & realizations,
288  Array2DImpl<float>* output, float startfreq,
289  float endfreq, float stepoutfreq) const;
291  float* unsortedfrequencies,float* unsortedamplitudes,
292  MyPointBasedMathFunction& sortedampspectrum,
293  int size ) const;
294 
295 };
296 
Setup::mDefSetupMemb
mDefSetupMemb(bool, outputfreq)
interpol1d.h
Setup::mDefSetupMemb
mDefSetupMemb(bool, outputcomp)
Interpolate::poly1D
T poly1D(float x0, T v0, float x1, T v1, float x2, T v2, float x3, T v3, float x)
Definition: interpol1d.h:217
DecompInput::createNoise
void createNoise(float stdev) const
OD::memValueSet
void memValueSet(T *, T, int64_t, TaskRunner *taskrun=0)
Definition: odmemory.h:479
IMFComponent::IMFComponent
IMFComponent(const IMFComponent &comp)
Definition: ceemdalgo.h:34
MyPointBasedMathFunction::MyPointBasedMathFunction
MyPointBasedMathFunction(PointBasedMathFunction::InterpolType t=PointBasedMathFunction::Poly, PointBasedMathFunction::ExtrapolType e=PointBasedMathFunction::ExtraPolGradient)
Definition: ceemdalgo.h:56
DecompInput::calcFrequencies
bool calcFrequencies(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realcomponents, const ManagedObjectSet< IMFComponent > &imagcomponents, ManagedObjectSet< IMFComponent > &frequencycomponents, const float refstep) const
OrgTraceMinusAverage::~OrgTraceMinusAverage
~OrgTraceMinusAverage()
Definition: ceemdalgo.h:152
DecompInput::computeStats
void computeStats(float &, float &) const
OrgTraceMinusAverage::name_
BufferString name_
Definition: ceemdalgo.h:153
mIsEqual
#define mIsEqual(x, y, eps)
Definition: commondefs.h:67
Setup::mDefSetupMemb
mDefSetupMemb(bool, usetestdata)
commondefs.h
IMFComponent
Definition: ceemdalgo.h:27
mIsUdf
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:289
MyPointBasedMathFunction::myOutsideVal
float myOutsideVal(float x) const
Definition: ceemdalgo.h:119
DecompInput::calcAmplitudes
bool calcAmplitudes(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realcomponents, const ManagedObjectSet< IMFComponent > &imagcomponents, const ManagedObjectSet< IMFComponent > &frequencycomponents, ManagedObjectSet< IMFComponent > &amplitudecomponents) const
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
Setup::Setup
Setup()
Setup::mDefSetupMemb
mDefSetupMemb(float, noisepercentage)
DecompInput::subtractDecompInputs
void subtractDecompInputs(const DecompInput *) const
Setup::mDefSetupMemb
mDefSetupMemb(int, method)
DecompInput::doHilbert
bool doHilbert(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realcomponents, ManagedObjectSet< IMFComponent > &imagcomponents) const
IMFComponent::~IMFComponent
~IMFComponent()
Definition: ceemdalgo.h:44
Setup::mDefSetupMemb
mDefSetupMemb(bool, symmetricboundary)
DecompInput::setup_
Setup setup_
Definition: ceemdalgo.h:208
BendPointBasedMathFunction::ExtrapolType
ExtrapolType
Definition: mathfunc.h:155
DecompInput::dumpComponents
bool dumpComponents(OrgTraceMinusAverage *orgminusaverage, const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realizations) const
MyPointBasedMathFunction::myInterpVal
float myInterpVal(float x) const
Definition: ceemdalgo.h:70
IMFComponent::IMFComponent
IMFComponent(int nrsamples)
Definition: ceemdalgo.h:29
BendPointBasedMathFunction::ExtraPolGradient
@ ExtraPolGradient
Definition: mathfunc.h:155
OrgTraceMinusAverage::averageinput_
float averageinput_
Definition: ceemdalgo.h:154
IMFComponent::size_
int size_
Definition: ceemdalgo.h:47
BendPointBasedMathFunction::Poly
@ Poly
Definition: mathfunc.h:154
IMFComponent::name_
BufferString name_
Definition: ceemdalgo.h:45
arrayndimpl.h
DecompInput::size_
int size_
Definition: ceemdalgo.h:209
DecompInput::values_
float * values_
Definition: ceemdalgo.h:211
ManagedObjectSet
ObjectSet where the objects contained are owned by this set.
Definition: manobjectset.h:57
TraceData::size
int size(int icomp=0) const
Definition: tracedata.h:55
Setup::mDefSetupMemb
mDefSetupMemb(float, stopsift)
DecompInput::decompositionLoop
bool decompositionLoop(ManagedObjectSet< IMFComponent > &, int maxnrimf, float stdevinput) const
BendPointBasedMathFunction
MathFunction based on bend points.
Definition: mathfunc.h:151
Setup::mDefSetupMemb
mDefSetupMemb(float, stopimf)
DecompInput::sortSpectrum
bool sortSpectrum(float *unsortedfrequencies, float *unsortedamplitudes, MyPointBasedMathFunction &sortedampspectrum, int size) const
Setup::mDefSetupMemb
mDefSetupMemb(int, maxnoiseloop)
DecompInput::~DecompInput
~DecompInput()
Definition: ceemdalgo.h:201
BendPointBasedMathFunction::InterpolType
InterpolType
Definition: mathfunc.h:154
OrgTraceMinusAverage::OrgTraceMinusAverage
OrgTraceMinusAverage(int nrsamples)
Definition: ceemdalgo.h:148
DecompInput::halflen_
int halflen_
Definition: ceemdalgo.h:210
DecompInput::retrieveFromComponent
void retrieveFromComponent(const ManagedObjectSet< IMFComponent > &components, int comp) const
OrgTraceMinusAverage::stdev_
float stdev_
Definition: ceemdalgo.h:155
MyPointBasedMathFunction::myGetValue
float myGetValue(float x) const
Definition: ceemdalgo.h:67
DecompInput::resetInput
void resetInput(const OrgTraceMinusAverage *) const
Setup::mDefSetupMemb
mDefSetupMemb(int, maxnrimf)
DecompInput::replaceDecompInputs
void replaceDecompInputs(const DecompInput *) const
mIsZero
#define mIsZero(x, eps)
Definition: commondefs.h:66
Setup::mDefSetupMemb
mDefSetupMemb(bool, stepoutfreq)
Taper::Linear
@ Linear
Definition: simpnumer.h:189
Setup
Definition: ceemdalgo.h:161
DecompInput::rescaleDecompInput
void rescaleDecompInput(float scaler) const
gendefs.h
DecompInput::usePolynomial
bool usePolynomial(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realizations, Array2DImpl< float > *output, float startfreq, float endfreq, float stepoutfreq) const
OrgTraceMinusAverage::size_
int size_
Definition: ceemdalgo.h:156
IMFComponent::values_
float * values_
Definition: ceemdalgo.h:48
OrgTraceMinusAverage::values_
float * values_
Definition: ceemdalgo.h:157
DecompInput::addZeroComponents
void addZeroComponents(ManagedObjectSet< IMFComponent > &components, int comp) const
mathfunc.h
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
DecompInput
Definition: ceemdalgo.h:193
Network::None
@ None
Definition: networkcommon.h:33
DecompInput::readComponents
void readComponents(ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realizations) const
Array2DImpl< float >
DecompInput::outputAttribute
bool outputAttribute(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realizations, Array2DImpl< float > *output, int outputattrib, float startfreq, float endfreq, float stepoutfreq, int startcomp, int outputcomp, float average) const
DecompInput::doDecompMethod
bool doDecompMethod(int nrsamples, float refstep, Array2DImpl< float > *output, int outputattrib, float startfreq, float endfreq, float stepoutfreq, int startcomp, int endcomp)
MyPointBasedMathFunction::replace
void replace(int idx, float x, float y)
Definition: ceemdalgo.h:62
DecompInput::addToComponent
void addToComponent(ManagedObjectSet< IMFComponent > &, int comp, int nrzeros) const
DecompInput::findExtrema
void findExtrema(int &nrmax, int &nrmin, int &nrzeros, bool symmetricboundary, MyPointBasedMathFunction &maxima, MyPointBasedMathFunction &minima) const
mUdf
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:274
manobjectset.h
DecompInput::transMethodNamesStr
static const char * transMethodNamesStr(int)
DecompInput::stackEemdComponents
void stackEemdComponents(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realizations, ManagedObjectSet< IMFComponent > &stackedcomponents) const
DecompInput::stackCeemdComponents
void stackCeemdComponents(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &currentrealizations, ManagedObjectSet< IMFComponent > &currentstackedcomponents, int nrimf) const
IMFComponent::nrzeros_
int nrzeros_
Definition: ceemdalgo.h:46
Setup::mDefSetupMemb
mDefSetupMemb(int, maxsift)
DecompInput::DecompInput
DecompInput(const Setup &setup, int nrsamples)
Definition: ceemdalgo.h:195
DecompInput::useGridding
bool useGridding(const ManagedObjectSet< ManagedObjectSet< IMFComponent > > &realizations, Array2DImpl< float > *output, float startfreq, float endfreq, float stepoutfreq) const
MyPointBasedMathFunction
Definition: ceemdalgo.h:53
Setup::mDefSetupMemb
mDefSetupMemb(int, attriboutput)
OrgTraceMinusAverage
Definition: ceemdalgo.h:146
DecompInput::testFunction
void testFunction(int &nrmax, int &nrmin, int &nrzeros, MyPointBasedMathFunction &maxima, MyPointBasedMathFunction &minima) const
DecompInput::addDecompInputs
void addDecompInputs(const DecompInput *arraytoadd) const

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021