lib/App/SeismicUnixGui/sunix/filter/subfilt.pm untested

filter: Statementstmt 0.0% 0 / 154 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 25 Podpod 0.0% 0 / 21 totaltotal 0.0% 0 / 234 CC 18 SCAR 16.6
CC
18
Cov
0%
apasshi
6.0
apasslo
6.0
astophi
6.0
CRAP 5.2
1 package App::SeismicUnixGui::sunix::filter::subfilt;
2  
3 =head2 SYNOPSIS
4  
5 PERL PROGRAM NAME:
6  
7 AUTHOR: Juan Lorenzo (Perl module only)
8  
9 DATE:
10  
11 DESCRIPTION:
12  
13 Version:
14  
15 =head2 USE
16  
17 =head3 NOTES
18  
19 =head4 Examples
20  
21 =head2 SYNOPSIS
22  
23 =head3 SEISMIC UNIX NOTES
24 SUBFILT - apply Butterworth bandpass filter
25  
26  
27  
28 subfilt <stdin >stdout [optional parameters]
29  
30  
31  
32 Required parameters:
33  
34 if dt is not set in header, then dt is mandatory
35  
36  
37  
38 Optional parameters: (nyquist calculated internally)
39  
40 zerophase=1 =0 for minimum phase filter
41  
42 locut=1 =0 for no low cut filter
43  
44 hicut=1 =0 for no high cut filter
45  
46 fstoplo=0.10*(nyq) freq(Hz) in low cut stop band
47  
48 astoplo=0.05 upper bound on amp at fstoplo
49  
50 fpasslo=0.15*(nyq) freq(Hz) in low cut pass band
51  
52 apasslo=0.95 lower bound on amp at fpasslo
53  
54 fpasshi=0.40*(nyq) freq(Hz) in high cut pass band
55  
56 apasshi=0.95 lower bound on amp at fpasshi
57  
58 fstophi=0.55*(nyq) freq(Hz) in high cut stop band
59  
60 astophi=0.05 upper bound on amp at fstophi
61  
62 verbose=0 =1 for filter design info
63  
64 dt = (from header) time sampling interval (sec)
65  
66  
67  
68 ... or set filter by defining poles and 3db cutoff frequencies
69  
70 npoleselo=calculated number of poles of the lo pass band
71  
72 npolesehi=calculated number of poles of the lo pass band
73  
74 f3dblo=calculated frequency of 3db cutoff frequency
75  
76 f3dbhi=calculated frequency of 3db cutoff frequency
77  
78  
79  
80 Notes:
81  
82 Butterworth filters were originally of interest because they
83  
84 can be implemented in hardware form through the combination of
85  
86 inductors, capacitors, and an amplifier. Such a filter can be
87  
88 constructed in such a way as to have very small oscillations
89  
90 in the flat portion of the bandpass---a desireable attribute.
91  
92 Because the filters are composed of LC circuits, the impulse
93  
94 response is an ordinary differential equation, which translates
95  
96 into a polynomial in the transform domain. The filter is expressed
97  
98 as the division by this polynomial. Hence the poles of the filter
99  
100 are of interest.
101  
102  
103  
104 The user may define low pass, high pass, and band pass filters
105  
106 that are either minimum phase or are zero phase. The default
107  
108 is to let the program calculate the optimal number of poles in
109  
110 low and high cut bands.
111  
112  
113  
114 Alternately the user may manually define the filter by the 3db
115  
116 frequency and by the number of poles in the low and or high
117  
118 cut region.
119  
120  
121  
122 The advantage of using the alternate method is that the user
123  
124 can control the smoothness of the filter. Greater smoothness
125  
126 through a larger pole number results in a more bell shaped
127  
128 amplitude spectrum.
129  
130  
131  
132 For simple zero phase filtering with sin squared tapering use
133  
134 "sufilter".
135  
136  
137  
138 Credits:
139  
140 CWP: Dave Hale c. 1993 for bf.c subs and test drivers
141  
142 CWP: Jack K. Cohen for su wrapper c. 1993
143  
144 SEAM Project: Bruce Verwest 2009 added explicit pole option
145  
146 in a program called "subfiltpole"
147  
148 CWP: John Stockwell (2012) combined Bruce Verwests changes
149  
150 into the original subfilt.
151  
152  
153  
154 Caveat: zerophase will not do good if trace has a spike near
155  
156 the end. One could make a try at getting the "effective"
157  
158 length of the causal filter, but padding the traces seems
159  
160 painful in an already expensive algorithm.
161  
162  
163  
164  
165  
166 Theory:
167  
168 The
169  
170  
171  
172 Trace header fields accessed: ns, dt, trid
173  
174  
175  
176 =head2 User's notes (Juan Lorenzo)
177 untested
178  
179 =cut
180  
181  
182 =head2 CHANGES and their DATES
183  
184 =cut
185  
186 use Moose;
187 our $VERSION = '0.0.1';
188  
189  
190 =head2 Import packages
191  
192 =cut
193  
194 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
195  
196 use App::SeismicUnixGui::misc::SeismicUnix qw($go $in $off $on $out $ps $to $suffix_ascii $suffix_bin $suffix_ps $suffix_segy $suffix_su);
197 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
198  
199  
200 =head2 instantiation of packages
201  
202 =cut
203  
204 my $get = L_SU_global_constants->new();
205 my $Project = Project_config->new();
206 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
207 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
208 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
209  
210 my $PS_SEISMIC = $Project->PS_SEISMIC();
211  
212 my $var = $get->var();
213 my $on = $var->{_on};
214 my $off = $var->{_off};
215 my $true = $var->{_true};
216 my $false = $var->{_false};
217 my $empty_string = $var->{_empty_string};
218  
219 =head2 Encapsulated
220 hash of private variables
221  
222 =cut
223  
224 my $subfilt = {
225 _apasshi => '',
226 _apasslo => '',
227 _astophi => '',
228 _astoplo => '',
229 _dt => '',
230 _f3dbhi => '',
231 _f3dblo => '',
232 _fpasshi => '',
233 _fpasslo => '',
234 _fstophi => '',
235 _fstoplo => '',
236 _hicut => '',
237 _locut => '',
238 _npolesehi => '',
239 _npoleselo => '',
240 _verbose => '',
241 _zerophase => '',
242 _Step => '',
243 _note => '',
244  
245 };
246  
247 =head2 sub Step
248  
249 collects switches and assembles bash instructions
250 by adding the program name
251  
252 =cut
253  
254 sub Step {
255  
256 $subfilt->{_Step} = 'subfilt'.$subfilt->{_Step};
257 return ( $subfilt->{_Step} );
258  
259 }
260  
261  
262 =head2 sub note
263  
264 collects switches and assembles bash instructions
265 by adding the program name
266  
267 =cut
268  
269 sub note {
270  
271 $subfilt->{_note} = 'subfilt'.$subfilt->{_note};
272 return ( $subfilt->{_note} );
273  
274 }
275  
276  
277  
278 =head2 sub clear
279  
280 =cut
281  
282 sub clear {
283  
284 $subfilt->{_apasshi} = '';
285 $subfilt->{_apasslo} = '';
286 $subfilt->{_astophi} = '';
287 $subfilt->{_astoplo} = '';
288 $subfilt->{_dt} = '';
289 $subfilt->{_f3dbhi} = '';
290 $subfilt->{_f3dblo} = '';
291 $subfilt->{_fpasshi} = '';
292 $subfilt->{_fpasslo} = '';
293 $subfilt->{_fstophi} = '';
294 $subfilt->{_fstoplo} = '';
295 $subfilt->{_hicut} = '';
296 $subfilt->{_locut} = '';
297 $subfilt->{_npolesehi} = '';
298 $subfilt->{_npoleselo} = '';
299 $subfilt->{_verbose} = '';
300 $subfilt->{_zerophase} = '';
301 $subfilt->{_Step} = '';
302 $subfilt->{_note} = '';
303 }
304  
305  
306 =head2 sub apasshi
307  
308  
309 =cut
310  
311 sub apasshi {
312  
313 my ( $self,$apasshi ) = @_;
314 if ( $apasshi ne $empty_string ) {
315  
316 $subfilt->{_apasshi} = $apasshi;
317 $subfilt->{_note} = $subfilt->{_note}.' apasshi='.$subfilt->{_apasshi};
318 $subfilt->{_Step} = $subfilt->{_Step}.' apasshi='.$subfilt->{_apasshi};
319  
320 } else {
321 print("subfilt, apasshi, missing apasshi,\n");
322 }
323 }
324  
325  
326 =head2 sub apasslo
327  
328  
329 =cut
330  
331 sub apasslo {
332  
333 my ( $self,$apasslo ) = @_;
334 if ( $apasslo ne $empty_string ) {
335  
336 $subfilt->{_apasslo} = $apasslo;
337 $subfilt->{_note} = $subfilt->{_note}.' apasslo='.$subfilt->{_apasslo};
338 $subfilt->{_Step} = $subfilt->{_Step}.' apasslo='.$subfilt->{_apasslo};
339  
340 } else {
341 print("subfilt, apasslo, missing apasslo,\n");
342 }
343 }
344  
345  
346 =head2 sub astophi
347  
348  
349 =cut
350  
351 sub astophi {
352  
353 my ( $self,$astophi ) = @_;
354 if ( $astophi ne $empty_string ) {
355  
356 $subfilt->{_astophi} = $astophi;
357 $subfilt->{_note} = $subfilt->{_note}.' astophi='.$subfilt->{_astophi};
358 $subfilt->{_Step} = $subfilt->{_Step}.' astophi='.$subfilt->{_astophi};
359  
360 } else {
361 print("subfilt, astophi, missing astophi,\n");
362 }
363 }
364  
365  
366 =head2 sub astoplo
367  
368  
369 =cut
370  
371 sub astoplo {
372  
373 my ( $self,$astoplo ) = @_;
374 if ( $astoplo ne $empty_string ) {
375  
376 $subfilt->{_astoplo} = $astoplo;
377 $subfilt->{_note} = $subfilt->{_note}.' astoplo='.$subfilt->{_astoplo};
378 $subfilt->{_Step} = $subfilt->{_Step}.' astoplo='.$subfilt->{_astoplo};
379  
380 } else {
381 print("subfilt, astoplo, missing astoplo,\n");
382 }
383 }
384  
385  
386 =head2 sub dt
387  
388  
389 =cut
390  
391 sub dt {
392  
393 my ( $self,$dt ) = @_;
394 if ( $dt ne $empty_string ) {
395  
396 $subfilt->{_dt} = $dt;
397 $subfilt->{_note} = $subfilt->{_note}.' dt='.$subfilt->{_dt};
398 $subfilt->{_Step} = $subfilt->{_Step}.' dt='.$subfilt->{_dt};
399  
400 } else {
401 print("subfilt, dt, missing dt,\n");
402 }
403 }
404  
405  
406 =head2 sub f3dbhi
407  
408  
409 =cut
410  
411 sub f3dbhi {
412  
413 my ( $self,$f3dbhi ) = @_;
414 if ( $f3dbhi ne $empty_string ) {
415  
416 $subfilt->{_f3dbhi} = $f3dbhi;
417 $subfilt->{_note} = $subfilt->{_note}.' f3dbhi='.$subfilt->{_f3dbhi};
418 $subfilt->{_Step} = $subfilt->{_Step}.' f3dbhi='.$subfilt->{_f3dbhi};
419  
420 } else {
421 print("subfilt, f3dbhi, missing f3dbhi,\n");
422 }
423 }
424  
425  
426 =head2 sub f3dblo
427  
428  
429 =cut
430  
431 sub f3dblo {
432  
433 my ( $self,$f3dblo ) = @_;
434 if ( $f3dblo ne $empty_string ) {
435  
436 $subfilt->{_f3dblo} = $f3dblo;
437 $subfilt->{_note} = $subfilt->{_note}.' f3dblo='.$subfilt->{_f3dblo};
438 $subfilt->{_Step} = $subfilt->{_Step}.' f3dblo='.$subfilt->{_f3dblo};
439  
440 } else {
441 print("subfilt, f3dblo, missing f3dblo,\n");
442 }
443 }
444  
445  
446 =head2 sub fpasshi
447  
448  
449 =cut
450  
451 sub fpasshi {
452  
453 my ( $self,$fpasshi ) = @_;
454 if ( $fpasshi ne $empty_string ) {
455  
456 $subfilt->{_fpasshi} = $fpasshi;
457 $subfilt->{_note} = $subfilt->{_note}.' fpasshi='.$subfilt->{_fpasshi};
458 $subfilt->{_Step} = $subfilt->{_Step}.' fpasshi='.$subfilt->{_fpasshi};
459  
460 } else {
461 print("subfilt, fpasshi, missing fpasshi,\n");
462 }
463 }
464  
465  
466 =head2 sub fpasslo
467  
468  
469 =cut
470  
471 sub fpasslo {
472  
473 my ( $self,$fpasslo ) = @_;
474 if ( $fpasslo ne $empty_string ) {
475  
476 $subfilt->{_fpasslo} = $fpasslo;
477 $subfilt->{_note} = $subfilt->{_note}.' fpasslo='.$subfilt->{_fpasslo};
478 $subfilt->{_Step} = $subfilt->{_Step}.' fpasslo='.$subfilt->{_fpasslo};
479  
480 } else {
481 print("subfilt, fpasslo, missing fpasslo,\n");
482 }
483 }
484  
485  
486 =head2 sub fstophi
487  
488  
489 =cut
490  
491 sub fstophi {
492  
493 my ( $self,$fstophi ) = @_;
494 if ( $fstophi ne $empty_string ) {
495  
496 $subfilt->{_fstophi} = $fstophi;
497 $subfilt->{_note} = $subfilt->{_note}.' fstophi='.$subfilt->{_fstophi};
498 $subfilt->{_Step} = $subfilt->{_Step}.' fstophi='.$subfilt->{_fstophi};
499  
500 } else {
501 print("subfilt, fstophi, missing fstophi,\n");
502 }
503 }
504  
505  
506 =head2 sub fstoplo
507  
508  
509 =cut
510  
511 sub fstoplo {
512  
513 my ( $self,$fstoplo ) = @_;
514 if ( $fstoplo ne $empty_string ) {
515  
516 $subfilt->{_fstoplo} = $fstoplo;
517 $subfilt->{_note} = $subfilt->{_note}.' fstoplo='.$subfilt->{_fstoplo};
518 $subfilt->{_Step} = $subfilt->{_Step}.' fstoplo='.$subfilt->{_fstoplo};
519  
520 } else {
521 print("subfilt, fstoplo, missing fstoplo,\n");
522 }
523 }
524  
525  
526 =head2 sub hicut
527  
528  
529 =cut
530  
531 sub hicut {
532  
533 my ( $self,$hicut ) = @_;
534 if ( $hicut ne $empty_string ) {
535  
536 $subfilt->{_hicut} = $hicut;
537 $subfilt->{_note} = $subfilt->{_note}.' hicut='.$subfilt->{_hicut};
538 $subfilt->{_Step} = $subfilt->{_Step}.' hicut='.$subfilt->{_hicut};
539  
540 } else {
541 print("subfilt, hicut, missing hicut,\n");
542 }
543 }
544  
545  
546 =head2 sub locut
547  
548  
549 =cut
550  
551 sub locut {
552  
553 my ( $self,$locut ) = @_;
554 if ( $locut ne $empty_string ) {
555  
556 $subfilt->{_locut} = $locut;
557 $subfilt->{_note} = $subfilt->{_note}.' locut='.$subfilt->{_locut};
558 $subfilt->{_Step} = $subfilt->{_Step}.' locut='.$subfilt->{_locut};
559  
560 } else {
561 print("subfilt, locut, missing locut,\n");
562 }
563 }
564  
565  
566 =head2 sub npolesehi
567  
568  
569 =cut
570  
571 sub npolesehi {
572  
573 my ( $self,$npolesehi ) = @_;
574 if ( $npolesehi ne $empty_string ) {
575  
576 $subfilt->{_npolesehi} = $npolesehi;
577 $subfilt->{_note} = $subfilt->{_note}.' npolesehi='.$subfilt->{_npolesehi};
578 $subfilt->{_Step} = $subfilt->{_Step}.' npolesehi='.$subfilt->{_npolesehi};
579  
580 } else {
581 print("subfilt, npolesehi, missing npolesehi,\n");
582 }
583 }
584  
585  
586 =head2 sub npoleselo
587  
588  
589 =cut
590  
591 sub npoleselo {
592  
593 my ( $self,$npoleselo ) = @_;
594 if ( $npoleselo ne $empty_string ) {
595  
596 $subfilt->{_npoleselo} = $npoleselo;
597 $subfilt->{_note} = $subfilt->{_note}.' npoleselo='.$subfilt->{_npoleselo};
598 $subfilt->{_Step} = $subfilt->{_Step}.' npoleselo='.$subfilt->{_npoleselo};
599  
600 } else {
601 print("subfilt, npoleselo, missing npoleselo,\n");
602 }
603 }
604  
605  
606 =head2 sub verbose
607  
608  
609 =cut
610  
611 sub verbose {
612  
613 my ( $self,$verbose ) = @_;
614 if ( $verbose ne $empty_string ) {
615  
616 $subfilt->{_verbose} = $verbose;
617 $subfilt->{_note} = $subfilt->{_note}.' verbose='.$subfilt->{_verbose};
618 $subfilt->{_Step} = $subfilt->{_Step}.' verbose='.$subfilt->{_verbose};
619  
620 } else {
621 print("subfilt, verbose, missing verbose,\n");
622 }
623 }
624  
625  
626 =head2 sub zerophase
627  
628  
629 =cut
630  
631 sub zerophase {
632  
633 my ( $self,$zerophase ) = @_;
634 if ( $zerophase ne $empty_string ) {
635  
636 $subfilt->{_zerophase} = $zerophase;
637 $subfilt->{_note} = $subfilt->{_note}.' zerophase='.$subfilt->{_zerophase};
638 $subfilt->{_Step} = $subfilt->{_Step}.' zerophase='.$subfilt->{_zerophase};
639  
640 } else {
641 print("subfilt, zerophase, missing zerophase,\n");
642 }
643 }
644  
645  
646 =head2 sub get_max_index
647  
648 max index = number of input variables -1
649
650 =cut
651
652 sub get_max_index {
653 my ($self) = @_;
654 my $max_index = 16;
655  
656 return($max_index);
657 }
658
659
660 1;