2nd try
Diff: IIR_filter.cpp
- Revision:
- 2:8706bb4e8f93
- Parent:
- 0:72b60c5271cc
diff -r dd5d116ace8f -r 8706bb4e8f93 IIR_filter.cpp --- a/IIR_filter.cpp Thu Mar 07 09:16:03 2019 +0000 +++ b/IIR_filter.cpp Fri Mar 08 13:34:39 2019 +0000 @@ -59,6 +59,30 @@ // dc-gain this->K = (double)K; } +void IIR_filter::setup(float T, float Ts, float K){ + + // filter orders + nb = 1; // Filter Order + na = 1; // Filter Order + + // filter coefficients + B = (double*)malloc((nb+1)*sizeof(double)); + A = (double*)malloc(na*sizeof(double)); + B[0] = (double)Ts/((double)Ts + 2.0*(double)T); + B[1] = B[0]; + A[0] = ((double)Ts - 2.0*(double)T)/((double)Ts + 2.0*(double)T); + + // signal arrays + uk = (double*)malloc((nb+1)*sizeof(double)); + yk = (double*)malloc(na*sizeof(double)); + uk[0]= uk[1] = 0.0; + yk[0] = 0.0; + + // dc-gain + this->K = (double)K; +} + + // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2) IIR_filter::IIR_filter(float w0, float D, float Ts, float K){ @@ -146,3 +170,7 @@ return (float)ret; } + + + +