Libary for control.

Dependencies:   FastPWM

Dependents:   RT2_Cuboid

Committer:
pmic
Date:
Thu May 05 09:18:40 2022 +0000
Revision:
10:eb29810d831b
Parent:
8:3a2131231969
Adjusted AvgFilter (damn...)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmic 6:e93f67d98616 1 #ifndef IIR_FILTER_H_
pmic 6:e93f67d98616 2 #define IIR_FILTER_H_
pmic 4:1cbd6af9836c 3
pmic 8:3a2131231969 4 #include <mbed.h>
pmic 4:1cbd6af9836c 5
pmic 6:e93f67d98616 6 class IIR_filter
pmic 4:1cbd6af9836c 7 {
pmic 4:1cbd6af9836c 8
pmic 4:1cbd6af9836c 9 public:
pmic 4:1cbd6af9836c 10
pmic 6:e93f67d98616 11 IIR_filter(float T, float Ts); // G(s) = s/(T*s + 1)
pmic 6:e93f67d98616 12 IIR_filter(float T, float Ts, float K); // G(s) = K/(T*s + 1)
pmic 6:e93f67d98616 13 IIR_filter(float w0, float D, float Ts, float K); // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2)
pmic 6:e93f67d98616 14 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)
pmic 6:e93f67d98616 15 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)
pmic 4:1cbd6af9836c 16
pmic 6:e93f67d98616 17 IIR_filter() {};
pmic 4:1cbd6af9836c 18
pmic 6:e93f67d98616 19 virtual ~IIR_filter();
pmic 4:1cbd6af9836c 20
pmic 4:1cbd6af9836c 21 void setup(float T, float Ts); // G(s) = s/(T*s + 1)
pmic 4:1cbd6af9836c 22 void setup(float T, float Ts, float K); // G(s) = K/(T*s + 1)
pmic 4:1cbd6af9836c 23 void setup(float w0, float D, float Ts, float K); // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2)
pmic 4:1cbd6af9836c 24 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)
pmic 4:1cbd6af9836c 25 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)
pmic 4:1cbd6af9836c 26
pmic 6:e93f67d98616 27 void reset();
pmic 4:1cbd6af9836c 28 void reset(float u);
pmic 4:1cbd6af9836c 29 void reset(float u, float y);
pmic 4:1cbd6af9836c 30
pmic 4:1cbd6af9836c 31 void set_limits(float yMax);
pmic 4:1cbd6af9836c 32 void set_limits(float yMin, float yMax);
pmic 4:1cbd6af9836c 33
pmic 4:1cbd6af9836c 34 float filter(float u);
pmic 4:1cbd6af9836c 35
pmic 4:1cbd6af9836c 36 float get_output();
pmic 4:1cbd6af9836c 37
pmic 4:1cbd6af9836c 38 float operator()(float u)
pmic 4:1cbd6af9836c 39 {
pmic 4:1cbd6af9836c 40 return filter(u);
pmic 4:1cbd6af9836c 41 }
pmic 4:1cbd6af9836c 42
pmic 6:e93f67d98616 43 float prewarp(float T, float Ts);
pmic 6:e93f67d98616 44
pmic 6:e93f67d98616 45 void print_filter_coeff();
pmic 4:1cbd6af9836c 46
pmic 4:1cbd6af9836c 47 private:
pmic 4:1cbd6af9836c 48
pmic 4:1cbd6af9836c 49 uint8_t nb, na;
pmic 4:1cbd6af9836c 50 float *B;
pmic 4:1cbd6af9836c 51 float *A;
pmic 4:1cbd6af9836c 52 float *uk;
pmic 4:1cbd6af9836c 53 float *yk;
pmic 4:1cbd6af9836c 54 float K;
pmic 4:1cbd6af9836c 55 float yMin, yMax;
pmic 4:1cbd6af9836c 56
pmic 4:1cbd6af9836c 57 float saturate(float y, float yMin, float yMax);
pmic 4:1cbd6af9836c 58
pmic 4:1cbd6af9836c 59 };
pmic 4:1cbd6af9836c 60 #endif