![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Realtime spectrum analyzer. Using FFT, linear prediction, or cepstrum smoothing. Version using MEMS microphone and CODEC, named "F746_RealtimeSpectrumAnalyzer_MEMS_Mic" is registered. リアルタイム スペクトル解析器.解析の手法:FFT,線形予測法,ケプストラムによる平滑化の3種類.このプログラムの説明は,CQ出版社のインターフェース誌,2016年4月号に掲載.外付けのマイクまたは他の信号源等を A0 に接続する.線形予測法,ケプストラムは,スペクトル解析の対象を音声信号に想定してパラメータを設定している.MEMS マイクと CODEC を使ったバージョンを "F746_RealtimeSpectrumAnalyzer_MEMS_Mic" として登録.
Dependencies: BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed
MyClasses/Sampler.cpp@2:095b360e0f54, 2015-12-13 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Dec 13 07:20:14 2015 +0000
- Revision:
- 2:095b360e0f54
- Child:
- 5:98ec9dd54144
3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 2:095b360e0f54 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 2:095b360e0f54 | 2 | // Class for sampling input signal |
MikamiUitOpen | 2:095b360e0f54 | 3 | // |
MikamiUitOpen | 2:095b360e0f54 | 4 | // 2015/12/11, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 2:095b360e0f54 | 5 | //----------------------------------------------------------- |
MikamiUitOpen | 2:095b360e0f54 | 6 | |
MikamiUitOpen | 2:095b360e0f54 | 7 | #include "Sampler.hpp" |
MikamiUitOpen | 2:095b360e0f54 | 8 | |
MikamiUitOpen | 2:095b360e0f54 | 9 | namespace Mikami |
MikamiUitOpen | 2:095b360e0f54 | 10 | { |
MikamiUitOpen | 2:095b360e0f54 | 11 | Sampler::Sampler(PinName pin, int fs, int nData) |
MikamiUitOpen | 2:095b360e0f54 | 12 | : TS_(1000000/fs), N_DATA_(nData), aIn_(pin), |
MikamiUitOpen | 2:095b360e0f54 | 13 | buffer_(new int16_t[nData]) |
MikamiUitOpen | 2:095b360e0f54 | 14 | { |
MikamiUitOpen | 2:095b360e0f54 | 15 | Set(false); |
MikamiUitOpen | 2:095b360e0f54 | 16 | Rd[0] = &Sampler::ReadNorm; // inphase |
MikamiUitOpen | 2:095b360e0f54 | 17 | Rd[1] = &Sampler::ReadInv; // out-of-phase |
MikamiUitOpen | 2:095b360e0f54 | 18 | sw_ = 0; |
MikamiUitOpen | 2:095b360e0f54 | 19 | } |
MikamiUitOpen | 2:095b360e0f54 | 20 | |
MikamiUitOpen | 2:095b360e0f54 | 21 | void Sampler::IntrEnable() |
MikamiUitOpen | 2:095b360e0f54 | 22 | { |
MikamiUitOpen | 2:095b360e0f54 | 23 | count_ = 0; |
MikamiUitOpen | 2:095b360e0f54 | 24 | timer_.attach_us(this, &Sampler::Isr, TS_); |
MikamiUitOpen | 2:095b360e0f54 | 25 | } |
MikamiUitOpen | 2:095b360e0f54 | 26 | |
MikamiUitOpen | 2:095b360e0f54 | 27 | void Sampler::Set(bool tf) |
MikamiUitOpen | 2:095b360e0f54 | 28 | { |
MikamiUitOpen | 2:095b360e0f54 | 29 | timer_.detach(); |
MikamiUitOpen | 2:095b360e0f54 | 30 | trigger_ = false; |
MikamiUitOpen | 2:095b360e0f54 | 31 | xnM1_ = 32767; |
MikamiUitOpen | 2:095b360e0f54 | 32 | filled_ = tf; |
MikamiUitOpen | 2:095b360e0f54 | 33 | } |
MikamiUitOpen | 2:095b360e0f54 | 34 | |
MikamiUitOpen | 2:095b360e0f54 | 35 | // Interrupt service routine for Ticker |
MikamiUitOpen | 2:095b360e0f54 | 36 | void Sampler::Isr() |
MikamiUitOpen | 2:095b360e0f54 | 37 | { |
MikamiUitOpen | 2:095b360e0f54 | 38 | if (!trigger_) |
MikamiUitOpen | 2:095b360e0f54 | 39 | { |
MikamiUitOpen | 2:095b360e0f54 | 40 | int16_t xn = (this->*Rd[sw_])(); |
MikamiUitOpen | 2:095b360e0f54 | 41 | // Detect rising edge |
MikamiUitOpen | 2:095b360e0f54 | 42 | if ((xn > (xnM1_+512)) && (xn > 2048)) |
MikamiUitOpen | 2:095b360e0f54 | 43 | trigger_ = true; |
MikamiUitOpen | 2:095b360e0f54 | 44 | else |
MikamiUitOpen | 2:095b360e0f54 | 45 | xnM1_ = xn; |
MikamiUitOpen | 2:095b360e0f54 | 46 | return; |
MikamiUitOpen | 2:095b360e0f54 | 47 | } |
MikamiUitOpen | 2:095b360e0f54 | 48 | |
MikamiUitOpen | 2:095b360e0f54 | 49 | buffer_[count_] = (this->*Rd[sw_])(); // Read from A0 |
MikamiUitOpen | 2:095b360e0f54 | 50 | |
MikamiUitOpen | 2:095b360e0f54 | 51 | if (++count_ >= N_DATA_) |
MikamiUitOpen | 2:095b360e0f54 | 52 | Set(true); // Permits spectrum analysis |
MikamiUitOpen | 2:095b360e0f54 | 53 | } |
MikamiUitOpen | 2:095b360e0f54 | 54 | } |
MikamiUitOpen | 2:095b360e0f54 | 55 |