Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Biquad.hpp
00001 //-------------------------------------------------------------- 00002 // 縦続形 IIR フィルタで使う 1D タイプの 2 次のフィルタ 00003 // Biquad filter of 1D type for IIR filter of cascade structure 00004 // このクラスでは,係数は実行中に書き換えられることを想定している 00005 // 00006 // u[n] = x[n] + a1*u[n-1] + a2*u[n-2] 00007 // y[n] = u[n] + b1*u[n-1] + b2*u[n-2] 00008 // x[n] : input signal 00009 // y[n] : output signal 00010 // b0 = 1 00011 // 00012 // 2016/03/25, Copyright (c) 2016 MIKAMI, Naoki 00013 //-------------------------------------------------------------- 00014 00015 #ifndef IIR_BIQUAD_HPP 00016 #define IIR_BIQUAD_HPP 00017 00018 #include "mbed.h" 00019 00020 // 2nd order IIR filter 00021 namespace Mikami 00022 { 00023 class Biquad 00024 { 00025 public: 00026 struct Coefs { float a1, a2, b1, b2; }; 00027 00028 Biquad() {} // Default constructore 00029 00030 Biquad(const Coefs ck) 00031 { 00032 SetCoefficients(ck); 00033 Clear(); 00034 } 00035 00036 void SetCoefficients(const Coefs ck) 00037 { 00038 a1_ = ck.a1; 00039 a2_ = ck.a2; 00040 b1_ = ck.b1; 00041 b2_ = ck.b2; 00042 } 00043 00044 float Execute(float xn) 00045 { 00046 float un = xn + a1_*un1_ + a2_*un2_; 00047 float yn = un + b1_*un1_ + b2_*un2_; 00048 00049 un2_ = un1_; 00050 un1_ = un; 00051 00052 return yn; 00053 } 00054 00055 void Clear() { un1_ = un2_ = 0; } 00056 00057 private: 00058 float a1_, a2_, b1_, b2_; 00059 float un1_, un2_; 00060 00061 // disallow copy constructor 00062 Biquad(const Biquad&); 00063 }; 00064 } 00065 #endif // IIR_BIQUAD_HPP
Generated on Fri Aug 5 2022 02:03:47 by
1.7.2