revised version of F746_SD_GraphicEqualizer

Dependencies:   BSP_DISCO_F746NG F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed

Fork of F746_SD_GraphicEqualizer by 不韋 呂

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BiquadGrEq.hpp Source File

BiquadGrEq.hpp

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 
00014 #ifndef IIR_BIQUAD_HPP
00015 #define IIR_BIQUAD_HPP
00016 
00017 #include "mbed.h"
00018 
00019 // 2nd order IIR filter
00020 namespace Mikami
00021 {
00022     class BiquadGrEq
00023     {
00024     public:
00025         struct Coefs { float a1, a2, b0, b1, b2; };
00026 
00027         BiquadGrEq() {}     // Default constructore
00028 
00029         BiquadGrEq(const Coefs ck)
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
00062         BiquadGrEq(const BiquadGrEq&);
00063     };
00064 }
00065 #endif  // IIR_BIQUAD_HPP
00066