32uword
gcd(uword, uword);
46template<WindowType T> vec
fir_low_pass(uword,
double) {
throw invalid_argument(
"unknown window type"); }
48template<> vec fir_low_pass<WindowType::Hamming>(uword,
double);
50template<> vec fir_low_pass<WindowType::Hann>(uword,
double);
52template<> vec fir_low_pass<WindowType::Blackman>(uword,
double);
54template<> vec fir_low_pass<WindowType::BlackmanNuttall>(uword,
double);
56template<> vec fir_low_pass<WindowType::BlackmanHarris>(uword,
double);
58template<> vec fir_low_pass<WindowType::FlatTop>(uword,
double);
60template<WindowType T> vec
fir_high_pass(uword,
double) {
throw invalid_argument(
"unknown window type"); }
62template<> vec fir_high_pass<WindowType::Hamming>(uword,
double);
64template<> vec fir_high_pass<WindowType::Hann>(uword,
double);
66template<> vec fir_high_pass<WindowType::Blackman>(uword,
double);
68template<> vec fir_high_pass<WindowType::BlackmanNuttall>(uword,
double);
70template<> vec fir_high_pass<WindowType::BlackmanHarris>(uword,
double);
72template<> vec fir_high_pass<WindowType::FlatTop>(uword,
double);
74template<WindowType T> vec
fir_band_pass(uword,
double,
double) {
throw invalid_argument(
"unknown window type"); }
76template<> vec fir_band_pass<WindowType::Hamming>(uword,
double,
double);
78template<> vec fir_band_pass<WindowType::Hann>(uword,
double,
double);
80template<> vec fir_band_pass<WindowType::Blackman>(uword,
double,
double);
82template<> vec fir_band_pass<WindowType::BlackmanNuttall>(uword,
double,
double);
84template<> vec fir_band_pass<WindowType::BlackmanHarris>(uword,
double,
double);
86template<> vec fir_band_pass<WindowType::FlatTop>(uword,
double,
double);
88template<WindowType T> vec
fir_band_stop(uword,
double,
double) {
throw invalid_argument(
"unknown window type"); }
90template<> vec fir_band_stop<WindowType::Hamming>(uword,
double,
double);
92template<> vec fir_band_stop<WindowType::Hann>(uword,
double,
double);
94template<> vec fir_band_stop<WindowType::Blackman>(uword,
double,
double);
96template<> vec fir_band_stop<WindowType::BlackmanNuttall>(uword,
double,
double);
98template<> vec fir_band_stop<WindowType::BlackmanHarris>(uword,
double,
double);
100template<> vec fir_band_stop<WindowType::FlatTop>(uword,
double,
double);
102template<WindowType T> vec
upsampling(
const vec& in,
const uword up_rate,
const uword window_size) {
103 const vec coef =
static_cast<double>(up_rate) * fir_low_pass<T>(window_size * up_rate, 1. /
static_cast<double>(up_rate));
105 vec out(up_rate * in.n_elem, fill::zeros);
107 for(
auto I = 0llu, J = 0llu; I < in.n_elem; ++I, J += up_rate) out(J) = in(I);
109 return conv(out, coef,
"same");
112template<WindowType T> mat
upsampling(
const string& file_name,
const uword up_rate,
const uword window_size) {
114 if(std::error_code code; !fs::exists(file_name, code) || !ext_data.load(file_name, raw_ascii) || ext_data.empty() || ext_data.n_cols < 2) {
119 const vec time_diff = diff(ext_data.col(0));
126 const auto upsampled_data = upsampling<T>(ext_data.col(1), up_rate, window_size);
128 mat result(upsampled_data.n_elem, 2, fill::none);
130 result.col(1) = upsampled_data;
132 const auto time_size = mean(time_diff) /
static_cast<double>(up_rate);
134 for(
auto I = 0llu; I < result.n_rows; ++I) result(I, 0) =
static_cast<double>(I) * time_size;
139mat
upsampling(
const string&,
const string&, uword, uword = 8llu);
std::enable_if_t<!std::numeric_limits< T >::is_integer, bool > approx_equal(T x, T y, int ulp=2)
Definition: utility.h:60
vec hann(uword)
Definition: resampling.cpp:46
vec blackman_harris(uword)
Definition: resampling.cpp:52
WindowType
Definition: resampling.h:23
vec upsampling(const vec &in, const uword up_rate, const uword window_size)
Definition: resampling.h:102
uword gcd(uword, uword)
Definition: resampling.cpp:20
vec fir_low_pass(uword, double, vec(*)(uword))
Definition: resampling.cpp:56
vec hamming(uword)
Definition: resampling.cpp:44
vec fir_band_pass(uword, double, double, vec(*)(uword))
Definition: resampling.cpp:89
vec blackman_nuttall(uword)
Definition: resampling.cpp:50
vec fir_band_stop(uword, double, double, vec(*)(uword))
Definition: resampling.cpp:110
vec fir_high_pass(uword, double, vec(*)(uword))
Definition: resampling.cpp:68
vec blackman(uword)
Definition: resampling.cpp:48
vec flat_top(uword)
Definition: resampling.cpp:54