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

Revision:
0:a539141b9dec
diff -r 000000000000 -r a539141b9dec MySpectrogram/LPC_Analyzer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MySpectrogram/LPC_Analyzer.cpp	Fri Feb 17 04:55:10 2017 +0000
@@ -0,0 +1,31 @@
+//-------------------------------------------------------
+//  Class for spectrum analysis using linear prediction
+//
+//  2017/02/11, Copyright (c) 2017 MIKAMI, Naoki
+//-------------------------------------------------------
+
+#include "LPC_Analyzer.hpp"
+
+namespace Mikami
+{
+    LpcAnalyzer::LpcAnalyzer(int nData, int nFft, int order)
+        : AnalyzerBase(nData, nFft, nData-1), order_(order),
+          lp_(nData-1, order),
+          an_(order), xFft_(nFft), yFft_(nFft/2+1) {}
+
+    void LpcAnalyzer::Analyze(const float xn[], float yn[])
+    {
+        float em;
+        lp_.Execute(xn, an_, em);
+
+        // To spectrum
+        xFft_[0] = 1.0f;
+        for (int n=0; n<order_; n++) xFft_[n+1] = -an_[n];
+        for (int n=order_+1; n<N_FFT_; n++) xFft_[n] = 0.0f;
+        fft_.Execute(xFft_, yFft_); // execute FFT
+
+        // Translate to dB
+        for (int n=0; n<=N_FFT_/2; n++)
+            yn[n] = 10.0f*log10f(em/Norm(yFft_[n]));
+    }
+}