├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── Stub.md ├── docs ├── .nojekyll ├── Stub.md ├── images │ ├── susdft_2.jpeg │ └── susdft_2.png ├── index.html ├── start.md ├── suctrcmedian.md ├── suisdct.md ├── suisdft.md ├── sulpasmooth.md ├── susdct.md ├── susdft.md ├── susdft_denoise.md ├── sutrcmedian.md └── suvpef.md ├── include ├── Makefile └── sux.h ├── lib ├── Makefile ├── cbsdft.c ├── ctrcbuf.c ├── otrcbuf.c ├── sdct.c └── sdft.c └── main ├── Makefile ├── suctrcmedian.c ├── suisdct.c ├── suisdft.c ├── sulpasmooth.c ├── susdct.c ├── susdft.c ├── susdft_denoise.c ├── sutrcmedian.c └── suvpef.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | 35 | INSTALL 36 | .directory 37 | test* 38 | programs.md 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, Wayne Mogg 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Master makefile for ./esu 2 | 3 | include $(CWPROOT)/src/Makefile.config 4 | 5 | INSTALL: 6 | cd include ; $(MAKE) 7 | cd lib ; $(MAKE) 8 | cd main ; $(MAKE) 9 | 10 | remake: 11 | cd include ; $(MAKE) remake 12 | cd lib ; $(MAKE) remake 13 | cd main ; $(MAKE) remake 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SeismicUnixExtra 2 | My addons to the [Seismic Unix](http://www.cwp.mines.edu/cwpcodes/) seismic processing package. 3 | 4 | Access the [documentation](https://waynegm.github.io/SeismicUnixExtra/) for more information. 5 | 6 | ## Installation 7 | * Install and build Seismic Unix if you haven't already done so in a folder with write access for the user building this software. 8 | * Make sure the CWPROOT environment variable is set 9 | * Download and extract the GitHub repository 10 | * Change to the directory where the SeismicUnixExtra files were extracted 11 | * Type "make" 12 | 13 | This should compile and install all programs into your seismic unix installation. 14 | 15 | ## Contributing 16 | * Fork it! 17 | * Create your feature branch: `git checkout -b my-new-feature` 18 | * Commit your changes: `git commit -am 'Add some feature'` 19 | * Push to the branch: `git push origin my-new-feature` 20 | * Submit a pull request 21 | 22 | ## License 23 | [BSD 3-clause "New" or "Revised" License](https://github.com/waynegm/SeismicUnixExtra/blob/master/LICENSE) 24 | 25 | ## Functionality 26 | 27 | | Program | Description | 28 | | ------- | -------------------------------------------| 29 | | [susdft](docs/susdft.md) | Time-frequency decomposition by the sliding discrete fourier transform | 30 | | [suisdft](docs/suisdft.md) | Inverse sliding discrete fourier tranform. | 31 | | [susdct](docs/susdct.md) | Time-frequency decomposition using the sliding discrete cosine transform | 32 | | [suisdct](docs/suisdct.md) | Inverse sliding discrete cosine tranform | 33 | | [sutrcmedian](docs/sutrcmedian.md) | Rolling median filter over a panel of seismic traces by an ordered trace buffer | 34 | | [suctrcmedian](docs/suctrcmedian.md) | Rolling median filter over a panel of seismic traces by a cyclic trace buffer | 35 | | [susdft_denoise](docs/susdft_denoise.md) | Time-frequency denoise over a panel of seismic traces using the sliding discrete fourier transform | 36 | | [sulpasmooth](docs/sulpasmooth.md) | Rolling LPA filter over a panel of seismic traces | 37 | | [suvpef](docs/suvpef.md) | Wiener predictive error filtering with spatially varying lag | 38 | -------------------------------------------------------------------------------- /Stub.md: -------------------------------------------------------------------------------- 1 | # SeismicUnixExtra 2 | My addons to the [Seismic Unix](http://www.cwp.mines.edu/cwpcodes/) seismic processing package. 3 | 4 | Access the [documentation](https://waynegm.github.io/SeismicUnixExtra/) for more information. 5 | 6 | ## Installation 7 | * Install and build Seismic Unix if you haven't already done so in a folder with write access for the user building this software. 8 | * Make sure the CWPROOT environment variable is set 9 | * Download and extract the GitHub repository 10 | * Change to the directory where the SeismicUnixExtra files were extracted 11 | * Type "make" 12 | 13 | This should compile and install all programs into your seismic unix installation. 14 | 15 | ## Contributing 16 | * Fork it! 17 | * Create your feature branch: `git checkout -b my-new-feature` 18 | * Commit your changes: `git commit -am 'Add some feature'` 19 | * Push to the branch: `git push origin my-new-feature` 20 | * Submit a pull request 21 | 22 | ## License 23 | [BSD 3-clause "New" or "Revised" License](https://github.com/waynegm/SeismicUnixExtra/blob/master/LICENSE) 24 | 25 | ## Functionality 26 | 27 | | Program | Description | 28 | | ------- | -------------------------------------------| 29 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waynegm/SeismicUnixExtra/1a9434a802f41a2bd919e8724fca86fb0868e918/docs/.nojekyll -------------------------------------------------------------------------------- /docs/Stub.md: -------------------------------------------------------------------------------- 1 | # SeismicUnixExtra 2 | My addons to the [Seismic Unix](http://www.cwp.mines.edu/cwpcodes/) seismic processing package. 3 | 4 | ## Installation 5 | * Install and build Seismic Unix if you haven't already done so in a folder with write access for the user building this software. 6 | * Make sure the CWPROOT environment variable is set 7 | * Download and extract the GitHub repository 8 | * Change to the directory where the SeismicUnixExtra files were extracted 9 | * Type "make" 10 | 11 | This should compile and install all programs into your seismic unix installation. 12 | 13 | ## Functionality 14 | 15 | | Program | Description | 16 | | ------- | -------------------------------------------| 17 | -------------------------------------------------------------------------------- /docs/images/susdft_2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waynegm/SeismicUnixExtra/1a9434a802f41a2bd919e8724fca86fb0868e918/docs/images/susdft_2.jpeg -------------------------------------------------------------------------------- /docs/images/susdft_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waynegm/SeismicUnixExtra/1a9434a802f41a2bd919e8724fca86fb0868e918/docs/images/susdft_2.png -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SeismicUnixExtra 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /docs/start.md: -------------------------------------------------------------------------------- 1 | # SeismicUnixExtra 2 | My addons to the [Seismic Unix](http://www.cwp.mines.edu/cwpcodes/) seismic processing package. 3 | 4 | ## Installation 5 | * Install and build Seismic Unix if you haven't already done so in a folder with write access for the user building this software. 6 | * Make sure the CWPROOT environment variable is set 7 | * Download and extract the GitHub repository 8 | * Change to the directory where the SeismicUnixExtra files were extracted 9 | * Type "make" 10 | 11 | This should compile and install all programs into your seismic unix installation. 12 | 13 | ## Functionality 14 | 15 | | Program | Description | 16 | | ------- | -------------------------------------------| 17 | | [susdft](susdft.md) | Time-frequency decomposition by the sliding discrete fourier transform | 18 | | [suisdft](suisdft.md) | Inverse sliding discrete fourier tranform. | 19 | | [susdct](susdct.md) | Time-frequency decomposition using the sliding discrete cosine transform | 20 | | [suisdct](suisdct.md) | Inverse sliding discrete cosine tranform | 21 | | [sutrcmedian](sutrcmedian.md) | Rolling median filter over a panel of seismic traces by an ordered trace buffer | 22 | | [suctrcmedian](suctrcmedian.md) | Rolling median filter over a panel of seismic traces by a cyclic trace buffer | 23 | | [susdft_denoise](susdft_denoise.md) | Time-frequency denoise over a panel of seismic traces using the sliding discrete fourier transform | 24 | | [sulpasmooth](sulpasmooth.md) | Rolling LPA filter over a panel of seismic traces | 25 | | [suvpef](suvpef.md) | Wiener predictive error filtering with spatially varying lag | 26 | -------------------------------------------------------------------------------- /docs/suctrcmedian.md: -------------------------------------------------------------------------------- 1 | # SUCTRCMEDIAN 2 | Rolling median filter over a panel of seismic traces by a cyclic trace buffer 3 | 4 | ## Usage 5 | suctrcmedian < stdin > stdout 6 | 7 | ### Optional Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | ntr= | number (odd) of traces in filter panel | 5 | 11 | | mode= | =0 output filtered trace, =1 output noise | 0 | 12 | | verbose= | =0 no advisory messages, =1 for messages | 0 | 13 | 14 | ## Notes 15 | This is primarily a demonstation and test platform for the cyclic trace buffer implementation. 16 | 17 | -------------------------------------------------------------------------------- /docs/suisdct.md: -------------------------------------------------------------------------------- 1 | # SUISDCT 2 | Inverse sliding discrete cosine tranform 3 | 4 | ## Usage 5 | suisdct < stdin > stdout 6 | 7 | ### Required Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | dt= | time sampling interval (sec) | trcheader | 11 | | nwin= | window size of original t-f transform | | 12 | 13 | ### Optional Parameters 14 | | Parameter | Description | Default | 15 | |:---------:| ----------------------------------------------- |:-------------:| 16 | | verbose | 0 - no advisory message, 1- for messages | | 17 | 18 | ## Notes 19 | This process inverts a time-frequency decomposition generated by the sliding 20 | discrete cosine transform (SUSDCT). 21 | 22 | ## Examples 23 | suvibro | susdct nwin=31 | suisdct nwin=31 | suximage 24 | 25 | -------------------------------------------------------------------------------- /docs/suisdft.md: -------------------------------------------------------------------------------- 1 | # SUISDFT 2 | Inverse sliding discrete fourier tranform. 3 | 4 | ## Usage 5 | suisdft < stdin > stdout 6 | 7 | ### Required Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | dt= | time sampling interval (sec) | trcheader | 11 | | nwin= | window size of original t-f transform | | 12 | 13 | ### Optional Parameters 14 | | Parameter | Description | Default | 15 | |:---------:| ----------------------------------------------- |:-------------:| 16 | | verbose | 0 - no advisory message, 1- for messages | | 17 | 18 | ## Notes 19 | This process inverts a time-frequency decomposition generated by the sliding 20 | discrete fourier transform (SUSDFT). 21 | 22 | ## Examples 23 | suvibro | susdft nwin=31 | suisdft nwin=31 | suximage 24 | 25 | -------------------------------------------------------------------------------- /docs/sulpasmooth.md: -------------------------------------------------------------------------------- 1 | # SULPASMOOTH 2 | Rolling LPA filter over a panel of seismic traces 3 | 4 | ## Usage 5 | sulpasmooth < stdin > sdout [optional parameters] 6 | 7 | ### Optional Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | mode= | =0 output filtered trace, =1 output noise | 0 | 11 | | verbose= | =0 no advisory messages, =1 for messages | 0 | 12 | 13 | -------------------------------------------------------------------------------- /docs/susdct.md: -------------------------------------------------------------------------------- 1 | # SUSDCT 2 | Time-frequency decomposition using the sliding discrete cosine transform 3 | 4 | ## Usage 5 | susdct < stdin > stdout 6 | 7 | ### Required Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | dt= | time sampling interval (sec) | trcheader | 11 | 12 | ### Optional Parameters 13 | | Parameter | Description | Default | 14 | |:---------:| ----------------------------------------------- |:-------------:| 15 | | nwin= | number (odd) of samples in SDFT window | 31 | 16 | | window= | none - no window applied to each data segment | none | 17 | | | hann - Hann window | | 18 | | | hamming - Hamming window | | 19 | | | blackman - Blackman window | | 20 | | verbose= | 0 - no advisory messages, 1 - for messages | 0 | 21 | 22 | ## Notes 23 | This process calculates a time-frequency decomposition of seismic data using 24 | the sliding discrete cosine transform. 25 | 26 | ## Examples 27 | suvibro | susdct | suximage 28 | 29 | -------------------------------------------------------------------------------- /docs/susdft.md: -------------------------------------------------------------------------------- 1 | # SUSDFT 2 | Time-frequency decomposition by the sliding discrete fourier transform 3 | 4 | ## Usage 5 | susdft < stdin > stdout 6 | 7 | ### Required Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | dt= | time sampling interval (sec) | trcheader | 11 | 12 | ### Optional Parameters 13 | | Parameter | Description | Default | 14 | |:---------:| ----------------------------------------------- |:-------------:| 15 | | nwin= | number (odd) of samples in SDFT window | 31 | 16 | | mode= | complex - output complex spectra | complex | 17 | | | amp - output spectral amplitude | | 18 | | | phase - output spectral phase | | 19 | | | real - output real part | | 20 | | | imag - output imaginary part | | 21 | | window= | none - no window applied to each data segment | none | 22 | | | hann - Hann window | | 23 | | | hamming - Hamming window | | 24 | | | blackman - Blackman window | | 25 | | verbose= | 0 - no advisory messages, 1 - for messages | 0 | 26 | 27 | ## Notes 28 | This process calculates a time-frequency decomposition of seismic data using 29 | the sliding discrete fourier transform. 30 | 31 | ## Examples: 32 | suvibro | susdft nwin=51 mode=amp window=hann | suximage 33 | 34 | ![susdft example](images/susdft_2.png) 35 | 36 | -------------------------------------------------------------------------------- /docs/susdft_denoise.md: -------------------------------------------------------------------------------- 1 | # SUSDFT_DENOISE 2 | Time-frequency denoise over a panel of seismic traces using the sliding discrete fourier transform 3 | 4 | ## Usage 5 | susdft_denoise < stdin > stdout 6 | 7 | ### Required Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | dt= | time sampling interval (sec) | trcheader | 11 | 12 | ### Optional Parameters 13 | | Parameter | Description | Default | 14 | |:---------:| ----------------------------------------------- |:-------------:| 15 | | ntr= | number (odd) of traces in analysis panel | 9 | 16 | | nwin= | number (odd) of samples in SDFT window | 31 | 17 | | window= | none - no window applied to each data segment | none | 18 | | | hann - Hann window | | 19 | | | hamming - Hamming window | | 20 | | | blackman - Blackman window | | 21 | | reject= | percentage of high trace amplitudes to reject | 10 | 22 | | type= | swmean - only replace rejected trace with mean of accepted | swmean | 23 | | | swmedian - only replace rejected trace with median of accepted | | 24 | | | median - output median of accepted traces | | 25 | | | mean - output mean of accepted traces | | 26 | | mode= | 0 - output filtered, 1 - output noise | 0 | 27 | | verbose= | 0 - no advisory messages, 1 - for messages | 0 | 28 | 29 | ## Notes 30 | This process implements the following algorithm: 31 | 32 | 1. Time-Frequency transform of the trace using the sliding DFT 33 | 2. For each time and frequency sample acrosss the panel of traces 34 | - Sort by amplitude and discard the top reject% of values 35 | - For type=mean or median output the mean or median respectively of the kept traces. 36 | - For type=swmean or swmedian output the mean or median respectively of the kept traces only if the current trace value was rejected, otherwise the original value is passed unchanged. 37 | 3. Inverse sliding DFT and output 38 | 39 | -------------------------------------------------------------------------------- /docs/sutrcmedian.md: -------------------------------------------------------------------------------- 1 | # SUTRCMEDIAN 2 | Rolling median filter over a panel of seismic traces by an ordered trace buffer 3 | 4 | ## Usage 5 | sutrcmedian < stdin > stdout 6 | ### Optional Parameters 7 | | Parameter | Description | Default | 8 | |:---------:| ----------------------------------------------- |:-------------:| 9 | | ntr= | number (odd) of traces in filter panel | 5 | 10 | | mode= | =0 output filtered trace, =1 output noise | 0 | 11 | | verbose= | =0 no advisory messages, =1 for messages | 0 | 12 | 13 | ## Notes 14 | This is primarily a demonstation and test platform for the ordered trace buffer implementation. 15 | 16 | -------------------------------------------------------------------------------- /docs/suvpef.md: -------------------------------------------------------------------------------- 1 | # SUVPEF 2 | Wiener predictive error filtering with spatially varying lag 3 | 4 | ## Usage 5 | suvpef < stdin > stdout [optional parameters] 6 | 7 | ### Required Parameters 8 | | Parameter | Description | Default | 9 | |:---------:| ----------------------------------------------- |:-------------:| 10 | | dt= | time sampling interval (sec) | trcheader | 11 | 12 | ### Optional Parameters 13 | | Parameter | Description | Default | 14 | |:---------:| ----------------------------------------------- |:-------------:| 15 | | key= | header word specifying lag locations | cdp | 16 | | xlag= | array of lag locations as given by key | | 17 | | lag= | array of prediction filter lags in seconds | dt | 18 | | len= | operator length in seconds | tr.ns*dt/20 | 19 | | pnoise= | relative additive noise level | 0.001 | 20 | | mincorr= | start of autocorrelation window in seconds | tmin | 21 | | maxcorr= | end of autocorrelation window in seconds | tmax | 22 | | verbose= | 0 - no advisory messages, 1 - for messages | 0 | 23 | 24 | Trace header fields accessed: ns, dt 25 | Trace header fields modified: none 26 | 27 | ## Notes 28 | - For fixed lag omit the key= and xlag= parameters and give a single lag= value. 29 | - For spatially variable lag specify key=, xlag= and lag= arrays. 30 | - Linear interpolation and constant extrapolation used to compute lag from the 31 | arrays. 32 | 33 | This is a simplified version of supef 34 | 35 | -------------------------------------------------------------------------------- /include/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ..SeismicUnixExtra/include 2 | # Just say "make" 3 | 4 | include $(CWPROOT)/src/Makefile.config 5 | 6 | INCLUDE = $I/sux.h 7 | 8 | INSTALL : $(INCLUDE) $I 9 | -rm -f INSTALL 10 | touch $@ 11 | 12 | $(INCLUDE): $(ITARGET) 13 | @-rm -f $@ 14 | @cp $? $@ 15 | @$(ICHMODLINE) 16 | @echo $(@F) installed in $I 17 | 18 | remake : 19 | @-rm -f $(INCLUDE) INSTALL 20 | @$(MAKE) INSTALL 21 | -------------------------------------------------------------------------------- /include/sux.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017.*/ 2 | /* All rights reserved. */ 3 | 4 | 5 | #ifndef SUX_H 6 | #define SUX_H 7 | 8 | #include "su.h" 9 | #include "segy.h" 10 | #include "header.h" 11 | 12 | typedef enum WinType { None, Hann, Hamming, Blackman } sux_Window; 13 | 14 | /* Sliding Discrete Fourier Transform */ 15 | typedef struct _SDFT *hSDFT; 16 | hSDFT SDFT_init( int nwin, int nsamples); 17 | void SDFT( hSDFT h, sux_Window window, float* data, complex** result ); 18 | void ISDFT( hSDFT h, complex** specdata, float* result ); 19 | void SDFT_window( hSDFT h, sux_Window window, complex** specdata ); 20 | void SDFT_free( hSDFT h ); 21 | 22 | /* Sliding Discrete Cosine Transform */ 23 | typedef struct _SDCT *hSDCT; 24 | hSDCT SDCT_init( int nwin, int nsamples ); 25 | void SDCT( hSDCT handle, sux_Window window, float* data, float** result ); 26 | void ISDCT( hSDCT handle, float** specdata, float* result ); 27 | void SDCT_window( hSDCT handle, sux_Window window, float** specdata ); 28 | void SDCT_free( hSDCT handle ); 29 | 30 | /* Ordered Trace buffer for seg Y trace data */ 31 | typedef struct _OTB *hOTB; 32 | hOTB OTB_init( int ntraces, int nsamples ); 33 | int OTB_traces( hOTB h ); 34 | int OTB_push( hOTB h, const segy* const tr ); 35 | void OTB_copyCurrentHdr( hOTB h, segy* const tr ); 36 | int OTB_getSlice( hOTB h, int isample, float* const data ); 37 | const float** const OTB_getData( hOTB h ); 38 | void OTB_getSlab( hOTB h, int isample, int size, float** const data ); 39 | void OTB_free( hOTB h ); 40 | 41 | /* Cyclic Trace buffer for seg Y trace data */ 42 | typedef struct _CTB *hCTB; 43 | hCTB CTB_init( int ntraces, int nsamples ); 44 | int CTB_traces( hCTB h ); 45 | int CTB_push( hCTB h, const segy* const tr ); 46 | void CTB_copyCurrentHdr( hCTB h, segy* const tr ); 47 | int CTB_getSlice( hCTB h, int isample, float* const data ); 48 | const float** const CTB_getData( hCTB h ); 49 | void CTB_free( hCTB h ); 50 | 51 | /* Cyclic buffer for multi-trace sliding discrete fourier transform */ 52 | typedef struct _CBSDFT *hCBSDFT; 53 | hCBSDFT CBSDFT_init( int ntraces, int nsamples, int nwin, sux_Window window ); 54 | int CBSDFT_traces( hCBSDFT h ); 55 | int CBSDFT_samples( hCBSDFT h ); 56 | int CBSDFT_size( hCBSDFT h ); 57 | int CBSDFT_nfreq( hCBSDFT h ); 58 | int CBSDFT_push( hCBSDFT h, const segy* const tr ); 59 | int CBSDFT_getSlice( hCBSDFT h, int isample, int ifreq, complex* const data ); 60 | void CBSDFT_setResult( hCBSDFT h, int isample, int ifreq, complex data ); 61 | void CBSDFT_getResult( hCBSDFT h, segy* const tr ); 62 | void CBSDFT_free( hCBSDFT ); 63 | 64 | #endif /* end of SUX_H */ 65 | 66 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ...SeismicUnixExtra/lib 2 | 3 | include $(CWPROOT)/src/Makefile.config 4 | 5 | D = $I/sux.h 6 | 7 | LIB = $L/libsux.a 8 | 9 | ARCH = \ 10 | $(LIB)(sdft.o) \ 11 | $(LIB)(sdct.o) \ 12 | $(LIB)(otrcbuf.o) \ 13 | $(LIB)(ctrcbuf.o) \ 14 | $(LIB)(cbsdft.o) 15 | 16 | INSTALL: $(LIB) $L 17 | @-rm -f INSTALL 18 | @touch $@ 19 | 20 | $(ARCH) : $D 21 | 22 | $(LIB) : $(ARCH) 23 | $(RANLIB) $(LIB) 24 | 25 | remake : 26 | @-rm -f $(LIB) INSTALL 27 | @$(MAKE) INSTALL 28 | 29 | list : 30 | $(AR) tv $(LIB) 31 | 32 | clean:: 33 | rm -f junk* core a.out 34 | 35 | .PRECIOUS: $(LIB) 36 | -------------------------------------------------------------------------------- /lib/cbsdft.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017. */ 2 | /* All rights reserved. */ 3 | 4 | /*********************** self documentation **********************/ 5 | /************************************************************************* 6 | CBSDFT - cyclic buffer for sliding discrete fourier transform of multi-trace panel 7 | 8 | CBSDFT_init initialise a cyclic SDFT buffer handle 9 | CBSDFT_traces return number of traces in the buffer 10 | CBSDFT_samples return number of time samples per trace 11 | CBSDFT_size return number of samples in SDFT window 12 | CBSDFT_nfreq return number of frequencies in SDFT 13 | CBSDFT_push add a seg y trace to the buffer 14 | CDSDFT_getslice get the spectral data for all traces at the specified time, frequency index 15 | CBSDFT_free release a SDFT transformer handle 16 | 17 | ************************************************************************** 18 | Function Prototypes: 19 | hCBSDFT CBSDFT_init(int ntraces, in nsamples, int nwin, suxWindow window); 20 | void CBSDFT_free(hCBSDFT h); 21 | int CBSDFT_traces(hCBSDFT h); 22 | int CBSDFT_samples(hCBSDFT h); 23 | int CBSDFT_size(hCBSDFT h); 24 | int CBSDFT_nfreq(hCBSDFT h); 25 | int CBSDFT_push(hCBSDFT h, const segy* const tr); 26 | int CBSDFT_getSlice(hCBSDFT h, int isample, int ifreq, complex* const data); 27 | void CBSDFT_setResult(hCBSDFT h, int isample, int ifreq, complex val); 28 | void CBSDFT_getResult(hCBSDFT h, segy* const tr); 29 | 30 | ************************************************************************** 31 | Author: Wayne Mogg 32 | **************************************************************************/ 33 | /**************** end self doc ********************************/ 34 | 35 | #include "cwp.h" 36 | #include "par.h" 37 | #include "sux.h" 38 | 39 | typedef struct { 40 | unsigned char hdr[HDRBYTES]; 41 | } _HDR; 42 | 43 | struct _CBSDFT { 44 | int ns; 45 | int nwin; 46 | int ntr; 47 | sux_Window window; 48 | int intr; 49 | int outtr; 50 | int trcount; 51 | hSDFT sdftH; 52 | complex** resbuf; 53 | _HDR* hdrs; 54 | complex*** specdata; 55 | }; 56 | 57 | hCBSDFT CBSDFT_init( int ntraces, int nsamples, int nwin, sux_Window window ) { 58 | 59 | hCBSDFT h = emalloc(sizeof(struct _CBSDFT)); 60 | h->ntr = ntraces; 61 | h->ns = nsamples; 62 | h->nwin = nwin; 63 | h->window = window; 64 | int hw = nwin/2; 65 | int nf = hw + 1; 66 | h->sdftH = SDFT_init( nwin, nsamples ); 67 | h->resbuf = ealloc2complex( nsamples, nf ); 68 | h->specdata = ealloc3complex( nsamples, nf, nwin ); 69 | h->hdrs = ealloc1(ntraces, sizeof(_HDR)); 70 | h->intr = -1; 71 | h->outtr = 0; 72 | h->trcount = 0; 73 | return h; 74 | } 75 | 76 | void CBSDFT_free( hCBSDFT h ) { 77 | if (h) { 78 | if (h->resbuf) free2complex(h->resbuf); 79 | if (h->specdata) free3complex(h->specdata); 80 | if (h->hdrs) free1(h->hdrs); 81 | SDFT_free(h->sdftH); 82 | free(h); 83 | h = 0; 84 | } else 85 | err("bad pointer in CBSDFT_free."); 86 | } 87 | 88 | int CBSDFT_traces( hCBSDFT h ) { 89 | return h ? h->trcount : 0; 90 | } 91 | 92 | int CBSDFT_samples( hCBSDFT h ) { 93 | return h ? h->ns : 0; 94 | } 95 | 96 | int CBSDFT_size( hCBSDFT h ) { 97 | return h ? h->nwin : 0; 98 | } 99 | 100 | int CBSDFT_nfreq( hCBSDFT h ) { 101 | return h ? h->nwin/2+1 : 0; 102 | } 103 | 104 | int CBSDFT_push( hCBSDFT h, const segy* const tr ) { 105 | if (h) { 106 | if (tr) { 107 | h->intr = (h->intr + 1)%h->ntr; 108 | SDFT(h->sdftH, h->window, (float*) tr->data, h->specdata[h->intr]); 109 | memcpy( (void*)&(h->hdrs[h->intr]), (void*) tr, HDRBYTES ); 110 | h->outtr = (h->trcount <= h->ntr/2)? h->outtr : (h->outtr + 1)%h->ntr; 111 | h->trcount = (h->trcount < h->ntr)? h->trcount+1 : h->ntr; 112 | } else { 113 | h->trcount = (h->trcount>0)? h->trcount-1 : 0; 114 | h->outtr = (h->outtr + 1)%h->ntr; 115 | } 116 | } else 117 | err("bad pointer in CBSDFT_push."); 118 | return h ? h->trcount > h->ntr/2 : 0; 119 | } 120 | 121 | int CBSDFT_getSlice( hCBSDFT h, int isample, int ifreq, complex* const data ) { 122 | if (h && data) { 123 | if (h->trcount >= h->ntr/2) { 124 | int spos = h->intr - h->trcount + 1; 125 | spos = (spos<0)? spos+h->ntr : spos; 126 | for (int itrc=0; itrctrcount; itrc++ ) 127 | data[itrc] = h->specdata[(spos+itrc)%h->ntr][ifreq][isample]; 128 | spos = (spos > h->outtr)? spos-h->ntr : spos; 129 | return (h->trcount < h->ntr)? h->outtr - spos : h->ntr/2; 130 | } else { 131 | warn("trace buffer too empty in CBSDFT_getSlice."); 132 | } 133 | } else 134 | err("bad pointer in CBSDFT_getSlice."); 135 | return 0; 136 | } 137 | 138 | void CBSDFT_setResult( hCBSDFT h, int isample, int ifreq, complex data ) { 139 | if (h) 140 | h->resbuf[ifreq][isample] = data; 141 | else 142 | err("bad pointer in CBSDFT_setResult"); 143 | } 144 | 145 | void CBSDFT_getResult( hCBSDFT h, segy* const tr ) { 146 | if (h && tr) { 147 | ISDFT( h->sdftH, h->resbuf, tr->data ); 148 | memcpy( (void*)tr, (void*)&(h->hdrs[h->outtr]), HDRBYTES ); 149 | } else 150 | err("bad pointer in CBSDFT_getResult"); 151 | 152 | } 153 | -------------------------------------------------------------------------------- /lib/ctrcbuf.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017. */ 2 | /* All rights reserved. */ 3 | 4 | /*********************** self documentation **********************/ 5 | /************************************************************************* 6 | CTB - cyclic buffer of SEG Y trace data - 7 | 8 | CTB_init initialise and return a trace buffer handle 9 | CTB_traces return number of traces in the buffer 10 | CTB_push add a seg y trace to the buffer 11 | CTB_copyCurrentHdr get the header of the current centre trace 12 | CTB_getslice get data at a particular sample for all traces 13 | CTB_getData return a pointer to the buffer data 14 | CTB_free release a trace buffer handle 15 | 16 | ************************************************************************** 17 | Function Prototypes: 18 | hCTB CTB_init(int ntraces, int nsamples); 19 | void CTB_free(hCTB h); 20 | int CTB_traces(hCTB h); 21 | int CTB_push(hCTB h, const seg* const tr); 22 | void CTB_copyCurrentHdr(hCTB h, segy* const tr); 23 | int CTB_getSlice(hCTB h, int isample, float* const data); 24 | const float** const CTB_getData(hOTB h); 25 | 26 | ************************************************************************** 27 | CTB_init: 28 | Input: 29 | ntraces number of traces in buffer - should be odd 30 | nsamples number of samples in each trace 31 | 32 | Returned: trace buffer handle 33 | 34 | ************************************************************************** 35 | CTB_free: 36 | Input: 37 | h trace buffer handle created by CTB_init 38 | 39 | ************************************************************************** 40 | CTB_traces: 41 | Input: 42 | h trace buffer handle created by CTB_init 43 | 44 | Returned: number of traces currrently in the trace buffer 45 | 46 | ************************************************************************** 47 | CTB_push: 48 | Input: 49 | h trace buffer handle created by CTB_init 50 | tr pointer to a seg Y trace to add to the buffer 51 | 52 | Returned: 1 if sufficient number of traces in buffer for processing (ie >ntraces/2), 53 | 0 otherwise 54 | 55 | ************************************************************************** 56 | CTB_copyCurrentHdr: 57 | Input: 58 | h trace buffer handle created by CTB_init 59 | 60 | Output: 61 | tr header from the central trace in the buffer is copied to the 62 | seg Y trace 63 | 64 | ************************************************************************** 65 | CTB_getSlice: 66 | Input: 67 | h trace buffer handle created by CTB_init 68 | isample trace sample for te data slice required 69 | 70 | Output: 71 | data float array with the buffer data at the given sample 72 | 73 | Returned: position in data of the central trace 74 | 75 | ************************************************************************** 76 | CTB_getData: 77 | Input: 78 | h trace buffer handle created by CTB_init 79 | 80 | Returned: pointer to 2D array holding the trace buffer data 81 | 82 | ************************************************************************** 83 | Notes: 84 | Encapsulates the logic of a rolling window of traces over a panel of data. 85 | For a usage example have a look at sutrcmedian. 86 | 87 | This data structure uses a circular buffer to hold the trace data. This has 88 | the advantage that adding a new trace to the buffer does not cause any copying. 89 | The disadvantage is that the traces are not stored in the buffer in the order 90 | they were added which can make some operations more difficult. 91 | 92 | ************************************************************************** 93 | Author: Wayne Mogg 94 | **************************************************************************/ 95 | /**************** end self doc ********************************/ 96 | 97 | #include "cwp.h" 98 | #include "par.h" 99 | #include "su.h" 100 | #include "segy.h" 101 | #include "header.h" 102 | #include "sux.h" 103 | 104 | typedef struct { 105 | unsigned char hdr[HDRBYTES]; 106 | } _HDR; 107 | 108 | struct _CTB { 109 | int ntr; 110 | int intr; 111 | int outtr; 112 | int trcount; 113 | int ns; 114 | _HDR* hdrs; 115 | float** data; 116 | }; 117 | 118 | hCTB CTB_init( int ntraces, int nsamples ) { 119 | 120 | hCTB h = emalloc(sizeof(struct _CTB)); 121 | h->ntr = ntraces; 122 | h->trcount = 0; 123 | h->intr= -1; 124 | h->outtr = 0; 125 | h->ns = nsamples; 126 | h->data = ealloc2float( nsamples, ntraces ); 127 | h->hdrs = ealloc1(ntraces, sizeof(_HDR)); 128 | return h; 129 | } 130 | 131 | void CTB_free( hCTB h ) { 132 | if ( h ) { 133 | if (h->data) free2float( h->data ); 134 | if (h->hdrs) free1( h->hdrs ); 135 | free( h ); 136 | h = 0; 137 | } else 138 | err("bad pointer in CTB_free."); 139 | } 140 | 141 | int CTB_traces( hCTB h ) { 142 | return h ? h->trcount : 0; 143 | } 144 | 145 | int CTB_push( hCTB h, const segy* const tr ) { 146 | if (h) { 147 | int ntr = h->ntr; 148 | int ns = h->ns; 149 | float** data = h->data; 150 | if (tr) { 151 | h->intr = (h->intr + 1)%ntr; 152 | memcpy( (void*)&(data[h->intr][0]), (void*) tr->data, ns*FSIZE ); 153 | memcpy( (void*)&(h->hdrs[h->intr]), (void*) tr, HDRBYTES ); 154 | h->outtr = (h->trcount <= ntr/2)? h->outtr : (h->outtr + 1)%ntr; 155 | h->trcount = (h->trcount < ntr)? h->trcount+1 : ntr; 156 | } else { 157 | h->trcount = (h->trcount>0)? h->trcount-1 : 0; 158 | h->outtr = (h->outtr + 1)%ntr; 159 | } 160 | } else 161 | err("bad pointer in CTB_push."); 162 | return h ? h->trcount > h->ntr/2 : 0; 163 | } 164 | 165 | void CTB_copyCurrentHdr( hCTB h, segy* const tr ) { 166 | if ( h && tr ) { 167 | memcpy( (void*)tr, (void*)&(h->hdrs[h->outtr]), HDRBYTES ); 168 | } else 169 | err("bad pointer in CTB_copyCurrentHdr"); 170 | } 171 | 172 | int CTB_getSlice( hCTB h, int isample, float* const data ) { 173 | if (h && data) { 174 | if (h->trcount >= h->ntr/2) { 175 | int spos = h->intr - h->trcount + 1; 176 | spos = (spos<0)? spos+h->ntr : spos; 177 | // if (isample==0) { 178 | // warn("CTB_getSlice - intr: %d outtr: %d trcount: %d spos: %d icur: %d", h->intr, h->outtr, h->trcount, spos, (h->trcountntr)? h->outtr : h->ntr/2); 179 | // } 180 | for (int itrc=0; itrctrcount; itrc++ ) 181 | data[itrc] = h->data[(spos+itrc)%h->ntr][isample]; 182 | spos = (spos > h->outtr)? spos-h->ntr : spos; 183 | return (h->trcount < h->ntr)? h->outtr - spos : h->ntr/2; 184 | } else { 185 | warn("trace buffer too empty in CTB_getSlice."); 186 | 187 | } 188 | } else 189 | err("bad pointer in CTB_getSlice."); 190 | return 0; 191 | } 192 | 193 | const float** const CTB_getData( hCTB h ) { 194 | if (h) 195 | return (const float** const) h->data; 196 | else 197 | err("bad pointer in OTB_getData."); 198 | return 0; 199 | } 200 | 201 | -------------------------------------------------------------------------------- /lib/otrcbuf.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017. */ 2 | /* All rights reserved. */ 3 | 4 | /*********************** self documentation **********************/ 5 | /************************************************************************* 6 | OTB - ordered buffer of SEG Y trace data - 7 | 8 | OTB_init initialise and return a trace buffer handle 9 | OTB_traces return number of traces in the buffer 10 | OTB_push add a seg y trace to the buffer 11 | OTB_copyCurrentHdr get the header of the current centre trace 12 | OTB_getslice get data at a particular sample for all traces 13 | OTB_getData return a pointer to the buffer data 14 | OTB_free release a trace buffer handle 15 | 16 | ************************************************************************** 17 | Function Prototypes: 18 | hOTB OTB_init(int ntraces, int nsamples); 19 | void OTB_free(hOTB h); 20 | int OTB_traces(hOTB h); 21 | int OTB_push(hOTB h, const seg* const tr); 22 | void OTB_copyCurrentHdr(hOTB h, segy* const tr); 23 | int OTB_getSlice(hOTB h, int isample, float* const data); 24 | const float** const OTB_getData(hOTB h); 25 | 26 | ************************************************************************** 27 | OTB_init: 28 | Input: 29 | ntraces number of traces in buffer - should be odd 30 | nsamples number of samples in each trace 31 | 32 | Returned: trace buffer handle 33 | 34 | ************************************************************************** 35 | OTB_free: 36 | Input: 37 | h trace buffer handle created by OTB_init 38 | 39 | ************************************************************************** 40 | OTB_traces: 41 | Input: 42 | h trace buffer handle created by OTB_init 43 | 44 | Returned: number of traces currrently in the trace buffer 45 | 46 | ************************************************************************** 47 | OTB_push: 48 | Input: 49 | h trace buffer handle created by OTB_init 50 | tr pointer to a seg Y trace to add to the buffer 51 | 52 | Returned: 1 if sufficient number of traces in buffer for processing (ie >ntraces/2), 53 | 0 otherwise 54 | 55 | ************************************************************************** 56 | OTB_copyCurrentHdr: 57 | Input: 58 | h trace buffer handle created by OTB_init 59 | 60 | Output: 61 | tr header from the central trace in the buffer is copied to the 62 | seg Y trace 63 | 64 | ************************************************************************** 65 | OTB_getSlice: 66 | Input: 67 | h trace buffer handle created by OTB_init 68 | isample trace sample for te data slice required 69 | 70 | Output: 71 | data float array with the buffer data at the given sample 72 | 73 | Returned: position in data of the central trace 74 | 75 | ************************************************************************** 76 | OTB_getData: 77 | Input: 78 | h trace buffer handle created by OTB_init 79 | 80 | Returned: pointer to 2D array holding the trace buffer data 81 | 82 | ************************************************************************** 83 | Notes: 84 | Encapsulates the logic of a rolling window of traces over a panel of data. 85 | For a usage example have a look at sutrcmedian. 86 | 87 | The order of traces added to the buffer is preserved in the output of the 88 | OTB_getSlice and OTB_getData. This convenience comes with the overhead of 89 | copying all traces in the buffer every time a new trace is added. 90 | 91 | ************************************************************************** 92 | Author: Wayne Mogg 93 | **************************************************************************/ 94 | /**************** end self doc ********************************/ 95 | 96 | #include "cwp.h" 97 | #include "par.h" 98 | #include "su.h" 99 | #include "segy.h" 100 | #include "header.h" 101 | #include "sux.h" 102 | 103 | typedef struct { 104 | unsigned char hdr[HDRBYTES]; 105 | } _HDR; 106 | 107 | struct _OTB { 108 | int ntr; 109 | int ftr; 110 | int ltr; 111 | int ns; 112 | _HDR* hdrs; 113 | float** data; 114 | }; 115 | 116 | hOTB OTB_init( int ntraces, int nsamples ) { 117 | 118 | hOTB h = emalloc(sizeof(struct _OTB)); 119 | h->ntr = ntraces; 120 | h->ltr = ntraces-1; 121 | h->ftr= ntraces; 122 | h->ns = nsamples; 123 | h->data = ealloc2float( nsamples, ntraces ); 124 | h->hdrs = ealloc1(ntraces, sizeof(_HDR)); 125 | return h; 126 | } 127 | 128 | void OTB_free( hOTB h ) { 129 | if ( h ) { 130 | if (h->data) free2float( h->data ); 131 | if (h->hdrs) free1( h->hdrs ); 132 | free( h ); 133 | h = 0; 134 | } else 135 | err("bad pointer in OTB_free."); 136 | } 137 | 138 | int OTB_traces( hOTB h ) { 139 | return h ? h->ltr - h->ftr + 1: 0; 140 | } 141 | 142 | int OTB_push( hOTB h, const segy* const tr ) { 143 | if (h) { 144 | int ntr = h->ntr; 145 | int ns = h->ns; 146 | float** data = h->data; 147 | h->ftr = (h->ftr > 0)? h->ftr-1 : 0; 148 | memcpy( (void*)&(data[0][0]), (void*)&(data[1][0]), (ntr-1)*ns*FSIZE ); 149 | memcpy( (void*) &(h->hdrs[0]), (void*) &(h->hdrs[1]), (ntr-1)*HDRBYTES ); 150 | if (tr) { 151 | memcpy( (void*)&(data[ntr-1][0]), (void*) tr->data, ns*FSIZE ); 152 | memcpy( (void*)&(h->hdrs[ntr-1]), (void*) tr, HDRBYTES ); 153 | } else 154 | h->ltr--; 155 | // h->ltr = (h->ltr>ntr/2)? h->ltr-1 : h->ltr; 156 | } else 157 | err("bad pointer in OTB_push."); 158 | return h->ltr >= h->ntr/2 && h->ftr <= h->ntr/2; 159 | } 160 | 161 | void OTB_copyCurrentHdr( hOTB h, segy* const tr ) { 162 | if ( h && tr ) { 163 | memcpy( (void*)tr, (void*)&(h->hdrs[h->ntr/2]), HDRBYTES ); 164 | } else 165 | err("bad pointer in OTB_copyCurrentHdr"); 166 | } 167 | 168 | int OTB_getSlice( hOTB h, int isample, float* const data ) { 169 | if (h && data) { 170 | if (h->ltr>=h->ntr/2) { 171 | int nt = OTB_traces(h); 172 | for (int itrc=0; itrcdata[itrc+h->ftr][isample]; 174 | return h->ntr/2-h->ftr; 175 | } else { 176 | warn("trace buffer too empty in OTB_getSlice."); 177 | return 0; 178 | } 179 | } else 180 | err("bad pointer in OTB_getSlice."); 181 | } 182 | 183 | const float** const OTB_getData( hOTB h ) { 184 | if (h) 185 | return (const float** const) h->data; 186 | else 187 | err("bad pointer in OTB_getData."); 188 | } 189 | 190 | void OTB_getSlab( hOTB h, int isample, int size, float** const data) { 191 | if (h && data) { 192 | for (int itrc=0; itrcntr; itrc++) { 193 | int utrc = itrc; 194 | if (itrc < h->ftr) 195 | utrc = h->ftr; 196 | else if (itrc>h->ltr) 197 | utrc = h->ltr; 198 | for (int is=0; isdata[utrc][0]; 202 | else if (idx>=h->ns) 203 | data[itrc][is] = h->data[utrc][h->ns-1]; 204 | else 205 | data[itrc][is] = h->data[utrc][isample+is-size/2]; 206 | } 207 | } 208 | } else 209 | err("bad pointer in OTB_getSlab."); 210 | } 211 | 212 | -------------------------------------------------------------------------------- /lib/sdct.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017. */ 2 | /* All rights reserved. */ 3 | 4 | /*********************** self documentation **********************/ 5 | /************************************************************************* 6 | SDCT - sliding discrete cosine transform (Type II) 7 | 8 | SDCT_init initialise a SDCT transformer handle 9 | SDCT calculate the sliding DCT 10 | ISDCT calculate the inverse sliding DCT 11 | SDCT_free release a SDCT transformer handle 12 | SDCT_window apply a window to the SDCT transform output 13 | 14 | ************************************************************************** 15 | Author: Wayne Mogg 16 | **************************************************************************/ 17 | /**************** end self doc ********************************/ 18 | 19 | #include "cwp.h" 20 | #include "par.h" 21 | #include "sux.h" 22 | 23 | struct _SDCT { 24 | int ns; 25 | int nwin; 26 | float* cosfact; 27 | float* cosfact2; 28 | }; 29 | 30 | hSDCT SDCT_init( int nwin, int nsamples ) { 31 | float fact; 32 | 33 | hSDCT handle = emalloc(sizeof(struct _SDCT)); 34 | handle->ns = nsamples; 35 | handle->nwin = nwin; 36 | handle->cosfact = ealloc1float(nwin); 37 | handle->cosfact2 = ealloc1float(nwin); 38 | 39 | for (int i=0; icosfact[i] = cos(fact/2.0); 42 | handle->cosfact2[i] = 2.0 * cos(fact); 43 | } 44 | 45 | return handle; 46 | } 47 | 48 | void SDCT_free( hSDCT handle ) { 49 | free1float(handle->cosfact); 50 | free1float(handle->cosfact2); 51 | free(handle); 52 | handle = 0; 53 | } 54 | 55 | void SDCT( hSDCT h, sux_Window window, float* data, float** result ){ 56 | int i, its, ifr, hw, neg1; 57 | float val, fact, cosfact; 58 | float frp1, fr, fmr, fmrm1; 59 | 60 | int ns = h->ns; 61 | int nwin = h->nwin; 62 | hw = nwin/2; 63 | 64 | /* Calculate DCT directly for first 2 positions */ 65 | for (ifr=0; ifrns-1)? data[ns-1] : data[its+hw]; 82 | fr = (its+hw-1>ns-1)? data[ns-1] : data[its+hw-1]; 83 | neg1 = 1; 84 | for( ifr=0; ifrcosfact2[ifr] - result[ifr][its-2] + h->cosfact[ifr] * val; 87 | neg1 *= -1; 88 | } 89 | } 90 | 91 | /* Apply the window in the transform domain */ 92 | SDCT_window( h, window, result ); 93 | for (its=0; itsns; 104 | int nwin = h->nwin; 105 | float* work = ealloc1float(nwin); 106 | 107 | switch(window) { 108 | case Hann: 109 | a0 = 0.5; 110 | a1 = -0.25; 111 | a2 = 0.0; 112 | break; 113 | case Hamming: 114 | a0 = 0.54; 115 | a1 = -0.23; 116 | a2 = 0.0; 117 | break; 118 | case Blackman: 119 | a0 = 0.42; 120 | a1 = -0.25; 121 | a2 = 0.04; 122 | break; 123 | default: 124 | err("unrecognised window function: %d", window); 125 | } 126 | 127 | for ( its=0; its=nwin)? data[nwin-2][its] : data[ifr+2][its]; 133 | cp4 = (ifr+4>=nwin)? data[nwin-4][its] : data[ifr+4][its]; 134 | work[ifr] = a0 * data[ifr][its] + a1 * (cm2 + cp2) + a2 * (cm4 + cp4); 135 | } 136 | for ( ifr=0; ifrnwin/2; 148 | 149 | for ( its=0; itsns; its++ ) { 150 | val = 0.0; 151 | neg1 = -1; 152 | for ( ifr=1; ifr<=hw; ifr++ ) { 153 | val += (float)neg1 * specdata[2*ifr][its]; 154 | neg1 *= -1; 155 | } 156 | result[its] = (specdata[0][its] * sqrt(2.0) + 2.0 * val) / (float)h->nwin; 157 | } 158 | } 159 | 160 | -------------------------------------------------------------------------------- /lib/sdft.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017. */ 2 | /* All rights reserved. */ 3 | 4 | /*********************** self documentation **********************/ 5 | /************************************************************************* 6 | SDFT - sliding discrete fourier transform 7 | 8 | SDFT_init initialise a SDFT transformer handle 9 | SDFT calculate the sliding DFT 10 | ISDCT calculate the inverse sliding DFT 11 | SDFT_free release a SDFT transformer handle 12 | SDFT_window apply a window to the SDFT transform output 13 | 14 | ************************************************************************** 15 | Author: Wayne Mogg 16 | **************************************************************************/ 17 | /**************** end self doc ********************************/ 18 | 19 | #include "cwp.h" 20 | #include "par.h" 21 | #include "sux.h" 22 | 23 | struct _SDFT { 24 | int ns; 25 | int nwin; 26 | complex* cfact; 27 | complex* cfactinv; 28 | }; 29 | 30 | hSDFT SDFT_init( int nwin, int nsamples ) { 31 | float fact; 32 | 33 | hSDFT h = emalloc(sizeof(struct _SDFT)); 34 | h->ns = nsamples; 35 | h->nwin = nwin; 36 | int hw = nwin/2; 37 | int nf = hw + 1; 38 | h->cfact = ealloc1complex(nf); 39 | h->cfactinv = ealloc1complex(nwin); 40 | 41 | for (int i=0; icfact[i] = cmplx(cos(fact),sin(fact)); 44 | } 45 | 46 | for (int i=0; icfactinv[i] = cmplx(cos(fact),sin(fact)); 49 | } 50 | 51 | return h; 52 | } 53 | 54 | void SDFT_free( hSDFT h ) { 55 | free1complex( h->cfact ); 56 | free( h ); 57 | h = 0; 58 | } 59 | 60 | void SDFT( hSDFT h, sux_Window window, float* data, complex** result ) { 61 | int i, its, ifr; 62 | complex cval; 63 | float oldv, newv, fact, jfact; 64 | 65 | int ns = h->ns; 66 | int nwin = h->nwin; 67 | int hw = nwin/2; 68 | int nf = hw + 1; 69 | 70 | /* Calculate DFT directly for the first position */ 71 | for (ifr=0; ifrns-1)? data[ns-1] : data[its+hw]; 88 | cval = cmplx(newv-oldv,0.0); 89 | for( ifr=0; ifrcfact[ifr]); 91 | } 92 | 93 | /* Apply the window in the transform domain */ 94 | SDFT_window( h, window, result ); 95 | } 96 | 97 | void SDFT_window( hSDFT h, sux_Window window, complex** data ) { 98 | if (window==None) return; 99 | float a0, a1, a2; 100 | complex cm1, cm2, cp1, cp2; 101 | int its, ifr; 102 | 103 | int ns = h->ns; 104 | int nwin = h->nwin; 105 | int nf = nwin/2+1; 106 | complex* work = ealloc1complex(nf); 107 | 108 | switch(window) { 109 | case Hann: 110 | a0 = 0.5; 111 | a1 = -0.25; 112 | a2 = 0.0; 113 | break; 114 | case Hamming: 115 | a0 = 0.54; 116 | a1 = -0.23; 117 | a2 = 0.0; 118 | break; 119 | case Blackman: 120 | a0 = 0.42; 121 | a1 = -0.25; 122 | a2 = 0.04; 123 | break; 124 | default: 125 | err("unrecognised window function: %d", window); 126 | } 127 | 128 | for ( its=0; its=nf)? conjg(data[nwin-ifr-1][its]): data[ifr+1][its]; 134 | cp2 = (ifr+2>=nf)? conjg(data[nwin-ifr-2][its]): data[ifr+2][its]; 135 | work[ifr] = cadd(cadd(crmul(data[ifr][its], a0), crmul(cadd(cp1,cm1),a1)), crmul(cadd(cp2,cm2),a2)); 136 | } 137 | for (ifr=0; ifrnwin; 147 | int nf = nwin/2+1; 148 | int ns = h->ns; 149 | 150 | for (its=0; itsnf-1)? conjg(specdata[nwin-ifr][its]) : (specdata[ifr][its]); 154 | val = cadd(val, cmul(F, h->cfactinv[ifr])); 155 | } 156 | result[its] = val.r/(float)nwin; 157 | } 158 | } 159 | 160 | -------------------------------------------------------------------------------- /main/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ...su/main 2 | 3 | include $(CWPROOT)/src/Makefile.config 4 | 5 | D = $L/libcwp.a $L/libpar.a $L/libsu.a $L/libsux.a 6 | 7 | LFLAGS= $(PRELFLAGS) -L$L -lsux -lsu -lpar -lcwp -lm $(POSTLFLAGS) 8 | 9 | 10 | PROGS = \ 11 | $B/susdft \ 12 | $B/suisdft \ 13 | $B/susdct \ 14 | $B/suisdct \ 15 | $B/sutrcmedian \ 16 | $B/suctrcmedian \ 17 | $B/susdft_denoise \ 18 | $B/sulpasmooth \ 19 | $B/suvpef 20 | 21 | INSTALL : $(PROGS) 22 | @-rm -f INSTALL 23 | @cat ../Stub.md ../programs.md >../README.md 24 | @cat ../docs/Stub.md ../docs/programs.md > ../docs/start.md 25 | @-rm ../programs.md 26 | @-rm ../docs/programs.md 27 | @touch $@ 28 | 29 | 30 | $(PROGS): $(CTARGET) $D 31 | -$(CC) $(CFLAGS) $(@F).c $(LFLAGS) -o $@ 32 | @$(MCHMODLINE) 33 | @-$(@F) 2> ../docs/$(@F).md 34 | @echo \| [$(@F)]"(docs/"$(@F)".md)" \| $(shell $(@F) 2>&1|head -n 2|tail -n 1) \| >> ../programs.md 35 | @echo \| [$(@F)]"("$(@F)".md)" \| $(shell $(@F) 2>&1|head -n 2|tail -n 1) \| >> ../docs/programs.md 36 | @echo $(@F) installed in $B 37 | 38 | remake : 39 | -rm -f $(PROGS) INSTALL 40 | $(MAKE) 41 | 42 | clean:: 43 | rm -f a.out junk* JUNK* core 44 | -------------------------------------------------------------------------------- /main/suctrcmedian.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) Wayne Mogg, 2017.*/ 2 | /* All rights reserved. */ 3 | 4 | #include "su.h" 5 | #include "segy.h" 6 | #include "header.h" 7 | #include "sux.h" 8 | 9 | /*********************** self documentation **********************/ 10 | char *sdoc[] = { 11 | "# SUCTRCMEDIAN ", 12 | "Rolling median filter over a panel of seismic traces by a cyclic trace buffer ", 13 | " ", 14 | "## Usage ", 15 | " suctrcmedian < stdin > stdout ", 16 | " ", 17 | "### Optional Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| ntr= | number (odd) of traces in filter panel | 5 |", 21 | "| mode= | =0 output filtered trace, =1 output noise | 0 |", 22 | "| verbose= | =0 no advisory messages, =1 for messages | 0 |", 23 | " ", 24 | "## Notes ", 25 | "This is primarily a demonstation and test platform for the cyclic trace buffer implementation. ", 26 | " ", 27 | NULL}; 28 | 29 | /* Author: Wayne Mogg, May 2017 30 | * 31 | * Trace header fields accessed: ns, trid 32 | */ 33 | /**************** end self doc ***********************************/ 34 | 35 | segy tr; 36 | 37 | int 38 | main(int argc, char **argv) 39 | { 40 | int ntr; 41 | int mode; 42 | int verbose; 43 | 44 | int is, tcount, imed; 45 | int nsamples; 46 | cwp_Bool seismic; 47 | float* databuf; 48 | hCTB ctbHandle; 49 | 50 | // Initialize 51 | initargs(argc, argv); 52 | requestdoc(1); 53 | 54 | /* Get info from first trace */ 55 | nsamples = 0; 56 | while (gettr(&tr)) { 57 | seismic = ISSEISMIC(tr.trid); 58 | if (seismic) { 59 | nsamples = tr.ns; 60 | break; 61 | } else 62 | warn("skipping non-seismic trace with trid=%d", tr.trid); 63 | } 64 | if (nsamples==0) 65 | err("zero length traces not allowed."); 66 | 67 | // Get parameters 68 | if (!getparint("ntr", &ntr)) ntr = 5; 69 | if (!ntr%2) { 70 | ntr++; 71 | if (verbose) 72 | warn("adjusting ntr to be odd, was %d now %d",ntr-1, ntr); 73 | } 74 | if (!getparint("mode", &mode)) mode = 0; 75 | if (!getparint("verbose", &verbose)) verbose=0; 76 | 77 | // Set up trace buffer and work space 78 | databuf = ealloc1float( ntr ); 79 | ctbHandle = CTB_init( ntr, nsamples ); 80 | /* Main processing loop */ 81 | do { 82 | seismic = ISSEISMIC(tr.trid); 83 | if (seismic) { 84 | if (CTB_push(ctbHandle, &tr)) { 85 | tcount = CTB_traces(ctbHandle); 86 | imed = tcount/2; 87 | for (is=0; is stdout ", 16 | " ", 17 | "### Required Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| dt= | time sampling interval (sec) | trcheader |", 21 | "| nwin= | window size of original t-f transform | |", 22 | " ", 23 | "### Optional Parameters ", 24 | "| Parameter | Description | Default |", 25 | "|:---------:| ----------------------------------------------- |:-------------:|", 26 | "| verbose | 0 - no advisory message, 1- for messages | |", 27 | " ", 28 | "## Notes ", 29 | "This process inverts a time-frequency decomposition generated by the sliding ", 30 | "discrete cosine transform (SUSDCT). ", 31 | " ", 32 | "## Examples ", 33 | " suvibro | susdct nwin=31 | suisdct nwin=31 | suximage ", 34 | " ", 35 | NULL}; 36 | 37 | /* Author: Wayne Mogg, Apr 2017 38 | * 39 | * Trace header fields accessed: ns,dt, trid, ntr 40 | * Trace header fields modified: tracl, tracr, d1, f2, d2, trid, ntr 41 | */ 42 | /**************** end self doc ***********************************/ 43 | 44 | 45 | segy tr; 46 | 47 | int 48 | main(int argc, char **argv) 49 | { 50 | float dt; 51 | int nwin; 52 | int verbose; 53 | 54 | int nt; 55 | int tracr=0; 56 | 57 | int ntrc; 58 | int nf; 59 | int j; 60 | float** specbuff; 61 | hSDCT dctHandle; 62 | 63 | /* Initialize */ 64 | initargs(argc, argv); 65 | requestdoc(1); 66 | 67 | /* Get info from first trace */ 68 | if (!gettr(&tr)) err("can't get first trace"); 69 | nt = tr.ns; 70 | if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; 71 | if (!dt) err("dt field is zero and not getparred"); 72 | if (tr.trid != AMPLITUDE) err("expecting AMPLITUDE trace but got trcid=%d", tr.trid); 73 | 74 | /* Get parameters */ 75 | if (!getparint("verbose", &verbose)) verbose=0; 76 | if (!getparint("nwin", &nwin)) err("nwin must be specified"); 77 | if (nwin%2==0) { 78 | nwin++; 79 | if (verbose) 80 | warn("adjusting nwin to be odd, was %d now %d",nwin-1, nwin); 81 | } 82 | 83 | /* Set up DCT parameters and workspaces */ 84 | nf = nwin; 85 | dctHandle = SDCT_init( nwin, nt ); 86 | specbuff = ealloc2float(nt, nf ); 87 | ntrc = 0; 88 | tracr = 0; 89 | /* Main processing loop */ 90 | do { 91 | for (j=0; j stdout ", 16 | " ", 17 | "### Required Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| dt= | time sampling interval (sec) | trcheader |", 21 | "| nwin= | window size of original t-f transform | |", 22 | " ", 23 | "### Optional Parameters ", 24 | "| Parameter | Description | Default |", 25 | "|:---------:| ----------------------------------------------- |:-------------:|", 26 | "| verbose | 0 - no advisory message, 1- for messages | |", 27 | " ", 28 | "## Notes ", 29 | "This process inverts a time-frequency decomposition generated by the sliding ", 30 | "discrete fourier transform (SUSDFT).", 31 | " ", 32 | "## Examples ", 33 | " suvibro | susdft nwin=31 | suisdft nwin=31 | suximage ", 34 | " ", 35 | NULL}; 36 | 37 | /* Author: Wayne Mogg, Apr 2017 38 | * 39 | * Trace header fields accessed: ns,dt, trid, ntr 40 | * Trace header fields modified: tracl, tracr, d1, f2, d2, trid, ntr 41 | */ 42 | /**************** end self doc ***********************************/ 43 | 44 | 45 | segy tr; 46 | 47 | int 48 | main(int argc, char **argv) 49 | { 50 | float dt; 51 | int nwin; 52 | int verbose; 53 | 54 | int nt; 55 | int tracr=0; 56 | 57 | int ntrc; 58 | int nf; 59 | int j; 60 | complex** specbuff; 61 | hSDFT dftHandle; 62 | 63 | /* Initialize */ 64 | initargs(argc, argv); 65 | requestdoc(1); 66 | 67 | /* Get info from first trace */ 68 | if (!gettr(&tr)) err("can't get first trace"); 69 | nt = tr.ns/2; 70 | if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; 71 | if (!dt) err("dt field is zero and not getparred"); 72 | if (tr.trid != FUNPACKNYQ) err("expecting complex trace but got trcid=%d", tr.trid); 73 | 74 | /* Get parameters */ 75 | if (!getparint("verbose", &verbose)) verbose=0; 76 | if (!getparint("nwin", &nwin)) err("nwin must be specified"); 77 | if (nwin%2==0) { 78 | nwin++; 79 | if (verbose) 80 | warn("adjusting nwin to be odd, was %d now %d",nwin-1, nwin); 81 | } 82 | 83 | /* Set up DCT parameters and workspaces */ 84 | nf = nwin/2+1; 85 | dftHandle = SDFT_init( nwin, nt ); 86 | specbuff = ealloc2complex(nt, nf ); 87 | ntrc = 0; 88 | tracr = 0; 89 | /* Main processing loop */ 90 | do { 91 | for (j=0; j sdout [optional parameters] ", 16 | " ", 17 | "### Optional Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| mode= | =0 output filtered trace, =1 output noise | 0 |", 21 | "| verbose= | =0 no advisory messages, =1 for messages | 0 |", 22 | " ", 23 | NULL}; 24 | 25 | /* Author: Wayne Mogg, May 2017 26 | * 27 | * Trace header fields accessed: ns, trid 28 | */ 29 | /**************** end self doc ***********************************/ 30 | 31 | segy tr; 32 | 33 | int 34 | main(int argc, char **argv) 35 | { 36 | int nsize=5; 37 | int ntr = nsize; 38 | int mode; 39 | int verbose; 40 | 41 | int is; 42 | int nsamples; 43 | cwp_Bool seismic; 44 | float** db; 45 | hOTB otbHandle; 46 | 47 | // Initialize 48 | initargs(argc, argv); 49 | requestdoc(1); 50 | 51 | /* Get info from first trace */ 52 | nsamples = 0; 53 | while (gettr(&tr)) { 54 | seismic = ISSEISMIC(tr.trid); 55 | if (seismic) { 56 | nsamples = tr.ns; 57 | break; 58 | } else 59 | warn("skipping non-seismic trace with trid=%d", tr.trid); 60 | } 61 | if (nsamples==0) 62 | err("zero length traces not allowed."); 63 | 64 | // Get parameters 65 | if (!getparint("mode", &mode)) mode = 0; 66 | if (!getparint("verbose", &verbose)) verbose=0; 67 | 68 | // Set up trace buffer and work space 69 | db = ealloc2float( nsize, ntr ); 70 | otbHandle = OTB_init( ntr, nsamples ); 71 | /* Main processing loop */ 72 | do { 73 | seismic = ISSEISMIC(tr.trid); 74 | if (seismic) { 75 | if (OTB_push( otbHandle, &tr )) { 76 | for (is=0; is stdout ", 16 | " ", 17 | "### Required Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| dt= | time sampling interval (sec) | trcheader |", 21 | " ", 22 | "### Optional Parameters ", 23 | "| Parameter | Description | Default |", 24 | "|:---------:| ----------------------------------------------- |:-------------:|", 25 | "| nwin= | number (odd) of samples in SDFT window | 31 |", 26 | "| window= | none - no window applied to each data segment | none |", 27 | "| | hann - Hann window | |", 28 | "| | hamming - Hamming window | |", 29 | "| | blackman - Blackman window | |", 30 | "| verbose= | 0 - no advisory messages, 1 - for messages | 0 |", 31 | " ", 32 | "## Notes ", 33 | "This process calculates a time-frequency decomposition of seismic data using ", 34 | "the sliding discrete cosine transform. ", 35 | " ", 36 | "## Examples ", 37 | " suvibro | susdct | suximage ", 38 | " ", 39 | NULL}; 40 | 41 | /* Author: Wayne Mogg, Apr 2017 42 | * 43 | * Trace header fields accessed: ns,dt, trid, ntr 44 | * Trace header fields modified: tracl, tracr, d1, f2, d2, trid, ntr 45 | */ 46 | /**************** end self doc ***********************************/ 47 | 48 | 49 | segy tr; 50 | 51 | int 52 | main(int argc, char **argv) 53 | { 54 | float dt; 55 | int nwin; 56 | int verbose; 57 | cwp_String window; 58 | sux_Window iwind = None; 59 | 60 | int nt; 61 | float df; 62 | int tracr=0; 63 | 64 | int nf; 65 | int i,j; 66 | cwp_Bool seismic; 67 | hSDCT dctHandle; 68 | float** specbuff; 69 | 70 | /* Initialize */ 71 | initargs(argc, argv); 72 | requestdoc(1); 73 | 74 | /* Get info from first trace */ 75 | if (!gettr(&tr)) err("can't get first trace"); 76 | nt = tr.ns; 77 | if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; 78 | if (!dt) err("dt field is zero and not getparred"); 79 | 80 | /* Get parameters */ 81 | if (!getparint("verbose", &verbose)) verbose=0; 82 | if (!getparint("nwin", &nwin)) nwin = 31; 83 | if (nwin%2==0) { 84 | nwin++; 85 | if (verbose) 86 | warn("adjusting nwin to be odd, was %d now %d",nwin-1, nwin); 87 | } 88 | if (!getparstring("window", &window)) window = "none"; 89 | if (STREQ(window, "hann")) iwind = Hann; 90 | else if (STREQ(window, "hamming")) iwind = Hamming; 91 | else if (STREQ(window, "blackman")) iwind = Blackman; 92 | else if (!STREQ(window, "none")) 93 | err("unknown window=\"%s\", see self-doc", window); 94 | 95 | 96 | /* Set up DCT parameters and workspaces */ 97 | df = 1.0/(2.0*nwin*dt); 98 | nf = nwin; 99 | dctHandle = SDCT_init( nwin, nt ); 100 | specbuff = ealloc2float(nt, nf ); 101 | 102 | /* Main processing loop */ 103 | do { 104 | seismic = ISSEISMIC(tr.trid); 105 | if (!seismic) { 106 | if (verbose) 107 | warn("ignoring input trace=%d with non-seismic trcid=%d", tr.tracl, tr.trid); 108 | continue; 109 | } 110 | SDCT( dctHandle, iwind, tr.data, specbuff ); 111 | tracr = 0; 112 | for ( i=0; i stdout ", 16 | " ", 17 | "### Required Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| dt= | time sampling interval (sec) | trcheader |", 21 | " ", 22 | "### Optional Parameters ", 23 | "| Parameter | Description | Default |", 24 | "|:---------:| ----------------------------------------------- |:-------------:|", 25 | "| nwin= | number (odd) of samples in SDFT window | 31 |", 26 | "| mode= | complex - output complex spectra | complex |", 27 | "| | amp - output spectral amplitude | |", 28 | "| | phase - output spectral phase | |", 29 | "| | real - output real part | |", 30 | "| | imag - output imaginary part | |", 31 | "| window= | none - no window applied to each data segment | none |", 32 | "| | hann - Hann window | |", 33 | "| | hamming - Hamming window | |", 34 | "| | blackman - Blackman window | |", 35 | "| verbose= | 0 - no advisory messages, 1 - for messages | 0 |", 36 | " ", 37 | "## Notes ", 38 | "This process calculates a time-frequency decomposition of seismic data using ", 39 | "the sliding discrete fourier transform. ", 40 | " ", 41 | "## Examples: ", 42 | " suvibro | susdft nwin=51 mode=amp window=hann | suximage ", 43 | " ", 44 | " ![susdft example](images/susdft_2.png) ", " ", 45 | NULL}; 46 | 47 | /* Author: Wayne Mogg, Apr 2017 48 | * 49 | * Trace header fields accessed: ns,dt, trid, ntr 50 | * Trace header fields modified: tracl, tracr, d1, f2, d2, trid, ntr 51 | */ 52 | /**************** end self doc ***********************************/ 53 | 54 | 55 | #define CPLX 1 56 | #define REAL 2 57 | #define IMAG 3 58 | #define AMP 4 59 | #define ARG 5 60 | 61 | segy tr; 62 | 63 | int 64 | main(int argc, char **argv) 65 | { 66 | float dt; 67 | int nwin; 68 | cwp_String mode; 69 | int imode=CPLX; 70 | int verbose; 71 | cwp_String window; 72 | sux_Window iwind = None; 73 | 74 | int nt; 75 | float df; 76 | int tracr=0; 77 | float re, im; 78 | 79 | int nf; 80 | int i,j; 81 | cwp_Bool seismic; 82 | hSDFT dftHandle; 83 | complex** specbuff; 84 | 85 | /* Initialize */ 86 | initargs(argc, argv); 87 | requestdoc(1); 88 | 89 | /* Get info from first trace */ 90 | if (!gettr(&tr)) err("can't get first trace"); 91 | nt = tr.ns; 92 | if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; 93 | if (!dt) err("dt field is zero and not getparred"); 94 | 95 | /* Get parameters */ 96 | if (!getparint("verbose", &verbose)) verbose=0; 97 | if (!getparint("nwin", &nwin)) nwin = 31; 98 | if (nwin%2==0) { 99 | nwin++; 100 | if (verbose) 101 | warn("adjusting nwin to be odd, was %d now %d",nwin-1, nwin); 102 | } 103 | if (!getparstring("mode", &mode)) mode = "complex"; 104 | 105 | if (STREQ(mode, "phase")) imode = ARG; 106 | else if (STREQ(mode, "real")) imode = REAL; 107 | else if (STREQ(mode, "imag")) imode = IMAG; 108 | else if (STREQ(mode, "amp")) imode = AMP; 109 | else if (!STREQ(mode, "complex")) 110 | err("unknown mode=\"%s\", see self-doc", mode); 111 | 112 | if (!getparstring("window", &window)) window = "none"; 113 | if (STREQ(window, "hann")) iwind = Hann; 114 | else if (STREQ(window, "hamming")) iwind = Hamming; 115 | else if (STREQ(window, "blackman")) iwind = Blackman; 116 | else if (!STREQ(window, "none")) 117 | err("unknown window=\"%s\", see self-doc", window); 118 | 119 | /* Set up DFT parameters and workspaces */ 120 | df = 1.0/(nwin*dt); 121 | nf = nwin/2+1; 122 | dftHandle = SDFT_init(nwin, nt); 123 | specbuff = ealloc2complex(nt, nf ); 124 | 125 | /* Main processing loop */ 126 | do { 127 | seismic = ISSEISMIC(tr.trid); 128 | if (!seismic) { 129 | if (verbose) 130 | warn("ignoring input trace=%d with non-seismic trcid=%d", tr.tracl, tr.trid); 131 | continue; 132 | } 133 | SDFT( dftHandle, iwind, tr.data, specbuff ); 134 | 135 | tracr = 0; 136 | for ( i=0; i stdout ", 16 | " ", 17 | "### Required Parameters ", 18 | "| Parameter | Description | Default |", 19 | "|:---------:| ----------------------------------------------- |:-------------:|", 20 | "| dt= | time sampling interval (sec) | trcheader |", 21 | " ", 22 | "### Optional Parameters ", 23 | "| Parameter | Description | Default |", 24 | "|:---------:| ----------------------------------------------- |:-------------:|", 25 | "| ntr= | number (odd) of traces in analysis panel | 9 |", 26 | "| nwin= | number (odd) of samples in SDFT window | 31 |", 27 | "| window= | none - no window applied to each data segment | none |", 28 | "| | hann - Hann window | |", 29 | "| | hamming - Hamming window | |", 30 | "| | blackman - Blackman window | |", 31 | "| reject= | percentage of high trace amplitudes to reject | 10 |", 32 | "| type= | swmean - only replace rejected trace with mean of accepted | swmean |", 33 | "| | swmedian - only replace rejected trace with median of accepted | |", 34 | "| | median - output median of accepted traces | |", 35 | "| | mean - output mean of accepted traces | |", 36 | "| mode= | 0 - output filtered, 1 - output noise | 0 |", 37 | "| verbose= | 0 - no advisory messages, 1 - for messages | 0 |", 38 | " ", 39 | "## Notes ", 40 | "This process implements the following algorithm: ", 41 | " ", 42 | "1. Time-Frequency transform of the trace using the sliding DFT ", 43 | "2. For each time and frequency sample acrosss the panel of traces ", 44 | " - Sort by amplitude and discard the top reject% of values ", 45 | " - For type=mean or median output the mean or median respectively of the kept traces. ", 46 | " - For type=swmean or swmedian output the mean or median respectively of the kept traces " 47 | " only if the current trace value was rejected, otherwise the original value is passed unchanged. ", 48 | "3. Inverse sliding DFT and output ", 49 | " ", 50 | NULL}; 51 | 52 | /* Author: Wayne Mogg, May 2017 53 | * 54 | * Trace header fields accessed: ns, trid 55 | */ 56 | /**************** end self doc ***********************************/ 57 | 58 | segy tr; 59 | typedef enum ProcType { SwMean, SwMedian, Median, Mean } proc_Type; 60 | 61 | int main(int argc, char **argv) 62 | { 63 | float dt; 64 | int nwin; 65 | int ntr; 66 | cwp_String window; 67 | sux_Window iwind = None; 68 | float reject; 69 | int nkeep; 70 | cwp_String type; 71 | proc_Type itype = SwMean; 72 | int mode; 73 | int verbose; 74 | 75 | int is, tcount, imed, ifreq,nfreq; 76 | int nsamples; 77 | cwp_Bool seismic; 78 | complex* specbuf; 79 | float* ampbuf; 80 | int* idxbuf; 81 | hCBSDFT cbsdftH; 82 | 83 | // Initialize 84 | initargs(argc, argv); 85 | requestdoc(1); 86 | 87 | /* Get info from first trace */ 88 | nsamples = 0; 89 | while (gettr(&tr)) { 90 | seismic = ISSEISMIC(tr.trid); 91 | if (seismic) { 92 | nsamples = tr.ns; 93 | break; 94 | } else 95 | warn("skipping non-seismic trace with trid=%d", tr.trid); 96 | } 97 | if (nsamples==0) 98 | err("zero length traces not allowed."); 99 | 100 | // Get parameters 101 | if (!getparint("verbose", &verbose)) verbose=0; 102 | if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; 103 | if (!dt) err("trace dt field is zero and not getparred"); 104 | if (!getparint("nwin", &nwin)) nwin = 31; 105 | if (nwin%2==0) { 106 | nwin++; 107 | if (verbose) 108 | warn("adjusting nwin to be odd, was %d now %d",nwin-1, nwin); 109 | } 110 | if (!getparint("ntr", &ntr)) ntr = 9; 111 | if (!ntr%2) { 112 | ntr++; 113 | if (verbose) 114 | warn("adjusting ntr to be odd, was %d now %d",ntr-1, ntr); 115 | } 116 | if (!getparfloat("reject", &reject)) reject=10.0; 117 | if (reject<=0 || reject>100) { 118 | warn("reject out of range 0-100, reset to 10"); 119 | reject = 10; 120 | } 121 | if (!getparstring("type", &type)) type = "swmean"; 122 | if (STREQ(type, "swmedian")) itype = SwMedian; 123 | else if (STREQ(type, "median")) itype = Median; 124 | else if (STREQ(type, "mean")) itype = Mean; 125 | else if (!STREQ(type, "swmean")) 126 | err("unknown type\"%s\", see self-doc", type); 127 | 128 | if (!getparint("mode", &mode)) mode = 0; 129 | 130 | if (!getparstring("window", &window)) window = "none"; 131 | if (STREQ(window, "hann")) iwind = Hann; 132 | else if (STREQ(window, "hamming")) iwind = Hamming; 133 | else if (STREQ(window, "blackman")) iwind = Blackman; 134 | else if (!STREQ(window, "none")) 135 | err("unknown window=\"%s\", see self-doc", window); 136 | 137 | // Set up cyclic SDFT buffer and work space 138 | specbuf = ealloc1complex( ntr ); 139 | ampbuf = ealloc1float( ntr ); 140 | idxbuf = ealloc1int( ntr ); 141 | cbsdftH = CBSDFT_init( ntr, nsamples, nwin, iwind ); 142 | nfreq = CBSDFT_nfreq(cbsdftH); 143 | /* Main processing loop */ 144 | do { 145 | seismic = ISSEISMIC(tr.trid); 146 | if (seismic) { 147 | if (CBSDFT_push(cbsdftH, &tr)) { 148 | tcount = CBSDFT_traces(cbsdftH); 149 | nkeep = NINT((float) tcount * (100-reject)/100); 150 | if (nkeep > tcount) 151 | nkeep = tcount; 152 | imed = nkeep/2; 153 | float inv_nkeep = 1.0/(float)nkeep; 154 | complex outval = cmplx(0.0,0.0); 155 | for (is=0; is tcount) 210 | nkeep = tcount; 211 | imed = nkeep/2; 212 | float inv_nkeep = 1.0/(float)nkeep; 213 | complex outval = cmplx(0.0,0.0); 214 | for (is=0; is stdout ", 16 | "### Optional Parameters ", 17 | "| Parameter | Description | Default |", 18 | "|:---------:| ----------------------------------------------- |:-------------:|", 19 | "| ntr= | number (odd) of traces in filter panel | 5 |", 20 | "| mode= | =0 output filtered trace, =1 output noise | 0 |", 21 | "| verbose= | =0 no advisory messages, =1 for messages | 0 |", 22 | " ", 23 | "## Notes ", 24 | "This is primarily a demonstation and test platform for the ordered trace buffer implementation. ", 25 | " ", 26 | NULL}; 27 | 28 | /* Author: Wayne Mogg, May 2017 29 | * 30 | * Trace header fields accessed: ns, trid 31 | */ 32 | /**************** end self doc ***********************************/ 33 | 34 | segy tr; 35 | 36 | int 37 | main(int argc, char **argv) 38 | { 39 | int ntr; 40 | int mode; 41 | int verbose; 42 | 43 | int is, tcount, imed; 44 | int nsamples; 45 | cwp_Bool seismic; 46 | float* databuf; 47 | hOTB otbHandle; 48 | 49 | // Initialize 50 | initargs(argc, argv); 51 | requestdoc(1); 52 | 53 | /* Get info from first trace */ 54 | nsamples = 0; 55 | while (gettr(&tr)) { 56 | seismic = ISSEISMIC(tr.trid); 57 | if (seismic) { 58 | nsamples = tr.ns; 59 | break; 60 | } else 61 | warn("skipping non-seismic trace with trid=%d", tr.trid); 62 | } 63 | if (nsamples==0) 64 | err("zero length traces not allowed."); 65 | 66 | // Get parameters 67 | if (!getparint("ntr", &ntr)) ntr = 5; 68 | if (!ntr%2) { 69 | ntr++; 70 | if (verbose) 71 | warn("adjusting ntr to be odd, was %d now %d",ntr-1, ntr); 72 | } 73 | if (!getparint("mode", &mode)) mode = 0; 74 | if (!getparint("verbose", &verbose)) verbose=0; 75 | 76 | // Set up trace buffer and work space 77 | databuf = ealloc1float( ntr ); 78 | otbHandle = OTB_init( ntr, nsamples ); 79 | /* Main processing loop */ 80 | do { 81 | seismic = ISSEISMIC(tr.trid); 82 | if (seismic) { 83 | if (OTB_push( otbHandle, &tr )) { 84 | tcount = OTB_traces(otbHandle); 85 | imed = tcount/2; 86 | for (is=0; is stdout [optional parameters] ", 17 | " ", 18 | "### Required Parameters ", 19 | "| Parameter | Description | Default |", 20 | "|:---------:| ----------------------------------------------- |:-------------:|", 21 | "| dt= | time sampling interval (sec) | trcheader |", 22 | " ", 23 | "### Optional Parameters ", 24 | "| Parameter | Description | Default |", 25 | "|:---------:| ----------------------------------------------- |:-------------:|", 26 | "| key= | header word specifying lag locations | cdp |", 27 | "| xlag= | array of lag locations as given by key | |", 28 | "| lag= | array of prediction filter lags in seconds | dt |", 29 | "| len= | operator length in seconds | tr.ns*dt/20 |", 30 | "| pnoise= | relative additive noise level | 0.001 |", 31 | "| mincorr= | start of autocorrelation window in seconds | tmin |", 32 | "| maxcorr= | end of autocorrelation window in seconds | tmax |", 33 | "| verbose= | 0 - no advisory messages, 1 - for messages | 0 |", 34 | " ", 35 | "Trace header fields accessed: ns, dt ", 36 | "Trace header fields modified: none ", 37 | " ", 38 | "## Notes ", 39 | "- For fixed lag omit the key= and xlag= parameters and give a single lag= value. ", 40 | "- For spatially variable lag specify key=, xlag= and lag= arrays. ", 41 | "- Linear interpolation and constant extrapolation used to compute lag from the ", 42 | "arrays. ", 43 | " ", 44 | "This is a simplified version of supef ", 45 | " ", 46 | NULL}; 47 | /*********************** end self doc *******************************************/ 48 | 49 | segy intrace, outtrace; 50 | 51 | int 52 | main(int argc, char **argv) 53 | { 54 | float dt; 55 | int ns; 56 | cwp_Bool seismic; 57 | 58 | cwp_String key; 59 | int nlag; 60 | float* xlag=NULL; 61 | float* lag=NULL; 62 | int ilag; 63 | float len; 64 | int ilen, lenbytes; 65 | float pnoise; 66 | float mincorr; 67 | float maxcorr; 68 | int imincorr, imaxcorr, ncorr, lcorr; 69 | int verbose; 70 | 71 | cwp_String keyType; 72 | int keyIndex; 73 | Value keyVal; 74 | float val; 75 | 76 | float* wiener=NULL; 77 | float* spiker=NULL; 78 | float* crosscorr=NULL; 79 | float* autocorr=NULL; 80 | 81 | /* Initialize */ 82 | initargs(argc, argv); 83 | requestdoc(1); 84 | 85 | /* Get info from first trace */ 86 | if (!gettr(&intrace)) err("can't get first trace"); 87 | ns = intrace.ns; 88 | if (!getparfloat("dt", &dt)) dt = ((double) intrace.dt)/1000000.0; 89 | if (!dt) err("dt field is zero and not getparred"); 90 | 91 | /* Get parameters */ 92 | if (!getparint("verbose", &verbose)) verbose=0; 93 | if (!getparstring("key", &key)) key="cdp"; 94 | nlag = countparval("xlag"); 95 | if (nlag>0) { 96 | if (countparval("lag")!=nlag) 97 | err("a lag value must be given for each %s in xlag=", key); 98 | } 99 | else { 100 | nlag = 1; 101 | } 102 | xlag = ealloc1float(nlag); 103 | if (!getparfloat("xlag",xlag)) xlag[0] = intrace.cdp; 104 | lag = ealloc1float(nlag); 105 | if (!getparfloat("lag",lag)) lag[0] = dt; 106 | 107 | if (getparfloat("mincorr", &mincorr)) { 108 | if (mincorr < 0.0) { 109 | warn("mincorr=%g too small resetting to start of trace", mincorr); 110 | imincorr=0; 111 | } else 112 | imincorr = NINT(mincorr/dt); 113 | } else 114 | imincorr = 0; 115 | 116 | if (getparfloat("maxcorr", &maxcorr)) { 117 | imaxcorr = NINT(maxcorr/dt); 118 | if (imaxcorr > ns) { 119 | warn("maxcorr=%g too big resetting to end of trace", maxcorr); 120 | imaxcorr = ns; 121 | } else if (imaxcorr