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

Revision:
8:1f4bc859bc84
Parent:
7:6598a9b70e5a
Child:
12:e5367ab82460
--- a/MyClasses/Sampler.cpp	Sun Dec 20 13:38:22 2015 +0000
+++ b/MyClasses/Sampler.cpp	Mon Dec 28 08:20:34 2015 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  Class for sampling input signal
 //
-//  2015/12/20, Copyright (c) 2015 MIKAMI, Naoki
+//  2015/12/28, Copyright (c) 2015 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "Sampler.hpp"
@@ -10,43 +10,35 @@
 {
     Sampler::Sampler(PinName pin, int fs, int nData)
         : TS_(1000000/fs), N_DATA_(nData), aIn_(pin),
-          xn_(new int16_t[nData]),
+          sn_(new int16_t[nData]),
           buffer_(new int16_t[nData])
     {
-        Rd[0] = &Sampler::ReadNorm; // inphase
-        Rd[1] = &Sampler::ReadInv;  // out-of-phase
-        sw_ = 0;
-        Set(false);
-        for (int n=0; n<nData; n++)
-            buffer_[n] = 32767;
+        for (int n=0; n<nData; n++) sn_[n] = 32767;
     }
 
     Sampler::~Sampler()
     {
-        delete[] xn_;
+        delete[] sn_;
         delete[] buffer_;
     }
 
-    void Sampler::Start()
+    // Start sampling
+    void Sampler::Start(bool onOff)
     {
         count_ = 0;
         filled_ = false;
-        timer_.attach_us(this, &Sampler::Isr, TS_);
-    }
-
-    void Sampler::Set(bool tf)
-    {
         trigger_ = false;
         xnM1_ = 32767;
-        filled_ = tf;
+        Invert(onOff);
+        timer_.attach_us(this, &Sampler::Isr, TS_);
     }
 
     // Interrupt service routine for Ticker
     void Sampler::Isr()
     {
+        int16_t xn = (this->*Rd)(); // Read from A0
         if (!trigger_)
         {
-            int16_t xn = (this->*Rd[sw_])();
             // Detect rising edge
             if ((xn > (xnM1_+512)) && (xn > 2048))
                 trigger_ = true;
@@ -54,14 +46,15 @@
                 xnM1_ = xn;
             return;
         }
-
-        buffer_[count_] = (this->*Rd[sw_])();   // Read from A0
+        else
+            buffer_[count_] = xn;   
 
         if (++count_ >= N_DATA_)
         {
             timer_.detach();
-            Set(true);  // Permits spectrum analysis
-            memcpy(xn_, buffer_, N_DATA_*sizeof(int16_t));
+            memcpy(sn_, buffer_, N_DATA_*sizeof(int16_t));
+            filled_ = true; // Permits spectrum analysis
         }
     }
 }
+