![](/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
MyClasses/CepstrumAnalysis.cpp@4:99d4d5ea06a2, 2015-12-15 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Dec 15 02:39:31 2015 +0000
- Revision:
- 4:99d4d5ea06a2
- Parent:
- 3:7c26b701f363
5
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 cepstrum |
MikamiUitOpen | 0:5c237fdcba23 | 3 | // |
MikamiUitOpen | 4:99d4d5ea06a2 | 4 | // 2015/12/15, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:5c237fdcba23 | 5 | //------------------------------------------------------- |
MikamiUitOpen | 0:5c237fdcba23 | 6 | |
MikamiUitOpen | 0:5c237fdcba23 | 7 | #include "CepstrumAnalysis.hpp" |
MikamiUitOpen | 0:5c237fdcba23 | 8 | |
MikamiUitOpen | 0:5c237fdcba23 | 9 | namespace Mikami |
MikamiUitOpen | 0:5c237fdcba23 | 10 | { |
MikamiUitOpen | 0:5c237fdcba23 | 11 | CepstrumAnalyzer::CepstrumAnalyzer(int nData, int nFft, int nLifter) |
MikamiUitOpen | 3:7c26b701f363 | 12 | : AnalyzerBase(nData, nFft, nFft), N_LIFTER_(nLifter), |
MikamiUitOpen | 4:99d4d5ea06a2 | 13 | yFft_(new Complex[nFft/2+1]), lifter_(new float[nLifter]), |
MikamiUitOpen | 4:99d4d5ea06a2 | 14 | db_(new Complex[nFft/2+1]), cep_(new float[nFft]), |
MikamiUitOpen | 0:5c237fdcba23 | 15 | cepLft_(new float[nFft]), cepFt_(new Complex[nFft/2+1]) |
MikamiUitOpen | 0:5c237fdcba23 | 16 | { |
MikamiUitOpen | 0:5c237fdcba23 | 17 | // Generate lifter |
MikamiUitOpen | 0:5c237fdcba23 | 18 | float pi2N = 3.1415926536f/nLifter; |
MikamiUitOpen | 0:5c237fdcba23 | 19 | for (int n=0; n<nLifter; n++) |
MikamiUitOpen | 0:5c237fdcba23 | 20 | lifter_[n] = 0.54f + 0.46f*cosf(pi2N*n); |
MikamiUitOpen | 0:5c237fdcba23 | 21 | } |
MikamiUitOpen | 0:5c237fdcba23 | 22 | |
MikamiUitOpen | 0:5c237fdcba23 | 23 | CepstrumAnalyzer::~CepstrumAnalyzer() |
MikamiUitOpen | 0:5c237fdcba23 | 24 | { |
MikamiUitOpen | 0:5c237fdcba23 | 25 | delete[] yFft_; |
MikamiUitOpen | 0:5c237fdcba23 | 26 | delete[] lifter_; |
MikamiUitOpen | 0:5c237fdcba23 | 27 | delete[] db_; |
MikamiUitOpen | 0:5c237fdcba23 | 28 | delete[] cep_; |
MikamiUitOpen | 0:5c237fdcba23 | 29 | delete[] cepLft_; |
MikamiUitOpen | 0:5c237fdcba23 | 30 | delete[] cepFt_; |
MikamiUitOpen | 0:5c237fdcba23 | 31 | } |
MikamiUitOpen | 0:5c237fdcba23 | 32 | |
MikamiUitOpen | 0:5c237fdcba23 | 33 | void CepstrumAnalyzer::Analyze(const float xn[], float yn[]) |
MikamiUitOpen | 0:5c237fdcba23 | 34 | { |
MikamiUitOpen | 4:99d4d5ea06a2 | 35 | fft_.Execute(xn, yFft_); // Execute FFT |
MikamiUitOpen | 0:5c237fdcba23 | 36 | |
MikamiUitOpen | 3:7c26b701f363 | 37 | // Translate to dB and to complex |
MikamiUitOpen | 0:5c237fdcba23 | 38 | for (int n=0; n<=N_FFT_/2; n++) |
MikamiUitOpen | 3:7c26b701f363 | 39 | db_[n] = Complex(10.0f*log10f(Norm(yFft_[n])), 0); |
MikamiUitOpen | 3:7c26b701f363 | 40 | |
MikamiUitOpen | 3:7c26b701f363 | 41 | fft_.ExecuteIfft(db_, cep_); // To cepstrum |
MikamiUitOpen | 0:5c237fdcba23 | 42 | |
MikamiUitOpen | 0:5c237fdcba23 | 43 | // Liftering |
MikamiUitOpen | 0:5c237fdcba23 | 44 | cepLft_[0] = cep_[0]; |
MikamiUitOpen | 0:5c237fdcba23 | 45 | for (int n=1; n<N_LIFTER_; n++) |
MikamiUitOpen | 0:5c237fdcba23 | 46 | cepLft_[n] = 2.0f*lifter_[n]*cep_[n]; |
MikamiUitOpen | 0:5c237fdcba23 | 47 | for (int n=N_LIFTER_; n<N_FFT_; n++) |
MikamiUitOpen | 0:5c237fdcba23 | 48 | cepLft_[n] = 0.0f; |
MikamiUitOpen | 0:5c237fdcba23 | 49 | |
MikamiUitOpen | 3:7c26b701f363 | 50 | // Smoothed spectrum |
MikamiUitOpen | 0:5c237fdcba23 | 51 | fft_.Execute(cepLft_, cepFt_); |
MikamiUitOpen | 0:5c237fdcba23 | 52 | for (int n=0; n<=N_FFT_/2; n++) |
MikamiUitOpen | 3:7c26b701f363 | 53 | yn[n] = cepFt_[n].real(); |
MikamiUitOpen | 0:5c237fdcba23 | 54 | } |
MikamiUitOpen | 0:5c237fdcba23 | 55 | } |