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-28
- Revision:
- 8:1f4bc859bc84
- Parent:
- 7:6598a9b70e5a
- Child:
- 12:e5367ab82460
File content as of revision 8:1f4bc859bc84:
//----------------------------------------------------------- // Class for sampling input signal // // 2015/12/28, 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), sn_(new int16_t[nData]), buffer_(new int16_t[nData]) { for (int n=0; n<nData; n++) sn_[n] = 32767; } Sampler::~Sampler() { delete[] sn_; delete[] buffer_; } // Start sampling void Sampler::Start(bool onOff) { count_ = 0; filled_ = false; trigger_ = false; xnM1_ = 32767; Invert(onOff); timer_.attach_us(this, &Sampler::Isr, TS_); } // Interrupt service routine for Ticker void Sampler::Isr() { int16_t xn = (this->*Rd)(); // Read from A0 if (!trigger_) { // Detect rising edge if ((xn > (xnM1_+512)) && (xn > 2048)) trigger_ = true; else xnM1_ = xn; return; } else buffer_[count_] = xn; if (++count_ >= N_DATA_) { timer_.detach(); memcpy(sn_, buffer_, N_DATA_*sizeof(int16_t)); filled_ = true; // Permits spectrum analysis } } }