![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使う適応線スペクトル強調器(ALE)のプログラム.ステップサイズパラメータをターミナルから変更できる. http://seminar.cqpub.co.jp/ccm/ES18-0020
Dependencies: F746_GUI F746_SAI_IO mbed
main.cpp@1:ba4abf0c8427, 2018-03-12 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Mar 12 04:58:20 2018 +0000
- Revision:
- 1:ba4abf0c8427
- Parent:
- 0:c8e52f514e03
- Child:
- 2:ef391be185f5
2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:c8e52f514e03 | 1 | //----------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 2 | // ディジタルフィルタ実験のためのプラットフォーム(標本化周波数:48 kHz) |
MikamiUitOpen | 0:c8e52f514e03 | 3 | // ---- 入出力信号の波形表示付き ---- |
MikamiUitOpen | 0:c8e52f514e03 | 4 | // |
MikamiUitOpen | 0:c8e52f514e03 | 5 | // 適応線スペクトル強調器(ALE): |
MikamiUitOpen | 0:c8e52f514e03 | 6 | // ターミナルソフトからステップサイズパラメータ(μ)の変更可能 |
MikamiUitOpen | 0:c8e52f514e03 | 7 | // |
MikamiUitOpen | 0:c8e52f514e03 | 8 | // 使用しているライブラリのリビジョン: |
MikamiUitOpen | 1:ba4abf0c8427 | 9 | // F746_GUI Rev.33 |
MikamiUitOpen | 1:ba4abf0c8427 | 10 | // F746_SAI_IO Rev.12 |
MikamiUitOpen | 1:ba4abf0c8427 | 11 | // mbed Rev.161 |
MikamiUitOpen | 0:c8e52f514e03 | 12 | // |
MikamiUitOpen | 1:ba4abf0c8427 | 13 | // 2018/03/12, Copyright (c) 2018 MIKAMI, Naoki |
MikamiUitOpen | 0:c8e52f514e03 | 14 | //----------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 15 | |
MikamiUitOpen | 0:c8e52f514e03 | 16 | #include "SAI_InOut.hpp" |
MikamiUitOpen | 0:c8e52f514e03 | 17 | #include "LcdPanelFrqEx.hpp" |
MikamiUitOpen | 0:c8e52f514e03 | 18 | #include "TerminalInput.hpp" // ターミナルとの通信用 |
MikamiUitOpen | 0:c8e52f514e03 | 19 | #include "GaussRand.hpp" // 正規乱数発生 |
MikamiUitOpen | 0:c8e52f514e03 | 20 | |
MikamiUitOpen | 0:c8e52f514e03 | 21 | #pragma diag_suppress 870 // マルチバイト文字使用の warning 抑制のため |
MikamiUitOpen | 0:c8e52f514e03 | 22 | |
MikamiUitOpen | 0:c8e52f514e03 | 23 | //----------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 24 | // 実行するフィルタに応じて以下のインクルードファイルを変更する |
MikamiUitOpen | 0:c8e52f514e03 | 25 | #include "ALE_Variable.hpp" // 線スペクトル強調器 |
MikamiUitOpen | 0:c8e52f514e03 | 26 | //----------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 27 | |
MikamiUitOpen | 0:c8e52f514e03 | 28 | int main() |
MikamiUitOpen | 0:c8e52f514e03 | 29 | { |
MikamiUitOpen | 0:c8e52f514e03 | 30 | //------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 31 | // xxxx_Variable 版の追加箇所 |
MikamiUitOpen | 0:c8e52f514e03 | 32 | const string MESSAGE = "1.0E-10 以下の数を入力してください\r\n"; |
MikamiUitOpen | 0:c8e52f514e03 | 33 | TermInput comm("\r\n適応線スペクトル強調器を実行します.\r\n"); |
MikamiUitOpen | 0:c8e52f514e03 | 34 | comm.printf("ここからμ (ステップサイズパラメータ) の値を変更できます.\r\n"); |
MikamiUitOpen | 0:c8e52f514e03 | 35 | comm.printf(MESSAGE+"? "); |
MikamiUitOpen | 0:c8e52f514e03 | 36 | // xxxx_Variable 版の追加箇所:ここまで |
MikamiUitOpen | 0:c8e52f514e03 | 37 | //------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 38 | |
MikamiUitOpen | 0:c8e52f514e03 | 39 | const int FS = I2S_AUDIOFREQ_48K; // 標本化周波数:48 kHz |
MikamiUitOpen | 0:c8e52f514e03 | 40 | // オーディオ信号出力用 |
MikamiUitOpen | 0:c8e52f514e03 | 41 | SaiIO mySai(SaiIO::OUTPUT, 2048, FS); |
MikamiUitOpen | 0:c8e52f514e03 | 42 | |
MikamiUitOpen | 0:c8e52f514e03 | 43 | // LCD パネル表示用 |
MikamiUitOpen | 0:c8e52f514e03 | 44 | LcdPanelEx myPanel(1.0f/(float)FS, 1); |
MikamiUitOpen | 0:c8e52f514e03 | 45 | |
MikamiUitOpen | 0:c8e52f514e03 | 46 | //----------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 47 | // ここでディジタルフィルタのオブジェクト生成や初期化などを行う |
MikamiUitOpen | 0:c8e52f514e03 | 48 | float mu = 1.0E-12f; |
MikamiUitOpen | 0:c8e52f514e03 | 49 | AleVariable df(5, 120, mu); // ALE を実行するオブジェクト |
MikamiUitOpen | 0:c8e52f514e03 | 50 | Mikami::GaussRand rd(0.6f, 0); // ガウス性白色雑音,標準偏差:0.6,平均値: 0 |
MikamiUitOpen | 0:c8e52f514e03 | 51 | //----------------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 52 | |
MikamiUitOpen | 0:c8e52f514e03 | 53 | // ステップサイズ・パラメータの表示用ラベル |
MikamiUitOpen | 0:c8e52f514e03 | 54 | NumericLabel<float> myLabel(40, 168, "mu = %8.2e"); |
MikamiUitOpen | 0:c8e52f514e03 | 55 | myLabel.Draw(mu); |
MikamiUitOpen | 0:c8e52f514e03 | 56 | |
MikamiUitOpen | 0:c8e52f514e03 | 57 | mySai.PlayOut(); // オーディオ信号出力開始 |
MikamiUitOpen | 0:c8e52f514e03 | 58 | |
MikamiUitOpen | 0:c8e52f514e03 | 59 | const float MAX_AMP = 10000.0f; |
MikamiUitOpen | 0:c8e52f514e03 | 60 | string rxBuf = ""; |
MikamiUitOpen | 0:c8e52f514e03 | 61 | while (true) // 無限ループ |
MikamiUitOpen | 0:c8e52f514e03 | 62 | { |
MikamiUitOpen | 0:c8e52f514e03 | 63 | // 出力バッファへの転送が完了したら以下の処理を行う |
MikamiUitOpen | 0:c8e52f514e03 | 64 | if (mySai.IsXferred()) |
MikamiUitOpen | 0:c8e52f514e03 | 65 | { |
MikamiUitOpen | 0:c8e52f514e03 | 66 | for (int n=0; n<mySai.GetLength(); n++) |
MikamiUitOpen | 0:c8e52f514e03 | 67 | { |
MikamiUitOpen | 0:c8e52f514e03 | 68 | // 入力信号の生成 |
MikamiUitOpen | 0:c8e52f514e03 | 69 | float phi = myPanel.GetPhi(); |
MikamiUitOpen | 0:c8e52f514e03 | 70 | float sn = sinf(phi); // 入力信号となる正弦波を発生 |
MikamiUitOpen | 0:c8e52f514e03 | 71 | sn = 0.6f*(sn + rd.Next()); // 雑音を付加 |
MikamiUitOpen | 0:c8e52f514e03 | 72 | |
MikamiUitOpen | 0:c8e52f514e03 | 73 | int16_t xn = (int16_t)(MAX_AMP*sn); |
MikamiUitOpen | 0:c8e52f514e03 | 74 | //------------------------------------------------------ |
MikamiUitOpen | 0:c8e52f514e03 | 75 | // ディジタルフィルタなどの信号処理の実行 |
MikamiUitOpen | 0:c8e52f514e03 | 76 | int16_t yn = df.Execute(xn); |
MikamiUitOpen | 0:c8e52f514e03 | 77 | //------------------------------------------------------ |
MikamiUitOpen | 0:c8e52f514e03 | 78 | myPanel.Store(xn, yn, n); // 表示用として格納 |
MikamiUitOpen | 0:c8e52f514e03 | 79 | |
MikamiUitOpen | 0:c8e52f514e03 | 80 | // ヘッドフォン端子への出力信号の選択 |
MikamiUitOpen | 0:c8e52f514e03 | 81 | switch (myPanel.GetOutNum()) |
MikamiUitOpen | 0:c8e52f514e03 | 82 | { |
MikamiUitOpen | 0:c8e52f514e03 | 83 | case 0: mySai.Output(xn, yn); break; // 入出力信号 |
MikamiUitOpen | 0:c8e52f514e03 | 84 | case 1: mySai.Output(xn, xn); break; // 両チャンネル:入力信号 |
MikamiUitOpen | 0:c8e52f514e03 | 85 | case 2: mySai.Output(yn, yn); break; // 両チャンネル:出力信号 |
MikamiUitOpen | 0:c8e52f514e03 | 86 | } |
MikamiUitOpen | 0:c8e52f514e03 | 87 | } |
MikamiUitOpen | 0:c8e52f514e03 | 88 | |
MikamiUitOpen | 0:c8e52f514e03 | 89 | myPanel.Display(); // 入出力信号の波形表示 |
MikamiUitOpen | 0:c8e52f514e03 | 90 | } |
MikamiUitOpen | 0:c8e52f514e03 | 91 | myPanel.Update(); // パネルの状態を読み取り必要なパラメータなどを更新する |
MikamiUitOpen | 0:c8e52f514e03 | 92 | |
MikamiUitOpen | 0:c8e52f514e03 | 93 | //--------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 94 | // xxxx_Variable 版の追加箇所 |
MikamiUitOpen | 0:c8e52f514e03 | 95 | // ターミナルとの通信 |
MikamiUitOpen | 0:c8e52f514e03 | 96 | float val; |
MikamiUitOpen | 0:c8e52f514e03 | 97 | if (comm.Get(val)) // 入力が完了していれば以下を実行する |
MikamiUitOpen | 0:c8e52f514e03 | 98 | { |
MikamiUitOpen | 0:c8e52f514e03 | 99 | if (val <= 1.0E-10f) |
MikamiUitOpen | 0:c8e52f514e03 | 100 | df.SetMu(val); |
MikamiUitOpen | 0:c8e52f514e03 | 101 | else |
MikamiUitOpen | 0:c8e52f514e03 | 102 | comm.printf(MESSAGE); |
MikamiUitOpen | 0:c8e52f514e03 | 103 | |
MikamiUitOpen | 0:c8e52f514e03 | 104 | myLabel.Draw(val); |
MikamiUitOpen | 0:c8e52f514e03 | 105 | comm.printf("? "); |
MikamiUitOpen | 0:c8e52f514e03 | 106 | } |
MikamiUitOpen | 0:c8e52f514e03 | 107 | // xxxx_Variable 版の追加箇所:ここまで |
MikamiUitOpen | 0:c8e52f514e03 | 108 | //--------------------------------------------------------- |
MikamiUitOpen | 0:c8e52f514e03 | 109 | } |
MikamiUitOpen | 0:c8e52f514e03 | 110 | } |