gctl_seismic/lib/seismic/signal.h

122 lines
4.7 KiB
C
Raw Normal View History

2024-09-10 20:22:53 +08:00
/********************************************************
*
*
*
*
*
*
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#ifndef _GCTL_SEISMIC_SIGNAL_H
#define _GCTL_SEISMIC_SIGNAL_H
#include "gctl_seismic_config.h"
#ifdef GCTL_SEISMIC_MATHGL
#include "mgl2/mgl.h"
#include "mgl2/fltk.h"
#endif // GCTL_SEISMIC_MATHGL
2025-02-09 22:16:31 +08:00
#include "gctl/core.h"
#include "gctl/utility.h"
#include "gctl/maths.h"
#include "gctl/algorithms.h"
#include "gctl/io.h"
2024-09-10 20:22:53 +08:00
namespace gctl
{
enum SIG_CHANNEL
{
UNKNOWN = 0,
SHN = 1,
SHE, // 2
SHZ,
BHN,
BHE,
BHZ,
SBHN,
SBHE,
SBHZ,
};
static const std::string CHANNEL_NAME[10] = {"UNKNOWN", "SHN", "SHE", "SHZ", "BHN", "BHE", "BHZ", "SBHN", "SBHE", "SBHZ"};
struct SIG_UNIT;
#ifdef GCTL_SEISMIC_MATHGL
class SIG_PLOT : public mglDraw
{
private:
SIG_UNIT *sig_ptr;
std::string file;
public:
SIG_PLOT();
virtual ~SIG_PLOT();
void link_source(SIG_UNIT *sig, std::string filename);
int Draw(mglGraph *gr);
};
#endif // GCTL_SEISMIC_MATHGL
struct SIG_UNIT
{
UTC_TIME t0 = UTC_START; // Signal reference time stamp that is referred to as the zero time
UTC_TIME te = UTC_START; // Signal end time
double rt0 = 0.0; // Signal start time w.r.t. the zero t0 stamp which is zero as well for the most times except for a result from the linear cross correlation
double delta = 1.0; // Signal delta (default is 1.0 s that is also 1.0 Hz)
array<double> val; // Signal values
#ifdef GCTL_SEISMIC_MATHGL
SIG_PLOT plt;
#endif // GCTL_SEISMIC_MATHGL
void init(int len, double init_val, double dt, UTC_TIME st = UTC_START, double rst = 0.0);
void info();
void save(std::string filename);
int cut_section(SIG_UNIT &sig, double cst, double cet) const;
int cut_section(SIG_UNIT &sig, const UTC_TIME &cst, double clen) const;
int cut_multiple_sections(time_unit roundup, double clen, array<SIG_UNIT> &sigs);
int down_sampling(int factor);
int resampling(double dt, time_unit roundup);
void remove_mean(int win_size = 0);
void remove_outliers(double factor);
void normalize(double norm = 1.0);
void normalize_1bit();
void spectral_whitening(int avg_num);
void filter(gctl::filting_type_e fi_type, gctl::filter_type_e fr_type, int order, double f1, double f2 = 0);
//void remove_trend();
void stack_sig_units(const array<SIG_UNIT*> &sigs);
void stack_sig_units(const array<SIG_UNIT> &sigs);
void stack_sig_units(const std::vector<SIG_UNIT> &sigs);
void merge_sig_units(const array<SIG_UNIT> &sigs);
void merge_sig_units(const std::vector<SIG_UNIT> &sigs);
void linear_cross_correlation(const SIG_UNIT &a, const SIG_UNIT &b);
void linear_cross_correlation_freq(const SIG_UNIT &a, const SIG_UNIT &b, int avg_num);
void circular_cross_correlation(const SIG_UNIT &a, const SIG_UNIT &b);
#ifdef GCTL_SEISMIC_MATHGL
int plot(std::string filename = "null");
#endif // GCTL_SEISMIC_MATHGL
};
}
#endif // _GCTL_SEISMIC_SIGNAL_H