AM中波放送用SDR.CICフィルタのみを使用.CQ出版社「トランジスタ技術」誌,2021年5月号に掲載

Dependencies:   mbed

Committer:
MikamiUitOpen
Date:
Sat Aug 29 11:26:29 2020 +0000
Revision:
0:7a653530c8ce
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:7a653530c8ce 1 //--------------------------------------------------------------
MikamiUitOpen 0:7a653530c8ce 2 // IIR フィルタを利用する直交信号発生器のクラス
MikamiUitOpen 0:7a653530c8ce 3 //
MikamiUitOpen 0:7a653530c8ce 4 // 2020/07/30, Copyright (c) 2020 MIKAMI, Naoki
MikamiUitOpen 0:7a653530c8ce 5 //--------------------------------------------------------------
MikamiUitOpen 0:7a653530c8ce 6
MikamiUitOpen 0:7a653530c8ce 7 #include "mbed.h"
MikamiUitOpen 0:7a653530c8ce 8
MikamiUitOpen 0:7a653530c8ce 9 #ifndef QUAD_PHASE_OSC_IIR_HPP
MikamiUitOpen 0:7a653530c8ce 10 #define QUAD_PHASE_OSC_IIR_HPP
MikamiUitOpen 0:7a653530c8ce 11
MikamiUitOpen 0:7a653530c8ce 12 namespace Mikami
MikamiUitOpen 0:7a653530c8ce 13 {
MikamiUitOpen 0:7a653530c8ce 14 class QuadOscIir
MikamiUitOpen 0:7a653530c8ce 15 {
MikamiUitOpen 0:7a653530c8ce 16 public:
MikamiUitOpen 0:7a653530c8ce 17 // コンストラクタ
MikamiUitOpen 0:7a653530c8ce 18 // f0 周波数,単位:Hz
MikamiUitOpen 0:7a653530c8ce 19 // ts 標本化間隔,単位:μs
MikamiUitOpen 0:7a653530c8ce 20 // amp 振幅
MikamiUitOpen 0:7a653530c8ce 21 QuadOscIir(float f0, float ts, float amp = 1)
MikamiUitOpen 0:7a653530c8ce 22 : TS_(ts*1.0E-6f), A0_(amp) { Set(f0); }
MikamiUitOpen 0:7a653530c8ce 23
MikamiUitOpen 0:7a653530c8ce 24 // sin/cos 発生
MikamiUitOpen 0:7a653530c8ce 25 void Generate(float &sinX, float &cosX)
MikamiUitOpen 0:7a653530c8ce 26 {
MikamiUitOpen 0:7a653530c8ce 27 float vn = a1_*vn1_ - vn2_;
MikamiUitOpen 0:7a653530c8ce 28 sinX = b1S_*vn1_;
MikamiUitOpen 0:7a653530c8ce 29 cosX = A0_*vn + b1C_*vn1_;
MikamiUitOpen 0:7a653530c8ce 30
MikamiUitOpen 0:7a653530c8ce 31 vn2_ = vn1_; // v[n-2] ← v[n-1]
MikamiUitOpen 0:7a653530c8ce 32 vn1_ = vn; // v[n-1] ← v[n]
MikamiUitOpen 0:7a653530c8ce 33 }
MikamiUitOpen 0:7a653530c8ce 34
MikamiUitOpen 0:7a653530c8ce 35 // 出力周波数の設定,周波数を変更し再スタートする場合も使える
MikamiUitOpen 0:7a653530c8ce 36 // f0:周波数,単位:Hz
MikamiUitOpen 0:7a653530c8ce 37 void Set(float f0)
MikamiUitOpen 0:7a653530c8ce 38 {
MikamiUitOpen 0:7a653530c8ce 39 static const float PI2 = 6.283185f;
MikamiUitOpen 0:7a653530c8ce 40 a1_ = 2.0f*cosf(PI2*f0*TS_);
MikamiUitOpen 0:7a653530c8ce 41 b1S_ = A0_*sinf(PI2*f0*TS_);
MikamiUitOpen 0:7a653530c8ce 42 b1C_ = -A0_*cosf(PI2*f0*TS_);
MikamiUitOpen 0:7a653530c8ce 43 vn1_ = 1.0f;
MikamiUitOpen 0:7a653530c8ce 44 vn2_ = 0.0f;
MikamiUitOpen 0:7a653530c8ce 45 }
MikamiUitOpen 0:7a653530c8ce 46
MikamiUitOpen 0:7a653530c8ce 47 private:
MikamiUitOpen 0:7a653530c8ce 48 const float TS_; // 標本化間隔
MikamiUitOpen 0:7a653530c8ce 49 const float A0_; // 振幅
MikamiUitOpen 0:7a653530c8ce 50 float a1_, b1S_, b1C_;
MikamiUitOpen 0:7a653530c8ce 51 float vn1_, vn2_;
MikamiUitOpen 0:7a653530c8ce 52
MikamiUitOpen 0:7a653530c8ce 53 // コピー・コンストラクタ,代入演算子の禁止のため
MikamiUitOpen 0:7a653530c8ce 54 QuadOscIir(const QuadOscIir&);
MikamiUitOpen 0:7a653530c8ce 55 QuadOscIir& operator=(const QuadOscIir&);
MikamiUitOpen 0:7a653530c8ce 56 };
MikamiUitOpen 0:7a653530c8ce 57 }
MikamiUitOpen 0:7a653530c8ce 58 #endif // QUAD_PHASE_OSC_IIR_HPP