// // Created by david on 04.03.2026. // #ifndef PASADASUPERPROJECT_SIGNAL_H #define PASADASUPERPROJECT_SIGNAL_H #include #include #include namespace pd_signal { using cplx = std::complex; /** `num` evenly spaced numbers over interval [start,stop] */ void linspace(std::vector& 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& data, double start, double stop, int num, bool endpoint); /** * Evaluate at points x the function given by the samples fp[xp[n]]. * Returned in y. */ void interp(std::vector& y, std::vector& x, std::vector& xp, std::vector& fp); /** resample to BEAT_LEN */ void resample(std::vector &out, std::vector &x, int beat_len); /** * normalized cross-correlation of the two signals of same length. * normalization factor is 1 / sqrt(\sum_i x_i^2 * \sum_i y_i^2) */ double crossCorr(std::vector &x, std::vector &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 &out, std::vector >& m); /** two-dimensional mean of a collection of signals */ void mean(std::vector &out, std::deque >& m); /** * Convolution of two polynomials given in ASCENDING power order. * If p = p_0 + p_1 x + ... + p_{P-1} x^{P-1} and likewise for q, * then out = p * q in ascending power order, of length P+Q-1. */ void polymul(std::vector& out, const std::vector& p, const std::vector& q); /** * Build a monic polynomial from its roots: * (x - r_0) (x - r_1) ... (x - r_{N-1}). * Returned in DESCENDING power order, i.e. out[0]=1, ..., out[N] * is the constant term. Length is roots.size() + 1. */ void poly(std::vector& out, const std::vector& 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& b, std::vector& a, int N, double fc, double fs); } #endif //PASADASUPERPROJECT_SIGNAL_H