-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsignal.h
146 lines (112 loc) · 3.84 KB
/
signal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <complex>
#include <numeric>
#include <cmath>
#include "consts.h"
#include "spline_interpolation.h"
#include <boost/numeric/odeint.hpp>
class Component {
public:
double freq;
size_t signal_size;
std::complex<double> ampl;
Component (): ampl(1.,0.) {}
Component(double freq, size_t signal_size): freq(freq), signal_size(signal_size), ampl(1.,0.) {}
~Component () {}
std::complex<double> operator[] (size_t t) const {
return (exp(2*pi*freq*t*imag));
}
size_t size() const {
return signal_size;
}
};
class ComponentVector {
public:
typedef std::vector<std::complex<double>> data_t;
std::complex<double> ampl;
std::vector<Component> cs;
ComponentVector():ampl(1,0) {}
ComponentVector(const Component &other): ampl(1.,0.) { cs.emplace_back(other);}
~ComponentVector() {}
size_t size() const{
return cs[0].size();
}
std::complex<double> operator[] (size_t t) const {
std::complex<double> res;
for (const auto & c: cs) {
res += ampl*c.ampl*c[t];
}
return res;
}
ComponentVector operator-=(const ComponentVector& other) {
if (size() != other.size() ) throw std::runtime_error("Inner product sizes not equal!");
for (auto i: other.cs) {
i.ampl*=-other.ampl;
cs.emplace_back(i);
}
return (*this);
}
};
class Signal {
public:
ComponentVector::data_t data;
Signal() {}
Signal(const std::vector<std::complex<double>> & v){
for (const auto i:v) data.emplace_back(i);
}
Signal(const Signal &) = default;
Signal& operator=(const Signal &) = default;
~Signal() {}
std::complex<double> operator[] (size_t t) const {
return data[t];
}
std::complex<double> operator[] (double t) const {
return spline(t, data);
}
std::complex<double> operator() (double t) const {
size_t a = (int)(t);
size_t b = (int)(t)+1;
return data[a]+(data[b]-data[a])*(t-a)/(1.0*(b-a));
}
size_t size() const{
return data.size();
}
Signal operator-=(const ComponentVector& other) {
if (size() != other.size() ) throw std::runtime_error("Inner product sizes not equal!");
for (size_t i = 0; i<size(); ++i) {
data[i] -= other[i];
data[i] -= std::conj(other[i]);
}
return *this;
}
};
class WindowFunc;
template <typename T1, typename T2>
std::complex<double> inner_product(const T1&, const T2&, const WindowFunc &, const bool&);
ComponentVector projection (const Component&, const ComponentVector &, const WindowFunc&, const bool&);
ComponentVector projection (const ComponentVector&, const ComponentVector&, const WindowFunc&, const bool&);
void signal_projection (const Signal&, ComponentVector&, const WindowFunc&, const bool&);
double cmp_RMS (const std::vector<double>&);
std::ostream& operator <<(std::ostream&, Signal);
std::ostream& operator <<(std::ostream& , ComponentVector);
std::ostream& operator <<(std::ostream&, Component);
void write_file (const std::string&, const std::vector<std::complex<double>>&, const double&, const double&, const double&) ;
void write_fft (const std::string&,const std::vector<double>&, const std::vector<double>&, const double&, const double&, const double&) ;
void write_file_merit (const std::string&, const std::function<double(double)>&, const double& , const double&, const double&);
size_t multiple_of_six(std::vector<double>&);
class Print_opt {
public:
enum {All = 0, Debug, Info};
static void Write(int level, std::string message);
static void SetLevel(int level);
protected:
static void Initialised();
static void Init();
private:
Print_opt();
static bool InitialisedM;
static int levelM;
};