![](/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/CepstrumAnalysis.cpp
- Revision:
- 0:5c237fdcba23
- Child:
- 2:095b360e0f54
diff -r 000000000000 -r 5c237fdcba23 MyClasses/CepstrumAnalysis.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyClasses/CepstrumAnalysis.cpp Wed Dec 09 05:05:00 2015 +0000 @@ -0,0 +1,63 @@ +//------------------------------------------------------- +// Class for spectrum analysis using cepstrum +// +// 2015/12/09, Copyright (c) 2015 MIKAMI, Naoki +//------------------------------------------------------- + +#include "CepstrumAnalysis.hpp" + +namespace Mikami +{ + CepstrumAnalyzer::CepstrumAnalyzer(int nData, int nFft, int nLifter) + : AnalyzerBase(nData, nFft), N_LIFTER_(nLifter), + wHm_(nData-1, nFft), + xFft_(new float[nFft]), yFft_(new Complex[nFft/2+1]), + lifter_(new float[nLifter]), db_(new float[nFft/2+1]), + cDb_(new Complex[nFft/2+1]), cep_(new float[nFft]), + cepLft_(new float[nFft]), cepFt_(new Complex[nFft/2+1]) + { + // Generate lifter + float pi2N = 3.1415926536f/nLifter; + for (int n=0; n<nLifter; n++) + lifter_[n] = 0.54f + 0.46f*cosf(pi2N*n); + } + + CepstrumAnalyzer::~CepstrumAnalyzer() + { + delete[] xFft_; + delete[] yFft_; + delete[] lifter_; + delete[] db_; + delete[] cDb_; + delete[] cep_; + delete[] cepLft_; + delete[] cepFt_; + } + + void CepstrumAnalyzer::Analyze(const float xn[], float yn[]) + { + wHm_.Execute(xn, xFft_); // Windowing and zero-padding + fft_.Execute(xFft_, yFft_); // Execute FFT + + // Translate to dB + for (int n=0; n<=N_FFT_/2; n++) + db_[n] = 10.0f*log10f(Norm(yFft_[n])); + + // To smoothed spectrum using cepstrum + for (int n=0; n<=N_FFT_/2; n++) + cDb_[n] = Complex(db_[n], 0); + + fft_.ExecuteIfft(cDb_, cep_); // To cepstrum + + // Liftering + cepLft_[0] = cep_[0]; + for (int n=1; n<N_LIFTER_; n++) + cepLft_[n] = 2.0f*lifter_[n]*cep_[n]; + for (int n=N_LIFTER_; n<N_FFT_; n++) + cepLft_[n] = 0.0f; + + fft_.Execute(cepLft_, cepFt_); + for (int n=0; n<=N_FFT_/2; n++) + yn[n] = cepFt_[n].real() + 10.0f; + } +}