// // 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 times; std::vector 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