![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cutoff frequency variable LPF by IIR 6th-order Butterworth filter for ST Nucleo F401RE.
Dependencies: UIT_IIR_Filter UIT_ACM1602NI UITDSP_ADDA mbed UIT_AQM1602
Diff: Biquad.hpp
- Revision:
- 0:a9412b9e85b7
diff -r 000000000000 -r a9412b9e85b7 Biquad.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Biquad.hpp Thu Oct 23 06:44:40 2014 +0000 @@ -0,0 +1,44 @@ +//-------------------------------------------------------------- +// Biquad filter for IIR filter of cascade structure +// 2014/10/21, Copyright (c) 2014 MIKAMI, Naoki +//-------------------------------------------------------------- + +#ifndef IIR_BIQUAD_HPP +#define IIR_BIQUAD_HPP + +#include "mbed.h" + +// 2nd order IIR filter +class Biquad +{ +public: + struct Coefs { float a1, a2, b1, b2; }; + + Biquad() {} // Default constructore + + Biquad(const Coefs ck) + : a1_(ck.a1), a2_(ck.a2), b1_(ck.b1), b2_(ck.b2) + { Clear(); } + + float Execute(float xn) + { + float un = xn + a1_*un1_ + a2_*un2_; + float yn = un + b1_*un1_ + b2_*un2_; + + un2_ = un1_; + un1_ = un; + + return yn; + } + + void Clear() { un1_ = un2_ = 0; } + +private: + float a1_, a2_, b1_, b2_; + float un1_, un2_; + + Biquad(const Biquad&); +}; + +#endif // IIR_BIQUAD_HPP +