![](/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
Diff: MyClasses/Sampler.cpp
- Revision:
- 7:6598a9b70e5a
- Parent:
- 6:b27ef8d98edc
- Child:
- 8:1f4bc859bc84
--- a/MyClasses/Sampler.cpp Fri Dec 18 10:09:31 2015 +0000 +++ b/MyClasses/Sampler.cpp Sun Dec 20 13:38:22 2015 +0000 @@ -1,35 +1,41 @@ //----------------------------------------------------------- // Class for sampling input signal // -// 2015/12/18, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/20, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #include "Sampler.hpp" namespace Mikami { - Sampler::Sampler(PinName pin, int fs, int nData, - int16_t* const buffer) + Sampler::Sampler(PinName pin, int fs, int nData) : TS_(1000000/fs), N_DATA_(nData), aIn_(pin), - buffer_(buffer) - { - Set(false); + xn_(new int16_t[nData]), + buffer_(new int16_t[nData]) + { Rd[0] = &Sampler::ReadNorm; // inphase Rd[1] = &Sampler::ReadInv; // out-of-phase sw_ = 0; + Set(false); for (int n=0; n<nData; n++) buffer_[n] = 32767; } - void Sampler::IntrEnable() + Sampler::~Sampler() + { + delete[] xn_; + delete[] buffer_; + } + + void Sampler::Start() { count_ = 0; + filled_ = false; timer_.attach_us(this, &Sampler::Isr, TS_); } void Sampler::Set(bool tf) { - timer_.detach(); trigger_ = false; xnM1_ = 32767; filled_ = tf; @@ -52,6 +58,10 @@ buffer_[count_] = (this->*Rd[sw_])(); // Read from A0 if (++count_ >= N_DATA_) - Set(true); // Permits spectrum analysis + { + timer_.detach(); + Set(true); // Permits spectrum analysis + memcpy(xn_, buffer_, N_DATA_*sizeof(int16_t)); + } } }