Realtime sound spectrogram using FFT or linear prediction. Spectrogram is displayed on the display of PC. リアルタイム・スペクトログラム.解析の手法:FFT,線形予測法.スペクトログラムは PC のディスプレー装置に表示される.PC 側のプログラム:F446_Spectrogram.

Dependencies:   Array_Matrix mbed SerialTxRxIntr F446_AD_DA UIT_FFT_Real

Committer:
MikamiUitOpen
Date:
Fri Feb 17 04:55:10 2017 +0000
Revision:
0:a539141b9dec
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:a539141b9dec 1 //-------------------------------------------------------
MikamiUitOpen 0:a539141b9dec 2 // Class for spectrum analysis using linear prediction
MikamiUitOpen 0:a539141b9dec 3 //
MikamiUitOpen 0:a539141b9dec 4 // 2017/02/11, Copyright (c) 2017 MIKAMI, Naoki
MikamiUitOpen 0:a539141b9dec 5 //-------------------------------------------------------
MikamiUitOpen 0:a539141b9dec 6
MikamiUitOpen 0:a539141b9dec 7 #include "LPC_Analyzer.hpp"
MikamiUitOpen 0:a539141b9dec 8
MikamiUitOpen 0:a539141b9dec 9 namespace Mikami
MikamiUitOpen 0:a539141b9dec 10 {
MikamiUitOpen 0:a539141b9dec 11 LpcAnalyzer::LpcAnalyzer(int nData, int nFft, int order)
MikamiUitOpen 0:a539141b9dec 12 : AnalyzerBase(nData, nFft, nData-1), order_(order),
MikamiUitOpen 0:a539141b9dec 13 lp_(nData-1, order),
MikamiUitOpen 0:a539141b9dec 14 an_(order), xFft_(nFft), yFft_(nFft/2+1) {}
MikamiUitOpen 0:a539141b9dec 15
MikamiUitOpen 0:a539141b9dec 16 void LpcAnalyzer::Analyze(const float xn[], float yn[])
MikamiUitOpen 0:a539141b9dec 17 {
MikamiUitOpen 0:a539141b9dec 18 float em;
MikamiUitOpen 0:a539141b9dec 19 lp_.Execute(xn, an_, em);
MikamiUitOpen 0:a539141b9dec 20
MikamiUitOpen 0:a539141b9dec 21 // To spectrum
MikamiUitOpen 0:a539141b9dec 22 xFft_[0] = 1.0f;
MikamiUitOpen 0:a539141b9dec 23 for (int n=0; n<order_; n++) xFft_[n+1] = -an_[n];
MikamiUitOpen 0:a539141b9dec 24 for (int n=order_+1; n<N_FFT_; n++) xFft_[n] = 0.0f;
MikamiUitOpen 0:a539141b9dec 25 fft_.Execute(xFft_, yFft_); // execute FFT
MikamiUitOpen 0:a539141b9dec 26
MikamiUitOpen 0:a539141b9dec 27 // Translate to dB
MikamiUitOpen 0:a539141b9dec 28 for (int n=0; n<=N_FFT_/2; n++)
MikamiUitOpen 0:a539141b9dec 29 yn[n] = 10.0f*log10f(em/Norm(yFft_[n]));
MikamiUitOpen 0:a539141b9dec 30 }
MikamiUitOpen 0:a539141b9dec 31 }