feat: Resampler: Normalizes incoming Android sensor sampling rate
This commit is contained in:
51
pasada-lib/include/pd_resamp.h
Normal file
51
pasada-lib/include/pd_resamp.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by david on 17.05.2026.
|
||||
//
|
||||
|
||||
#ifndef PASADASUPERPROJECT_PD_RESAMP_H
|
||||
#define PASADASUPERPROJECT_PD_RESAMP_H
|
||||
|
||||
#include "iir_filter.h"
|
||||
|
||||
/** Filter that changes sampling rate between input and output. */
|
||||
class ResamplingFilter {
|
||||
public:
|
||||
ResamplingFilter() {}
|
||||
virtual ~ResamplingFilter() {}
|
||||
virtual void push(double ts, double val) = 0;
|
||||
virtual bool peek() = 0;
|
||||
virtual double get() = 0;
|
||||
};
|
||||
|
||||
/** Normalizes incoming Android sensor sampling rate. */
|
||||
class Resampler : public ResamplingFilter {
|
||||
protected:
|
||||
const size_t INITIAL_SAMPLES = 100;
|
||||
std::vector<double> times;
|
||||
std::vector<double> data;
|
||||
/** circular buffer size */
|
||||
size_t N;
|
||||
/** write index */
|
||||
size_t n;
|
||||
/** read index */
|
||||
size_t m;
|
||||
bool initialized;
|
||||
bool read_valid;
|
||||
/** computed sampling frequency, this will be the output rate */
|
||||
double fs;
|
||||
void compute_fs();
|
||||
public:
|
||||
Resampler();
|
||||
/**
|
||||
* Push a value into the buffer.
|
||||
* Caller is responsible for polling via peek() and get() afterward.
|
||||
* @param ts timestamp in nanoseconds
|
||||
* @param val signal sample
|
||||
*/
|
||||
void push(double ts, double val) override;
|
||||
bool peek() override;
|
||||
double get() override;
|
||||
double get_fs() const;
|
||||
};
|
||||
|
||||
#endif //PASADASUPERPROJECT_PD_RESAMP_H
|
||||
@@ -40,6 +40,10 @@ namespace pd_signal {
|
||||
/** two-dimensional mean of a collection of signals */
|
||||
void mean(std::vector<double> &out, std::deque<std::vector<double> >& m);
|
||||
|
||||
/** simple mean of 1-d signal */
|
||||
double mean(const std::vector<double>& in);
|
||||
void diff(std::vector<double>& out, const std::vector<double>& in);
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
||||
Reference in New Issue
Block a user