-
Notifications
You must be signed in to change notification settings - Fork 9
/
IIR_Filter.h
55 lines (42 loc) · 2.45 KB
/
IIR_Filter.h
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
53
54
55
#ifndef IIR_Filter_H_
#define IIR_Filter_H_
#include <math.h>
class IIR_Filter
{
public:
IIR_Filter(float T, float Ts); // G(s) = s/(T*s + 1)
IIR_Filter(float T, float Ts, float K); // G(s) = K/(T*s + 1)
IIR_Filter(float w0, float D, float Ts, float K); // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2)
IIR_Filter(float wz, float Dz, float wp, float Dp, float Ts, float K); // G(s) = K * wp^2/wz^2 * (s^2 + 2*Dz*wz*s + wz^2)/(s^2 + 2*Dp*wp*s + wp^2)
IIR_Filter(float k, float Tz, float Tp, float Ts, int typ); // G(s) = K * (Tz*s+1)/(Tp*s+1) Lead/Lag in bilinear trafo
IIR_Filter(float *b, float *a, int nb, int na); // G(z) = B(z) / A(z) = (b_0 + b_1*z^-1 + ... + b_nb*z^-nb) / (1 + a_1*z^-1 + ... + a_na*z^-na)
IIR_Filter(float *b, float *a, int nb, int na, float yMin, float yMax); // G(z) = B(z) / A(z) = (b_0 + b_1*z^-1 + ... + b_nb*z^-nb) / (1 + a_1*z^-1 + ... + a_na*z^-na)
IIR_Filter(){};
virtual ~IIR_Filter();
void setup(float T, float Ts); // G(s) = s/(T*s + 1)
void setup(float T, float Ts, float K); // G(s) = K/(T*s + 1)
void setup(float w0, float D, float Ts, float K); // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2)
void setup(float wz, float Dz, float wp, float Dp, float Ts, float K); // G(s) = K * wp^2/wz^2 * (s^2 + 2*Dz*wz*s + wz^2)/(s^2 + 2*Dp*wp*s + wp^2)
void setup(float k, float Tz, float Tp, float Ts, int typ); // G(s) = K * (Tz*s+1)/(Tp*s+1) Lead/Lag in bilinear trafo
void setup(float *b, float *a, int nb, int na); // G(z) = B(z) / A(z) = (b_0 + b_1*z^-1 + ... + b_nb*z^-nb) / (1 + a_1*z^-1 + ... + a_na*z^-na)
void setup(float *b, float *a, int nb, int na, float yMin, float yMax); // G(z) = B(z) / A(z) = (b_0 + b_1*z^-1 + ... + b_nb*z^-nb) / (1 + a_1*z^-1 + ... + a_na*z^-na)
void reset();
void reset(float u);
void reset(float u, float y);
void setLimits(float yMax = 1.0e6f);
void setLimits(float yMin, float yMax);
float filter(float u);
float get_output();
float prewarp(float T, float Ts);
// void print_filter_coeff();
float *B;
float *A;
unsigned nb, na;
private:
float *uk;
float *yk;
float K;
float yMin, yMax;
float saturate(float y, float yMin, float yMax);
};
#endif