Infinite impulse response filter

Fork of IIR by Project_WIPV_antiSlip

Revision:
1:3d8226c5abfe
Parent:
0:a7405ea45d27
Child:
2:0bae37b297f4
diff -r a7405ea45d27 -r 3d8226c5abfe IIR.h
--- a/IIR.h	Fri Jul 29 14:26:54 2016 +0000
+++ b/IIR.h	Fri Jul 29 14:55:33 2016 +0000
@@ -1,5 +1,17 @@
 #include <vector>
 using std::vector;
+/*-----------------------------*/
+//
+//    y     gain*( sum(i from 0 to m) b[i]*x[k-i] )
+//   --- = --------------------------------------------
+//    u     1 + sum( i from 1 to n) a[i]*y[k-i]
+//
+//   y[k] = gain*( sum(i from 0 to m) b[i]*x[k-i] ) - sum( i from 1 to n) a[i]*y[k-i]
+//   
+//   Compatible with the coefficient generated by Matlab fdatool 
+//
+//   by C.F. Huang from LDSC
+/*-----------------------------*/
 
 class Circular_buffer{
 private:
@@ -58,11 +70,16 @@
         y.Init(n);      
     }
     void Assign_parameters(float b_in[], float a_in[], float gain_in){
-        b.assign(b_in,b_in+m+1);
-        a.assign(a_in,a_in+n);
+        //b.assign(b_in,b_in+m+1);
+        // a.assign(a_in,a_in+n);
+        b.resize(m+1);
+        a.resize(n);
+        for (size_t i = 0; i < n; i++){
+            a[i] = a_in[i+1];
+        }
         gain = gain_in;
         for (size_t i = 0; i < b.size(); i++){
-            b[i] *= gain;
+            b[i] = gain*b_in[i];
         }
     }
     float Iterate_once(float x_in){