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/LPC_Analysis.cpp@0:5c237fdcba23, 2015-12-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Dec 09 05:05:00 2015 +0000
- Revision:
- 0:5c237fdcba23
- Child:
- 2:095b360e0f54
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:5c237fdcba23 | 1 | //------------------------------------------------------- |
MikamiUitOpen | 0:5c237fdcba23 | 2 | // Class for spectrum analysis using linear prediction |
MikamiUitOpen | 0:5c237fdcba23 | 3 | // |
MikamiUitOpen | 0:5c237fdcba23 | 4 | // 2015/12/08, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:5c237fdcba23 | 5 | //------------------------------------------------------- |
MikamiUitOpen | 0:5c237fdcba23 | 6 | |
MikamiUitOpen | 0:5c237fdcba23 | 7 | #include "LPC_Analysis.hpp" |
MikamiUitOpen | 0:5c237fdcba23 | 8 | |
MikamiUitOpen | 0:5c237fdcba23 | 9 | namespace Mikami |
MikamiUitOpen | 0:5c237fdcba23 | 10 | { |
MikamiUitOpen | 0:5c237fdcba23 | 11 | LpcAnalyzer::LpcAnalyzer(int nData, int nFft, int order) |
MikamiUitOpen | 0:5c237fdcba23 | 12 | : AnalyzerBase(nData, nFft), ORDER_(order), |
MikamiUitOpen | 0:5c237fdcba23 | 13 | wHm_(nData-1, nData-1), lp_(nData-1, order), |
MikamiUitOpen | 0:5c237fdcba23 | 14 | xData_(new float[nData]), an_(new float[order]), |
MikamiUitOpen | 0:5c237fdcba23 | 15 | xFft_(new float[nFft]), yFft_(new Complex[nFft/2+1]) {} |
MikamiUitOpen | 0:5c237fdcba23 | 16 | |
MikamiUitOpen | 0:5c237fdcba23 | 17 | LpcAnalyzer::~LpcAnalyzer() |
MikamiUitOpen | 0:5c237fdcba23 | 18 | { |
MikamiUitOpen | 0:5c237fdcba23 | 19 | delete[] xData_; |
MikamiUitOpen | 0:5c237fdcba23 | 20 | delete[] an_; |
MikamiUitOpen | 0:5c237fdcba23 | 21 | delete[] xFft_; |
MikamiUitOpen | 0:5c237fdcba23 | 22 | delete[] yFft_; |
MikamiUitOpen | 0:5c237fdcba23 | 23 | } |
MikamiUitOpen | 0:5c237fdcba23 | 24 | |
MikamiUitOpen | 0:5c237fdcba23 | 25 | void LpcAnalyzer::Analyze(const float xn[], float yn[]) |
MikamiUitOpen | 0:5c237fdcba23 | 26 | { |
MikamiUitOpen | 0:5c237fdcba23 | 27 | wHm_.Execute(xn, xData_); // Windowing |
MikamiUitOpen | 0:5c237fdcba23 | 28 | float em; |
MikamiUitOpen | 0:5c237fdcba23 | 29 | lp_.Execute(xData_, an_, em); |
MikamiUitOpen | 0:5c237fdcba23 | 30 | |
MikamiUitOpen | 0:5c237fdcba23 | 31 | // To spectrum |
MikamiUitOpen | 0:5c237fdcba23 | 32 | xFft_[0] = 1.0f; |
MikamiUitOpen | 0:5c237fdcba23 | 33 | for (int n=0; n<ORDER_; n++) xFft_[n+1] = -an_[n]; |
MikamiUitOpen | 0:5c237fdcba23 | 34 | for (int n=ORDER_+1; n<N_FFT_; n++) xFft_[n] = 0.0f; |
MikamiUitOpen | 0:5c237fdcba23 | 35 | fft_.Execute(xFft_, yFft_); // execute FFT |
MikamiUitOpen | 0:5c237fdcba23 | 36 | |
MikamiUitOpen | 0:5c237fdcba23 | 37 | // Translate to dB |
MikamiUitOpen | 0:5c237fdcba23 | 38 | for (int n=0; n<=N_FFT_/2; n++) |
MikamiUitOpen | 0:5c237fdcba23 | 39 | yn[n] = 10.0f*log10f(em/Norm(yFft_[n])); |
MikamiUitOpen | 0:5c237fdcba23 | 40 | } |
MikamiUitOpen | 0:5c237fdcba23 | 41 | } |