revised version of F746_SD_GraphicEqualizer

Fork of F746_SD_GraphicEqualizer by

Embed: (wiki syntax)

« Back to documentation index

00001 //--------------------------------------------------------------
00002 //  グラフィックイコライザで使う 1D タイプの 2 次のフィルタ
00003 //  Biquad filter of 1D type for graphic equalizer
00004 //      このクラスでは，係数は実行中に書き換えられることを想定している
00005 //
00006 //      u[n] = x[n] + a1*u[n-1] + a2*u[n-2]
00007 //      y[n] = b0*u[n] + b1*u[n-1] + b2*u[n-2]
00008 //          x[n] :  input signal
00009 //          y[n] :  output signal
00010 //
00011 // 2016/03/25, Copyright (c) 2016 MIKAMI, Naoki
00012 //--------------------------------------------------------------
00013
00016
00017 #include "mbed.h"
00018
00019 // 2nd order IIR filter
00020 namespace Mikami
00021 {
00023     {
00024     public:
00025         struct Coefs { float a1, a2, b0, b1, b2; };
00026
00027         BiquadGrEq() {}     // Default constructore
00028
00030         {
00031             SetCoefficients(ck);
00032             Clear();
00033         }
00034
00035         void SetCoefficients(const Coefs ck)
00036         {
00037             a1_ = ck.a1;
00038             a2_ = ck.a2;
00039             b0_ = ck.b0;
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 = b0_*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_, b0_, b1_, b2_;
00059         float un1_, un2_;
00060
00061         // disallow copy constructor