1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#pragma once
#include "libvideostitch/status.hpp"
namespace VideoStitch {
namespace Stab {
class IIRFilter {
public:
IIRFilter();
/**
* @brief init biquad parameters
* @param cutoffFreq : cutoff frequency
* @param sampleRate : sampling rate
*/
Status initLowPass(unsigned int cutoffFreq, unsigned int sampleRate);
/**
* @brief init biquad parameters given a ratio of Nyquist frequency
* @param ratioNyquist : between 0 and 1
*/
Status initLowPass(double ratioNyquist);
/**
* @brief Compute the next filtered value
* @param inputVal : input value
* @return output value
*
* This function uses the state (x1, x2, y1, y2) of the object to
* compute the next value. It also updates this state during the process
*
* see: http://www.earlevel.com/main/2003/02/28/biquads/
*
*/
double filterValue(double inputVal);
private:
void initLowPassHelper(double K);
double a0, a1, a2, b1, b2;
double x1; /// order 1 delayed input
double x2; /// order 2 delayed input
double y1; /// order 1 delayed output
double y2; /// order 2 delayed output
};
} // namespace Stab
} // namespace VideoStitch