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
SignalProcessing/IIR_Cascade.hpp@0:fa74b1130cc3, 2017-01-29 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Jan 29 09:11:30 2017 +0000
- Revision:
- 0:fa74b1130cc3
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:fa74b1130cc3 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:fa74b1130cc3 | 2 | // IIR filter ---- Cascade structure |
MikamiUitOpen | 0:fa74b1130cc3 | 3 | |
MikamiUitOpen | 0:fa74b1130cc3 | 4 | // 2017/01/26, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:fa74b1130cc3 | 5 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:fa74b1130cc3 | 6 | |
MikamiUitOpen | 0:fa74b1130cc3 | 7 | #ifndef IIR_CASCADE_HPP |
MikamiUitOpen | 0:fa74b1130cc3 | 8 | #define IIR_CASCADE_HPP |
MikamiUitOpen | 0:fa74b1130cc3 | 9 | |
MikamiUitOpen | 0:fa74b1130cc3 | 10 | #include "mbed.h" |
MikamiUitOpen | 0:fa74b1130cc3 | 11 | #include "Biquad.hpp" |
MikamiUitOpen | 0:fa74b1130cc3 | 12 | #include "Array.hpp" |
MikamiUitOpen | 0:fa74b1130cc3 | 13 | using namespace Mikami; |
MikamiUitOpen | 0:fa74b1130cc3 | 14 | |
MikamiUitOpen | 0:fa74b1130cc3 | 15 | namespace Mikami |
MikamiUitOpen | 0:fa74b1130cc3 | 16 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 17 | // IIR filter -- Cascade structure |
MikamiUitOpen | 0:fa74b1130cc3 | 18 | class IirCascade |
MikamiUitOpen | 0:fa74b1130cc3 | 19 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 20 | public: |
MikamiUitOpen | 0:fa74b1130cc3 | 21 | IirCascade(int order, float g0 = 1, |
MikamiUitOpen | 0:fa74b1130cc3 | 22 | const Biquad::Coefs ck[] = NULL) |
MikamiUitOpen | 0:fa74b1130cc3 | 23 | : ORDER2_(order/2), hk_(order/2) |
MikamiUitOpen | 0:fa74b1130cc3 | 24 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 25 | if (ck != NULL) SetCoefs(g0, ck); |
MikamiUitOpen | 0:fa74b1130cc3 | 26 | else g0_ = g0; |
MikamiUitOpen | 0:fa74b1130cc3 | 27 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 28 | |
MikamiUitOpen | 0:fa74b1130cc3 | 29 | void SetCoefs(float g0, const Biquad::Coefs ck[]) |
MikamiUitOpen | 0:fa74b1130cc3 | 30 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 31 | g0_ = g0; |
MikamiUitOpen | 0:fa74b1130cc3 | 32 | for (int k=0; k<ORDER2_; k++) hk_[k].SetCoefs(ck[k]); |
MikamiUitOpen | 0:fa74b1130cc3 | 33 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 34 | |
MikamiUitOpen | 0:fa74b1130cc3 | 35 | void GetCoefs(float &g0, Biquad::Coefs ck[]) |
MikamiUitOpen | 0:fa74b1130cc3 | 36 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 37 | g0 = g0_; |
MikamiUitOpen | 0:fa74b1130cc3 | 38 | for (int k=0; k<ORDER2_; k++) hk_[k].GetCoefs(ck[k]); |
MikamiUitOpen | 0:fa74b1130cc3 | 39 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 40 | |
MikamiUitOpen | 0:fa74b1130cc3 | 41 | float Execute(float xn) |
MikamiUitOpen | 0:fa74b1130cc3 | 42 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 43 | float yn = g0_*xn; |
MikamiUitOpen | 0:fa74b1130cc3 | 44 | for (int k=0; k<ORDER2_; k++) |
MikamiUitOpen | 0:fa74b1130cc3 | 45 | yn = hk_[k].Execute(yn); |
MikamiUitOpen | 0:fa74b1130cc3 | 46 | |
MikamiUitOpen | 0:fa74b1130cc3 | 47 | return yn; |
MikamiUitOpen | 0:fa74b1130cc3 | 48 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 49 | |
MikamiUitOpen | 0:fa74b1130cc3 | 50 | void Clear() |
MikamiUitOpen | 0:fa74b1130cc3 | 51 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 52 | for (int k=0; k<ORDER2_; k++) |
MikamiUitOpen | 0:fa74b1130cc3 | 53 | hk_[k].Clear(); |
MikamiUitOpen | 0:fa74b1130cc3 | 54 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 55 | |
MikamiUitOpen | 0:fa74b1130cc3 | 56 | private: |
MikamiUitOpen | 0:fa74b1130cc3 | 57 | const int ORDER2_; |
MikamiUitOpen | 0:fa74b1130cc3 | 58 | Array<Biquad> hk_; // Elements of cascade structure |
MikamiUitOpen | 0:fa74b1130cc3 | 59 | float g0_; // gain factor |
MikamiUitOpen | 0:fa74b1130cc3 | 60 | |
MikamiUitOpen | 0:fa74b1130cc3 | 61 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:fa74b1130cc3 | 62 | IirCascade(const IirCascade&); |
MikamiUitOpen | 0:fa74b1130cc3 | 63 | IirCascade& operator=(const IirCascade&); |
MikamiUitOpen | 0:fa74b1130cc3 | 64 | }; |
MikamiUitOpen | 0:fa74b1130cc3 | 65 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 66 | #endif // IIR_CASCADE_HPP |