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
Diff: MultirateLiPh.hpp
- Revision:
- 0:79c0b1e2fd10
- Child:
- 1:6f582d9e27b4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MultirateLiPh.hpp Mon May 25 06:13:53 2020 +0000 @@ -0,0 +1,77 @@ +//----------------------------------------------------------- +// 出力を 4 倍にアップサンプリングするクラス(ヘッダ) +// 補間処理で使うフィルタとして,直線位相 FIR フィルタを使用 +// +// 出力端子: A2 (PA_4) +// +// 2020/05/25, Copyright (c) 2020 MIKAMI, Naoki +//----------------------------------------------------------- + +#include "DSP_AdcIntr.hpp" +#include "DSP_Dac.hpp" +#include "Array.hpp" + +#ifndef MULTIRATE_LINEARPHASE_HPP +#define MULTIRATE_LINEARPHASE_HPP + +namespace Mikami +{ + class MultirateLiPh + { + public: + // コンストラクタ + MultirateLiPh(); + + 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); + + // AD変換の結果を取り出す + float Input() { return xn_; } + + + // 補間用フィルタを実行し,処理結果を出力用バッファへ書き込む + void Output(float yn); + + private: + static const int FACTOR_ = 4; // アップサンプリング倍率:4 倍 + // この倍率は 2 のべき乗にすること + static const int MASK_FACTOR_ = FACTOR_ - 1; + static const int MASK_BUF_ = 2*FACTOR_ - 1; + + static DspAdc_Intr *adc_; // AD変換器のオブジェクトのポインタ + static DspDac dac_; // DA変換器のオブジェクト + + static Array<float> buf_; // DA変換器に出力するデータ用バッファ + static int indexR_; // buf_ から読み出す際のインデックス + static float xn_; // AD変換器から入力されたデータ + int indexW_; // buf_ へ書き込む際のインデックス + + // 補間用フィルタ用 + const int FIR_LOOP_; // FIR フィルタのループの数 + const int CENTER_; // 補間処理をしない信号の位置 + Array<float> un_; // FIR フィルタの遅延器に対応するバッファ + Array<float> h1_, h2_, h3_; // FIR フィルタの係数 + + // 補間用フィルタ用の係数(デフォルト) + static const int ORDER_; + static const float HK1_[], HK2_[], HK3_[]; + + // 引数を 0 ~ (アップサンプリング倍率-1) の間でカウントアップ + static inline int ModIndex(int &index) + { return ++index & MASK_BUF_; } + + // ADC 変換終了割り込みに対する割り込みサービス・ルーチン + static void AdcIsr(); + + // 補間用 FIR フィルタ + float Interpolator(const float hk[]) const; + }; +} +#endif // MULTIRATE_LINEARPHASE_HPP \ No newline at end of file