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

Revision:
0:fa74b1130cc3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SignalProcessing/Biquad.hpp	Sun Jan 29 09:11:30 2017 +0000
@@ -0,0 +1,60 @@
+//--------------------------------------------------------------
+//  縦続形 IIR フィルタで使う 1D タイプの 2 次のフィルタ
+//  Biquad filter of 1D type for IIR filter of cascade structure
+//      このクラスでは,係数は実行中に書き換えられることを想定している
+//
+//      u[n] = x[n] + a1*u[n-1] + a2*u[n-2]
+//      y[n] = u[n] + b1*u[n-1] + b2*u[n-2]
+//          x[n] :  input signal
+//          y[n] :  output signal
+//          b0 = 1
+//
+// 2017/01/26, Copyright (c) 2017 MIKAMI, Naoki
+//--------------------------------------------------------------
+
+#ifndef IIR_BIQUAD_HPP
+#define IIR_BIQUAD_HPP
+
+#include "mbed.h"
+
+// 2nd order IIR filter
+namespace Mikami
+{
+    class Biquad
+    {
+    public:
+        struct Coefs { float a1, a2, b1, b2; };
+
+        Biquad(const Coefs ck = (Coefs){0, 0, 0, 0})
+        {
+            SetCoefs(ck);
+            Clear();
+        }
+        
+        void SetCoefs(const Coefs cf) { cf_ = cf; }
+        
+        void GetCoefs(Coefs &cf) { cf = cf_; }
+
+        float Execute(float xn)
+        {
+            float un = xn + cf_.a1*un1_ + cf_.a2*un2_;
+            float yn = un + cf_.b1*un1_ + cf_.b2*un2_;
+        
+            un2_ = un1_;
+            un1_ = un;
+
+            return yn;
+        }
+
+        void Clear() { un1_ = un2_ = 0; }
+
+    private:
+        Coefs cf_;
+        float un1_, un2_;
+
+        // disallow copy constructor and assignment operator
+        Biquad(const Biquad&);
+        Biquad& operator=(const Biquad&);
+    };
+}
+#endif  // IIR_BIQUAD_HPP