1次遅れと2次遅れ,ノッチフィルターを実装

Fork of Filter by Yuki Ueno

Revision:
3:987d5d78f863
Parent:
2:a842c1a33e4f
Child:
4:fc9412c8334e
--- a/Filter.cpp	Thu Jan 11 07:00:44 2018 +0000
+++ b/Filter.cpp	Sat Jan 13 17:05:58 2018 +0000
@@ -3,22 +3,26 @@
 Filter::Filter(double xint_time)
 {
     int_time = xint_time;
+    preOutput = 0;
+    set_t = false;
 }
 
 void Filter::setLowPassPara(double T)
 {
     T_LPF = T;
+    set_t = true;
 }
 
 double Filter::LowPassFilter(double input)
 {
-    static double preOutput = 0.0;
-
-    double Output = (int_time * input + T_LPF * preOutput)/(T_LPF + int_time);
-
-    preOutput = Output;
-
-    return Output;
+    //static double preOutput = input;
+    if(!set_t) {
+        return input;
+    } else {
+        double Output = (int_time * input + T_LPF * preOutput)/(T_LPF + int_time);
+        preOutput = Output;
+        return Output;
+    }
 }
 
 void Filter::setNotchPara(double Omega)
@@ -34,14 +38,14 @@
 {
     static double preOutput[2] = {0.0, 0.0};
     static double preInput[2] = {0.0, 0.0};
-    
+
     double Output = (2*(1 + Om_n * int_time) * preOutput[0]-preOutput[1] + (1 + sq_Om * sq_dt) * input -2 * preInput[0] + preInput[1]) / (1 + 2 * Om_n * int_time + sq_Om * sq_dt);
-    
+
     preInput[1] = preInput[0];
     preInput[0] = input;
-    
+
     preOutput[1] = preOutput[0];
     preOutput[0] = Output;
-    
+
     return Output;
 }
\ No newline at end of file