![](/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:
- 3:7c26b701f363
- Parent:
- 2:095b360e0f54
- Child:
- 4:99d4d5ea06a2
diff -r 095b360e0f54 -r 7c26b701f363 MyClasses/CepstrumAnalysis.cpp --- a/MyClasses/CepstrumAnalysis.cpp Sun Dec 13 07:20:14 2015 +0000 +++ b/MyClasses/CepstrumAnalysis.cpp Mon Dec 14 13:44:42 2015 +0000 @@ -1,7 +1,7 @@ //------------------------------------------------------- // Class for spectrum analysis using cepstrum // -// 2015/12/09, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/14, Copyright (c) 2015 MIKAMI, Naoki //------------------------------------------------------- #include "CepstrumAnalysis.hpp" @@ -9,11 +9,10 @@ namespace Mikami { CepstrumAnalyzer::CepstrumAnalyzer(int nData, int nFft, int nLifter) - : AnalyzerBase(nData, nFft), N_LIFTER_(nLifter), - wHm_(nData-1, nFft), + : AnalyzerBase(nData, nFft, nFft), N_LIFTER_(nLifter), 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]), + lifter_(new float[nLifter]), db_(new Complex[nFft/2+1]), + cep_(new float[nFft]), cepLft_(new float[nFft]), cepFt_(new Complex[nFft/2+1]) { // Generate lifter @@ -28,7 +27,6 @@ delete[] yFft_; delete[] lifter_; delete[] db_; - delete[] cDb_; delete[] cep_; delete[] cepLft_; delete[] cepFt_; @@ -39,15 +37,11 @@ wHm_.Execute(xn, xFft_); // Windowing and zero-padding fft_.Execute(xFft_, yFft_); // Execute FFT - // Translate to dB + // Translate to dB and to complex 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 + db_[n] = Complex(10.0f*log10f(Norm(yFft_[n])), 0); + + fft_.ExecuteIfft(db_, cep_); // To cepstrum // Liftering cepLft_[0] = cep_[0]; @@ -56,9 +50,10 @@ for (int n=N_LIFTER_; n<N_FFT_; n++) cepLft_[n] = 0.0f; + // Smoothed spectrum fft_.Execute(cepLft_, cepFt_); for (int n=0; n<=N_FFT_/2; n++) - yn[n] = cepFt_[n].real() + 10.0f; + yn[n] = cepFt_[n].real(); } }