Test program with the RT black boxes

Revision:
10:a28f393c6716
Parent:
5:d6c7ccbbce78
Child:
12:6287235b2570
```diff -r 30ee1d386a1d -r a28f393c6716 IIR_filter.cpp
--- a/IIR_filter.cpp	Thu Mar 22 17:34:18 2018 +0000
+++ b/IIR_filter.cpp	Wed Apr 04 14:18:43 2018 +0000
@@ -7,6 +7,7 @@
init for: first order differentiatior:   G(s) = s/(T*s + 1)
first order lowpass with gain  G(s) = K/(T*s + 1)
second order lowpass with gain G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0*w0)
+            nth order, with arbitrary values
the billinear transformation is used for s -> z
reseting the filter only makes sence for static signals, whatch out if you're using the differnetiator
*/
@@ -87,6 +88,32 @@
// dc-gain
this->K = K;
}
+
+IIR_filter::IIR_filter(float *b,float *a,int nb_, int na_){
+
+    // filter orders
+    this->nb = nb_-1;    // Filter Order
+    this->na = na_;      // Filter Order
+
+    // filter coefficients
+    B = (float*)malloc((nb+1)*sizeof(float));
+    A = (float*)malloc(na*sizeof(float));
+    uk = (float*)malloc((nb+1)*sizeof(float));
+    yk = (float*)malloc(na*sizeof(float));
+
+    for(int k=0;k<=nb;k++){
+        B[k]=b[k];
+        uk[k]=0.0f;
+        }
+    for(int k=0;k<na;k++){
+        A[k] = a[k];
+        yk[k] = 0.0f;
+        }
+
+    // dc-gain
+    this->K = 1.0f;
+}
+

IIR_filter::~IIR_filter() {}

@@ -118,22 +145,3 @@
yk[0] = ret;
return ret;
}
-
-// (B[0] + B[1]*z^-1 + ... + B[nb]*z^-nb)*U(z) = (1 + A[0]*z^-1 + ... + A[na-1]*z^-na))*Y(z)
-/*
-IIR_filter::IIR_filter(float *a[], float *b[], float K){
-
-    this->A = A[0];
-    this->B = B[0];
-    nb = sizeof(B)/sizeof(B[0]);
-    na = sizeof(A)/sizeof(A[0]);
-    uk = (float*)malloc((nb+1)*sizeof(float));
-    yk = (float*)malloc(na*sizeof(float));
-    for(int ii=0; ii<nb; ii++){
-        uk[ii] = 0.0f;
-    }
-    for(int ii=0; ii<na; ii++){
-        yk[ii] = 0.0f;
-    }
-    this->K = K;       %%% THIS IMPLEMENTATION SUITS NOT THE RESET PROCESS %%%
-}*/
\ No newline at end of file
```