STM32F446 内蔵の DAC から出力する際に,補間フィルタを利用し,標本化周波数を入力の際の4倍の標本化周波数で出力するためのライブラリ.このライブラリを登録した際のプログラム: Demo_DSP_ADDA_Multirate. Library for outputting from built-in DAC in STM32F446 using interpolation filter at sampling frequency of 4 times in case of input.

Dependencies:   Array_Matrix DSP_ADDA

Dependents:   Demo_DSP_ADDA_Multirate DSP_AD_DA_Multirate DSP_GraphicEqualizerB DSP_VariableLHpfB ... more

Revision:
3:59af3dfa0595
Parent:
2:aa092bbc8877
Child:
5:e905fed6b994
--- a/MultirateLiPh.hpp	Tue May 26 12:21:41 2020 +0000
+++ b/MultirateLiPh.hpp	Tue Jun 16 09:48:54 2020 +0000
@@ -4,7 +4,7 @@
 //
 //      出力端子: A2 (PA_4) 
 //
-//  2020/05/26, Copyright (c) 2020 MIKAMI, Naoki
+//  2020/06/16, Copyright (c) 2020 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "DSP_AdcIntr.hpp"
@@ -19,25 +19,31 @@
     class MultirateLiPh
     {
     public:
-        // コンストラクタ
-        MultirateLiPh();
+        // コンストラクタ(デフォルトの補間フィルタの係数を使う場合)
+        //      fSampling   入力の標本化周波数
+        //      pin         入力ピン(デフォルトは A1)
+        //      adc         ADC1, ADC2, ADC3 のいずれか
+        MultirateLiPh(float fSampling,
+                      PinName pin = A1, ADC_TypeDef* const adc = ADC2);
+        // コンストラクタ(デフォルト以外の補間フィルタの係数を使う場合)
+        //      order       補間フィルタの次数
+        //      h1, h2, h3  補間フィルタの係数
+        MultirateLiPh(float fSampling, int order, const float hk1[],
+                      const float hk2[], const float hk3[],
+                      PinName pin = A1, ADC_TypeDef* const adc = ADC2);
 
         virtual ~MultirateLiPh() { delete adc_; }
 
         // 標本化の実行開始
-        //      fSampling   入力の標本化周波数
         //      Func        ソフトウェア割込みに対する ISR
-        //      pin         入力ピン(デフォルトは A1)
-        //      adc         ADC1, ADC2, ADC3 のいずれか
-        void Start(float fSampling, void (*Func)(), PinName pin = A1,
-                   ADC_TypeDef* const adc = ADC2);
+        void Start(void (*Func)());
 
         // AD変換の結果を取り出す
         float Input() { return xn_; }
 
         // 補間用フィルタを実行し,処理結果を出力用バッファへ書き込む
-        void Output(float yn);          
-        
+        void Output(float yn);
+
     private:
         static const int FACTOR_ = 4;   // アップサンプリング倍率:4 倍
                                         // この倍率は 2 のべき乗にすること
@@ -53,25 +59,27 @@
         int indexW_;                // buf_ へ書き込む際のインデックス
 
         // 補間用フィルタ用
-        const int SIZE_;
         const int FIR_LOOP_;        // FIR フィルタのループの数
         const int CENTER_;          // 補間処理をしない信号の位置
         Array<float> un_;           // FIR フィルタの遅延器に対応するバッファ
-        const Array<float> h1_, h2_, h3_;   // FIR フィルタの係数
+        Array<float> h1_, h2_, h3_; // FIR フィルタの係数
 
-        // 補間用フィルタ用の係数
+        // 補間用フィルタ用の係数(デフォルト)
         static const int ORDER_;
         static const float HK1_[], HK2_[], HK3_[];
 
         // 引数を 0 ~ (アップサンプリング倍率-1) の間でカウントアップ
-        static int ModIndex(int &index)
-        {   return index = ++index & MASK_BUF_; }
-        
+        static inline int ModIndex(int &index)
+        {   return ++index & MASK_BUF_; }
+
         // ADC 変換終了割り込みに対する割り込みサービス・ルーチン
         static void AdcIsr();
 
         // 補間用 FIR フィルタ
         float Interpolator(const float hk[]) const;
+
+        // ADC の初期化と割込み優先順位の設定
+         void Init(float fSampling, PinName pin, ADC_TypeDef* const adc);
     };
 }
 #endif  // MULTIRATE_LINEARPHASE_HPP
\ No newline at end of file