Main Page | Class Hierarchy | Class List | File List | Class Members

filter.h

00001 /* ======== IGeoS ===== Distribition full ===== IGeoS =========
00002 **                                                                         
00003 ** filter.h     : Created by 'AMSS-developer' on Fri Jan 12 19:49:03 2018
00004 **                                                                         
00005 ** Product      : IGeoS - Integrated Geoscience Software
00006 **                                                                         
00007 ** Description  : System for seismic, well log, and potential-field data analysis
00008 **                                                                         
00009 ** =================== Limited License: ===================================
00010 ** 
00011 ** This software is provided free under the following terms and conditions:
00012 ** 
00013 ** 1. Permission to use, copy, and modify this software 
00014 ** for non-commercial purposes without fee is hereby granted, provided  
00015 ** that this copyright notice, the warranty disclaimer, and this
00016 ** permission notice appear in all copies.
00017 ** 
00018 ** 2. Distribution of this software or any part of it "bundled" in with
00019 ** any product is considered to be a 'commercial purpose'.
00020 ** 
00021 ** 3. Any new or adapted code developed to operate as a part of this
00022 ** software shall be contributed to the authors and distributed under
00023 ** the same license.
00024 ** 
00025 ** ================== Warranty Disclaimer: ================================
00026 ** 
00027 ** This software is provided "as is", with no support and without
00028 ** obligation on the part of the author to assist in its use, correction,
00029 ** modification, or enhancement. No guarantees or warranties,
00030 ** either express or implied, and regarding the accuracy, safety, or
00031 ** fitness for any particular purpose are provided by any contributor
00032 ** to this software package.
00033 ** 
00034 ** ======== IGeoS ===== Distribition full ===== IGeoS ========= */
00035 
00036 #ifndef MOD_FILTER
00037 #define MOD_FILTER
00038 
00039 #include "../store/store.h"     /* typedef of STORE */
00040 #include "../wllog/wllog.h"
00041 #include "sia_fft.h"
00042 
00043 /*--------- frequency bands -------------*/
00044 
00045 #define POLYGON         1       /* all low-pass, band-pass, high-pass,
00046                                                         and notch filters */
00047 #define PREDEFINED      2       /* filter retrieved from elsewhere */
00048 #define BAND_SLOPE      3       /* band slope filter */
00049 #define GAUSSIAN        4       /* gaussian-shaped */
00050 #define SP_BALANCE      5       /* spectral balancing */
00051 #define BUTTERWORTH     6       // Butterworth
00052 #define F_WAVELET       7       // standard wavelet
00053 #define RESPONSE        8       // response correction
00054 
00055 /*--- other lists ----------------*/
00056 
00057 #define RAMP            9
00058 
00059 /*---- types of polygon filters -------*/
00060 
00061 #define GENERAL         200
00062 #define BAND_PASS       201
00063 #define BAND_CUT        202
00064 #define LOW_PASS        203
00065 #define HIGH_PASS       204
00066 #define NOTCH           205
00067 
00070 struct Filter_Shape
00071 {
00072   Filter_Shape() {}
00073 
00074   Filter_Shape(const Filter_Shape &r)
00075         : frequency(r.frequency),amplitude(r.amplitude) {}
00076 
00077   Filter_Shape &operator=(const Filter_Shape &r) 
00078         { frequency=r.frequency; amplitude=r.amplitude; return *this; }
00079 
00080   HEADER_PARAM  frequency, amplitude;
00081 };
00082 
00083 struct FILTER_SHAPES : public ARRAY<Filter_Shape> 
00084 {
00085   FILTER_SHAPES() : ARRAY<Filter_Shape>() {}
00086   
00087   void read_preset_band ( int n, float *amps ); 
00090 
00091   void show() const;    
00092 };
00093 
00094 class FILTER;
00095 
00096 struct FILTER_FFT : public SIA_FFT
00097 {
00098   FILTER_FFT() : SIA_FFT(),_cfilter(NULL),alloc_freq(0) {}
00099   FILTER_FFT( TRACE *t, double pad = 0.25 );
00101 
00102   ~FILTER_FFT() { free(); }
00103 
00104   void alloc( int num_samples, double pad=0.25 ) 
00105         { num_points(num_samples,pad); 
00106           realloc(num_freq()); 
00107         }       
00108 
00109 
00110   void filter ( DATA_SAMPLE *data, int num_data_samples, boolean real_filter ) 
00111                                         { filter(data,num_data_samples,_cfilter,real_filter); }
00114 
00115   void filter ( DATA_SAMPLE *data, int num_data_samples, COMPLEX *filter, boolean real_filter );
00118 
00119   void time_shift ( double dt );        
00121 
00122   COMPLEX *cfilter() const { return _cfilter; } 
00123 
00124   COMPLEX cfilter( double freq ) const;         
00128 
00129   void clear_cfilter() { memset(_cfilter,0,num_freq()*sizeof(COMPLEX)); }
00131 
00132   void inverse_waterlevel ( double wlevel, double cutoff_freq_times_dt );
00137 
00138 private:
00139 
00140   COMPLEX *_cfilter;    
00141   int alloc_freq;       
00142 
00143   void free() { if ( _cfilter ) delete[] _cfilter; _cfilter = NULL; }
00144   void realloc( int nfreq );
00145 };
00146 
00149 struct Filter : public SIA_List, WLLOG_PROC
00150 {
00151     Filter ( Filter *pred=NULL, int _type=0, boolean _zero_phase=FALSE );
00152     ~Filter();
00153 
00154     int type;   
00155 
00156     /*----- flags to generate filter for each trace ---------------*/
00157 
00158     boolean     individual_gate,        
00159                 individual_filter;      
00160 
00161     HEADER_PARAM        time_start, time_end,   
00162                         f_base,                 
00163                         f_scalar;               
00164 
00165     double              df;                     
00166 
00167     boolean read_time_gate ();  
00168 
00169     virtual void show() const;  
00170 
00171     virtual void plotmtv_filter( FILE *f ) const;       
00172 
00173     virtual void proc ( FILTER *FIL, TRACE *t );                                
00174     virtual void proc ( FILTER *FIL, DATA_SAMPLE *d, int num_samples );         
00175 
00176     virtual boolean build ( FILTER *FIL, TRACE *t );    
00177 
00178     virtual boolean build ( FILTER *F, byte *header, 
00179                         int samples_per_trace, double sample_interval )
00180                         { return FAIL; }
00182 
00183     /*------- work arrays and parameters --------------------------*/
00184 
00185     FILTER_FFT  fft;            
00186 
00187     boolean     zero_phase;     
00188     int         start,          
00189                 nt,             
00190                 start_freq, end_freq;   
00191 
00192     COMPLEX     *filter;        
00193 };
00194 
00195 #include "filter_polygon.h"
00196 #include "filter_bslope.h"
00197 #include "filter_spbal.h"
00198 #include "filter_bworth.h"
00199 #include "filter_wavelet.h"
00200 #include "filter_response.h"
00201 #include "filter_defined.h"
00202 
00205 struct FILTER_TRANGE : public SIA_List
00206 {
00207   FILTER_TRANGE(FILTER_TRANGE *pred=NULL)
00208         : SIA_List(pred),filter(NULL)
00209         { ramp_start.set(REAL,-1.0);ramp_end.set(REAL,-1.0); }
00210 
00211   FILTER_TRANGE( double f_locut, double f_lopass, 
00212                         double f_hipass, double f_hicut, 
00213                         boolean bandpass=TRUE,
00214                         FILTER_TRANGE *pred=NULL );
00218 
00219   FILTER_TRANGE( double f_locut, double f_lopass, boolean high=TRUE,
00220                                 FILTER_TRANGE *pred=NULL );
00224                 
00225   FILTER_TRANGE( const ARRAY<POINT> &shape, FILTER_TRANGE *pred=NULL );
00228                 
00229   FILTER_TRANGE( Filter *f );   
00230 
00231   ~FILTER_TRANGE();
00232 
00233   Filter *filter;       
00234 
00235   HEADER_PARAM  ramp_start, ramp_end;
00236 
00237   Filter *add_filter( Filter *f ) 
00238                 { if (filter) return (Filter*)filter->add_last(f); return filter = f; }
00240 
00241   /*---- read parameter lists ---------*/
00242 
00243   void  read_ramp (),
00244         read_band ( int filter_type ),
00245         read_preset_band ( Filter_Shape *s, int n, float *amps ),
00246         read_sp_balance ( int filter_type ),
00247         read_polygon ( int filter_type, int rep ),
00248         read_predefined ( int filter_type ),
00249         read_butterworth ( int filter_type ),
00250         read_wavelet ( int filter_type ),
00251         read_bslope ( int filter_type ),
00252         read_response ( int filter_type );
00253 
00254   void proc ( FILTER *FIL, TRACE *t, int num_filter  ); 
00255 
00256 
00257   void proc ( FILTER *FIL, DATA_SAMPLE *d, int num_samples );           
00259 
00260   void show() const;    
00261 
00262   void plotmtv_filter( FILE *f ) const;         
00263 
00264 private:
00265 
00266   boolean remove_filter() 
00267         { 
00268           if ( filter )
00269             if ( Filter *f = ((Filter*)(filter->last())) )
00270             {
00271               f->_remove();
00272 
00273               if ( filter == f )
00274                 filter = NULL;
00275 
00276               delete f;
00277               return OK;
00278             }
00279 
00280           return FAIL;
00281         }
00283 };
00284 
00287 struct FILTER : public SIA_MODULE
00288 {
00289   FILTER();     
00290 
00291   FILTER( double f_locut, double f_lopass, double f_hipass, double f_hicut, 
00292                                                 boolean bandpass=TRUE );
00296 
00297   FILTER( double f_locut, double f_lopass, boolean highpass=TRUE );
00301         
00302   FILTER( const ARRAY<POINT> &shape);
00306 
00307   FILTER( FILTER_TRANGE *f );   
00308 
00309   ~FILTER();
00310 
00311   boolean time_domain;          
00312 
00313   boolean panels;               
00314 
00315   AHEADER panel_count;                  
00316   HEADER_PARAM panel_count_start;       
00317 
00318   FILTER_TRANGE *trange;        
00319 
00320   int   max_allocated;          
00321 
00322 
00323   void add_filter( FILTER_TRANGE *f ) { if ( trange ) trange->add_last(f); else trange=f; }
00325 
00326   void build( GATHER *g );      
00327 
00328 
00329   void build( TRACE *t );       
00330 
00331 
00332   void allocate ( int num_samples );
00334 
00335   boolean apply( TRACE *t, int count=-1 );
00340 
00341   boolean apply( DATA_SAMPLE *srray, int num_samples);  
00343 
00344   void show( const char *title = NULL ) const;  
00345 
00346   void plotmtv_filter( const char *file_name, const char *heading=NULL, 
00347                         const char *line_color="1", boolean append=FALSE ) const;       
00350 
00351   CHARSTR module_name( boolean active );        
00352   int edit();                                   
00353   boolean process();                            
00354   
00355   double sample_interval;       
00356 
00357   /*------- work areas ------------------------------------*/
00358 
00359   DATA_SAMPLE   *rt;                            
00360 
00361   COMPLEX       *ct() const { return (COMPLEX*)rt; }    
00363 
00364   int           *work_n;        
00365   double        *work;
00366 
00367 private:
00368 
00369   boolean remove_trange() 
00370         { 
00371           if ( trange )
00372             if ( FILTER_TRANGE *f = ((FILTER_TRANGE*)(trange->last())) )
00373             {
00374               f->_remove();
00375 
00376               if ( trange == f )
00377                 trange = NULL;
00378 
00379               delete f;
00380               return OK;
00381             }
00382 
00383           return FAIL;
00384         }
00386 };
00387 
00390 struct FILTER_EDIT : public UI_X_PROPERTY_EDIT
00391 {
00392   FILTER_EDIT( int _mode, double f_lo, double f_hi, 
00393                 const char *comment, const char *status );      
00394 
00395   SELECTION_EDIT mode;  
00396 
00397   REAL_EDIT     f_locut, f_hicut;       
00398 
00399   FILTER filter;        
00400 
00401   ARRAY<UI_X_PROPERTY_EDIT*> sub_items();
00403 
00404 //  boolean set_value( const char *new_value );
00405 //      ///< Set value of the sub-item #'ind' using the 'new_value' string.
00406 //      ///< This method should be called after a value has been edited
00407 //      ///< by the user and provided in 'new_value'.
00408 
00409   void curr_value();    
00410 };
00411 
00412 /*=============================================================================
00413         Applies predefined real or complex filter to a time
00414         sequence.
00415         nfft    is the number of samples in 'data'
00416         work    is complex work area for fft (may coincide with 'data')
00417 ==============================================================================*/
00418 
00419 void FILTER_apply ( DATA_SAMPLE *data, COMPLEX *filter, 
00420                         int nfft, boolean real_filter, COMPLEX *work );
00421 
00422 #endif

Generated on Wed Apr 1 21:42:25 2020 for Module FILTER by  doxygen 1.3.9.1