A combination of some frequently used filters

Revision:
6:18dd3f9ac217
Parent:
5:2291a3ccc64a
Child:
7:10df955a92d9
--- a/FILTER_LIB.h	Wed Jan 11 09:27:58 2017 +0000
+++ b/FILTER_LIB.h	Fri Jan 20 15:49:04 2017 +0000
@@ -7,6 +7,7 @@
 #define FILTER_LIB_H
 //
 #include "IIR.h"
+#include <math.h>
 #include <vector>
 
 using std::vector;
@@ -36,8 +37,8 @@
     vector<float> output;
 
     LPF_vector(size_t dimension, float samplingTime, float cutOff_freq_Hz_in); // cutOff_freq_Hz_in is in "Hz"
-    vector<float> filter(const vector<float> &v_in);
-    void reset(const vector<float> &v_in);
+    vector<float> filter(const vector<float> &input);
+    void reset(const vector<float> &input);
 
 private:
     size_t n;
@@ -53,6 +54,53 @@
     vector<float> zeros; // Zero vector [0;0;0]
 };
 
+//--------------------LPF_nthOrderCritical---------------------//
+class LPF_nthOrderCritical{ // nth-order critical-damped Low-pass filter (all the poles are at the same place)
+public:
+    float output;
+
+    LPF_nthOrderCritical(float samplingTime, float cutOff_freq_Hz_in, size_t order_in); // cutOff_freq_Hz_in is in "Hz"
+    float filter(float input);
+    void reset(float input);
+
+private:
+    float Ts;
+    size_t order;
+    float cutOff_freq_Hz; // Hz
+
+    // Layers of 1st-order LPF
+    vector<LPF> filter_layers;
+
+    // Flag
+    bool Flag_Init;
+};
+
+//--------------------LPF_vector_nthOrderCritical---------------------//
+class LPF_vector_nthOrderCritical{ // Vectorized nth-order critical-damped Low-pass filter (all the poles are at the same place)
+public:
+    vector<float> output;
+
+    LPF_vector_nthOrderCritical(size_t dimension, float samplingTime, float cutOff_freq_Hz_in, size_t order_in); // cutOff_freq_Hz_in is in "Hz"
+    vector<float> filter(const vector<float> &input);
+    void reset(const vector<float> &input);
+
+private:
+    size_t n;
+    float Ts;
+    size_t order;
+
+    float cutOff_freq_Hz; // Hz
+
+    // Flag
+    bool Flag_Init;
+
+    // Layers of vectorized 1st-order LPF
+    vector<LPF_vector> filter_layers;
+
+    //
+    vector<float> zeros; // Zero vector [0;0;0]
+};
+
 
 //--------------------HPF---------------------//
 class HPF{ // High-pass filter
@@ -82,8 +130,8 @@
     vector<float> output;
 
     HPF_vector(size_t dimension, float samplingTime, float cutOff_freq_Hz_in); // cutOff_freq_Hz_in is in "Hz"
-    vector<float> filter(const vector<float> &v_in);
-    void reset(const vector<float> &v_in);
+    vector<float> filter(const vector<float> &input);
+    void reset(const vector<float> &input);
 
 private:
     size_t n;
@@ -99,6 +147,80 @@
     LPF_vector lpf_v;
 };
 
+//--------------------HPF_nthOrderCritical---------------------//
+class HPF_nthOrderCritical{ // nth-order critical-damped High-pass filter (all the poles are at the same place)
+public:
+    float output;
+
+    HPF_nthOrderCritical(float samplingTime, float cutOff_freq_Hz_in, size_t order_in); // cutOff_freq_Hz_in is in "Hz"
+    float filter(float input);
+    void reset(float input);
+
+private:
+    float Ts;
+    size_t order;
+    float cutOff_freq_Hz; // Hz
+
+    // Layers of 1st-order HPF
+    vector<HPF> filter_layers;
+
+    // Flag
+    bool Flag_Init;
+};
+
+
+//--------------------HPF_vector_nthOrderCritical---------------------//
+class HPF_vector_nthOrderCritical{ // Vectorized nth-order critical-damped High-pass filter (all the poles are at the same place)
+public:
+    vector<float> output;
+
+    HPF_vector_nthOrderCritical(size_t dimension, float samplingTime, float cutOff_freq_Hz_in, size_t order_in); // cutOff_freq_Hz_in is in "Hz"
+    vector<float> filter(const vector<float> &input);
+    void reset(const vector<float> &input);
+
+private:
+    size_t n;
+    float Ts;
+    size_t order;
+
+    float cutOff_freq_Hz; // Hz
+
+    // Flag
+    bool Flag_Init;
+
+    // Layers of vectorized 1st-order LPF
+    vector<HPF_vector> filter_layers;
+
+    //
+    vector<float> zeros; // Zero vector [0;0;0]
+};
+
+//--------------------HPF_vector_1minusLPF_nthOrderCritical---------------------//
+class HPF_vector_1minusLPF_nthOrderCritical{ // Vectorized nth-order critical-damped High-pass filter ( the version of (1 - nth-order LPF), all the poles are at the same place)
+public:
+    vector<float> output;
+
+    HPF_vector_1minusLPF_nthOrderCritical(size_t dimension, float samplingTime, float cutOff_freq_Hz_in, size_t order_in); // cutOff_freq_Hz_in is in "Hz"
+    vector<float> filter(const vector<float> &input);
+    void reset(const vector<float> &input);
+
+private:
+    size_t n;
+    float Ts;
+    size_t order;
+
+    float cutOff_freq_Hz; // Hz
+
+    // Flag
+    bool Flag_Init;
+
+    // Layers of vectorized 1st-order LPF
+    vector<LPF_vector> filter_layers;
+
+    //
+    vector<float> zeros; // Zero vector [0;0;0]
+};
+
 
 //--------------------Derivative_appr---------------------//
 class Derivative_appr{ // Approximated Derivative, cut-off at 10% of sampling frequency