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
- Committer:
- MikamiUitOpen
- Date:
- 2015-12-20
- Revision:
- 7:6598a9b70e5a
- Parent:
- 6:b27ef8d98edc
- Child:
- 8:1f4bc859bc84
File content as of revision 7:6598a9b70e5a:
//----------------------------------------------------------- // Class for sampling input signal // // 2015/12/20, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #include "Sampler.hpp" namespace Mikami { Sampler::Sampler(PinName pin, int fs, int nData) : TS_(1000000/fs), N_DATA_(nData), aIn_(pin), 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; } 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) { trigger_ = false; xnM1_ = 32767; filled_ = tf; } // Interrupt service routine for Ticker void Sampler::Isr() { if (!trigger_) { int16_t xn = (this->*Rd[sw_])(); // Detect rising edge if ((xn > (xnM1_+512)) && (xn > 2048)) trigger_ = true; else xnM1_ = xn; return; } buffer_[count_] = (this->*Rd[sw_])(); // Read from A0 if (++count_ >= N_DATA_) { timer_.detach(); Set(true); // Permits spectrum analysis memcpy(xn_, buffer_, N_DATA_*sizeof(int16_t)); } } }