2026-03-04 15:34:46 +01:00
|
|
|
//
|
|
|
|
|
// Created by david on 04.03.2026.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef PASADASUPERPROJECT_SIGNAL_H
|
|
|
|
|
#define PASADASUPERPROJECT_SIGNAL_H
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
2026-03-11 20:47:53 +01:00
|
|
|
#include <deque>
|
2026-05-10 13:04:23 +02:00
|
|
|
#include <complex>
|
2026-03-04 15:34:46 +01:00
|
|
|
|
|
|
|
|
namespace pd_signal {
|
2026-05-10 13:04:23 +02:00
|
|
|
using cplx = std::complex<double>;
|
|
|
|
|
|
2026-03-04 16:27:00 +01:00
|
|
|
/** `num` evenly spaced numbers over interval [start,stop] */
|
|
|
|
|
void linspace(std::vector<double>& data, double start, double stop, int num);
|
|
|
|
|
/** `num` evenly spaced numbers over interval [start,stop] with endpoint=true or [start,stop) with endpoint=false */
|
|
|
|
|
void linspace(std::vector<double>& data, double start, double stop, int num, bool endpoint);
|
|
|
|
|
|
2026-03-04 15:34:46 +01:00
|
|
|
/**
|
|
|
|
|
* Evaluate at points x the function given by the samples fp[xp[n]].
|
|
|
|
|
* Returned in y.
|
|
|
|
|
*/
|
2026-03-04 16:27:00 +01:00
|
|
|
void interp(std::vector<double>& y, std::vector<double>& x, std::vector<double>& xp, std::vector<double>& fp);
|
|
|
|
|
|
|
|
|
|
/** resample to BEAT_LEN */
|
2026-03-09 18:38:21 +01:00
|
|
|
void resample(std::vector<double> &out, std::vector<double> &x, int beat_len);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* normalized cross-correlation of the two signals of same length.
|
|
|
|
|
* normalization factor is <c>1 / sqrt(\sum_i x_i^2 * \sum_i y_i^2)</c>
|
|
|
|
|
*/
|
|
|
|
|
double crossCorr(std::vector<double> &x, std::vector<double> &y);
|
|
|
|
|
|
|
|
|
|
/** clip 'val' to between 'a_min' and 'a_max'. */
|
|
|
|
|
double clip(double val, double a_min, double a_max);
|
|
|
|
|
|
|
|
|
|
/** two-dimensional mean of a collection of signals */
|
|
|
|
|
void mean(std::vector<double> &out, std::vector<std::vector<double> >& m);
|
2026-03-11 20:47:53 +01:00
|
|
|
/** two-dimensional mean of a collection of signals */
|
|
|
|
|
void mean(std::vector<double> &out, std::deque<std::vector<double> >& m);
|
2026-03-04 16:27:00 +01:00
|
|
|
|
2026-05-19 21:57:27 +02:00
|
|
|
/** simple mean of 1-d signal */
|
|
|
|
|
double mean(const std::vector<double>& in);
|
|
|
|
|
void diff(std::vector<double>& out, const std::vector<double>& in);
|
|
|
|
|
|
2026-05-20 00:10:37 +02:00
|
|
|
std::vector<double> gauss(size_t N, double mu, double sigma);
|
|
|
|
|
|
2026-05-10 13:04:23 +02:00
|
|
|
/**
|
|
|
|
|
* Convolution of two polynomials given in ASCENDING power order.
|
|
|
|
|
* If <c>p = p_0 + p_1 x + ... + p_{P-1} x^{P-1}</c> and likewise for q,
|
|
|
|
|
* then <c>out = p * q</c> in ascending power order, of length P+Q-1.
|
|
|
|
|
*/
|
|
|
|
|
void polymul(std::vector<cplx>& out,
|
|
|
|
|
const std::vector<cplx>& p, const std::vector<cplx>& q);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build a monic polynomial from its roots:
|
|
|
|
|
* <c>(x - r_0) (x - r_1) ... (x - r_{N-1})</c>.
|
|
|
|
|
* Returned in DESCENDING power order, i.e. <c>out[0]=1, ..., out[N]</c>
|
|
|
|
|
* is the constant term. Length is <c>roots.size() + 1</c>.
|
|
|
|
|
*/
|
|
|
|
|
void poly(std::vector<cplx>& out, const std::vector<cplx>& roots);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Design an N-th order Butterworth IIR high-pass digital filter via the
|
|
|
|
|
* bilinear transform. The passband is normalized to unit gain at Nyquist.
|
|
|
|
|
*
|
|
|
|
|
* @param b numerator coefficients in DESCENDING powers of z (length N+1)
|
|
|
|
|
* @param a denominator coefficients in DESCENDING powers of z (length N+1)
|
|
|
|
|
* @param N filter order (>= 1)
|
|
|
|
|
* @param fc cutoff frequency of the digital filter in Hz (0 < fc < fs/2)
|
|
|
|
|
* @param fs sampling frequency in Hz
|
|
|
|
|
*/
|
|
|
|
|
void iirHighpass(std::vector<double>& b, std::vector<double>& a,
|
|
|
|
|
int N, double fc, double fs);
|
2026-03-04 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif //PASADASUPERPROJECT_SIGNAL_H
|