Demo program of digital signal processing: Variable LPF/HPF, Vocal canceller, Pitch shifter, Reverbrator. ディジタル信号処理のデモプログラム. 遮断周波数可変 LPF/HPF,ボーカルキャンセラ,ピッチシフタ,残響生成器.

Dependencies:   Array_Matrix F446_AD_DA UIT_AQM1602 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Biquad.hpp Source File

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 // 2017/01/26, Copyright (c) 2017 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(const Coefs ck = (Coefs){0, 0, 0, 0})
00029         {
00030             SetCoefs(ck);
00031             Clear();
00032         }
00033         
00034         void SetCoefs(const Coefs cf) { cf_ = cf; }
00035         
00036         void GetCoefs(Coefs &cf) { cf = cf_; }
00037 
00038         float Execute(float xn)
00039         {
00040             float un = xn + cf_.a1*un1_ + cf_.a2*un2_;
00041             float yn = un + cf_.b1*un1_ + cf_.b2*un2_;
00042         
00043             un2_ = un1_;
00044             un1_ = un;
00045 
00046             return yn;
00047         }
00048 
00049         void Clear() { un1_ = un2_ = 0; }
00050 
00051     private:
00052         Coefs cf_;
00053         float un1_, un2_;
00054 
00055         // disallow copy constructor and assignment operator
00056         Biquad(const Biquad&);
00057         Biquad& operator=(const Biquad&);
00058     };
00059 }
00060 #endif  // IIR_BIQUAD_HPP