takanaka kouzou
/
SDR_AM_Rx_CIC_FIR
AM中波放送用SDR.CICフィルタと通常のFIRフィルタを組み合わせて使用.CQ出版社「トランジスタ技術」誌に掲載予定
SDR_Library/QuadOscIir.hpp@0:9c28f5905a1a, 2020-08-29 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Aug 29 11:25:01 2020 +0000
- Revision:
- 0:9c28f5905a1a
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:9c28f5905a1a | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:9c28f5905a1a | 2 | // IIR フィルタを利用する直交信号発生器のクラス |
MikamiUitOpen | 0:9c28f5905a1a | 3 | // |
MikamiUitOpen | 0:9c28f5905a1a | 4 | // 2020/07/30, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:9c28f5905a1a | 5 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:9c28f5905a1a | 6 | |
MikamiUitOpen | 0:9c28f5905a1a | 7 | #include "mbed.h" |
MikamiUitOpen | 0:9c28f5905a1a | 8 | |
MikamiUitOpen | 0:9c28f5905a1a | 9 | #ifndef QUAD_PHASE_OSC_IIR_HPP |
MikamiUitOpen | 0:9c28f5905a1a | 10 | #define QUAD_PHASE_OSC_IIR_HPP |
MikamiUitOpen | 0:9c28f5905a1a | 11 | |
MikamiUitOpen | 0:9c28f5905a1a | 12 | namespace Mikami |
MikamiUitOpen | 0:9c28f5905a1a | 13 | { |
MikamiUitOpen | 0:9c28f5905a1a | 14 | class QuadOscIir |
MikamiUitOpen | 0:9c28f5905a1a | 15 | { |
MikamiUitOpen | 0:9c28f5905a1a | 16 | public: |
MikamiUitOpen | 0:9c28f5905a1a | 17 | // コンストラクタ |
MikamiUitOpen | 0:9c28f5905a1a | 18 | // f0 周波数,単位:Hz |
MikamiUitOpen | 0:9c28f5905a1a | 19 | // ts 標本化間隔,単位:μs |
MikamiUitOpen | 0:9c28f5905a1a | 20 | // amp 振幅 |
MikamiUitOpen | 0:9c28f5905a1a | 21 | QuadOscIir(float f0, float ts, float amp = 1) |
MikamiUitOpen | 0:9c28f5905a1a | 22 | : TS_(ts*1.0E-6f), A0_(amp) { Set(f0); } |
MikamiUitOpen | 0:9c28f5905a1a | 23 | |
MikamiUitOpen | 0:9c28f5905a1a | 24 | // sin/cos 発生 |
MikamiUitOpen | 0:9c28f5905a1a | 25 | void Generate(float &sinX, float &cosX) |
MikamiUitOpen | 0:9c28f5905a1a | 26 | { |
MikamiUitOpen | 0:9c28f5905a1a | 27 | float vn = a1_*vn1_ - vn2_; |
MikamiUitOpen | 0:9c28f5905a1a | 28 | sinX = b1S_*vn1_; |
MikamiUitOpen | 0:9c28f5905a1a | 29 | cosX = A0_*vn + b1C_*vn1_; |
MikamiUitOpen | 0:9c28f5905a1a | 30 | |
MikamiUitOpen | 0:9c28f5905a1a | 31 | vn2_ = vn1_; // v[n-2] ← v[n-1] |
MikamiUitOpen | 0:9c28f5905a1a | 32 | vn1_ = vn; // v[n-1] ← v[n] |
MikamiUitOpen | 0:9c28f5905a1a | 33 | } |
MikamiUitOpen | 0:9c28f5905a1a | 34 | |
MikamiUitOpen | 0:9c28f5905a1a | 35 | // 出力周波数の設定,周波数を変更し再スタートする場合も使える |
MikamiUitOpen | 0:9c28f5905a1a | 36 | // f0:周波数,単位:Hz |
MikamiUitOpen | 0:9c28f5905a1a | 37 | void Set(float f0) |
MikamiUitOpen | 0:9c28f5905a1a | 38 | { |
MikamiUitOpen | 0:9c28f5905a1a | 39 | static const float PI2 = 6.283185f; |
MikamiUitOpen | 0:9c28f5905a1a | 40 | a1_ = 2.0f*cosf(PI2*f0*TS_); |
MikamiUitOpen | 0:9c28f5905a1a | 41 | b1S_ = A0_*sinf(PI2*f0*TS_); |
MikamiUitOpen | 0:9c28f5905a1a | 42 | b1C_ = -A0_*cosf(PI2*f0*TS_); |
MikamiUitOpen | 0:9c28f5905a1a | 43 | vn1_ = 1.0f; |
MikamiUitOpen | 0:9c28f5905a1a | 44 | vn2_ = 0.0f; |
MikamiUitOpen | 0:9c28f5905a1a | 45 | } |
MikamiUitOpen | 0:9c28f5905a1a | 46 | |
MikamiUitOpen | 0:9c28f5905a1a | 47 | private: |
MikamiUitOpen | 0:9c28f5905a1a | 48 | const float TS_; // 標本化間隔 |
MikamiUitOpen | 0:9c28f5905a1a | 49 | const float A0_; // 振幅 |
MikamiUitOpen | 0:9c28f5905a1a | 50 | float a1_, b1S_, b1C_; |
MikamiUitOpen | 0:9c28f5905a1a | 51 | float vn1_, vn2_; |
MikamiUitOpen | 0:9c28f5905a1a | 52 | |
MikamiUitOpen | 0:9c28f5905a1a | 53 | // コピー・コンストラクタ,代入演算子の禁止のため |
MikamiUitOpen | 0:9c28f5905a1a | 54 | QuadOscIir(const QuadOscIir&); |
MikamiUitOpen | 0:9c28f5905a1a | 55 | QuadOscIir& operator=(const QuadOscIir&); |
MikamiUitOpen | 0:9c28f5905a1a | 56 | }; |
MikamiUitOpen | 0:9c28f5905a1a | 57 | } |
MikamiUitOpen | 0:9c28f5905a1a | 58 | #endif // QUAD_PHASE_OSC_IIR_HPP |