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:
7:6598a9b70e5a
Parent:
6:b27ef8d98edc
Child:
8:1f4bc859bc84
--- a/main.cpp	Fri Dec 18 10:09:31 2015 +0000
+++ b/main.cpp	Sun Dec 20 13:38:22 2015 +0000
@@ -2,7 +2,7 @@
 //  Realtime spectrum analyzer
 //      Input: A0 (CN5)
 //
-//  2015/12/18, Copyright (c) 2015 MIKAMI, Naoki
+//  2015/12/20, Copyright (c) 2015 MIKAMI, Naoki
 //------------------------------------------------
 
 #include "button_group.hpp"
@@ -33,11 +33,11 @@
     const uint32_t INACTIVE_TEXT_COLOR = LCD_COLOR_GRAY;
     const uint32_t AXIS_COLOR          = 0xFFCCFFFF;
     const uint32_t LINE_COLOR          = LCD_COLOR_CYAN;
-    
-    LCD_DISCO_F746NG lcd;               // Object for LCD display
-    TS_DISCO_F746NG ts;                 // Object for touch pannel
-    int16_t sn[N_DATA];                 // input buffer
-    Sampler input(A0, FS, N_DATA, sn);  // Object for sampling
+
+    LCD_DISCO_F746NG lcd;           // Object for LCD display
+    TS_DISCO_F746NG ts;             // Object for touch pannel
+    Sampler input(A0, FS, N_DATA);  // Object for sampling
+    int16_t* sn = input.Get();      // input data
 
     lcd.Clear(BACK_COLOR);
 
@@ -69,55 +69,51 @@
     // Linear prediction:   order = 14
     // Cepstral smoothing:  lifter length = 50
     Selector selector(disp, method, N_DATA, N_FFT, 14, 50,
-                      TOUCHED_COLOR);   
+                      TOUCHED_COLOR);
 
     // Wait for "RUN" button touched
     while (!runStop.Touched(0)) {}
+    method.DrawAll(ORIGINAL_COLOR);
 
     // Start of spectrum analyzing
     int inv = 0;    // 0: "NORM", 1: "INV"
     int select = -1;
     while (true)
-    {     
+    {
         if (runStop.GetCurrentColor(0) != TOUCHED_COLOR)
         {
             if (runStop.Touched(0, TOUCHED_COLOR))
             {
-                input.IntrEnable();
-                for (int n=0; n<3; n++)
-                    if (n != select) method.Redraw(n);
+                input.Start();
                 normInv.Draw(inv, TOUCHED_COLOR);
                 normInv.Redraw(1-inv);
             }
             if (method.GetTouchedNumber(select, TOUCHED_COLOR))
                 selector.Execute(sn, select);
         }
-        
+
         if (runStop.GetCurrentColor(0) == TOUCHED_COLOR)
         {
             normInv.GetTouchedNumber(inv, TOUCHED_COLOR);
 
             if (input.Filled())
             {
-                waveDisp.Execute(sn);
-  
-                // spectrum analysis and display
-                selector.Execute(sn, select);   
+                // Restart
+                input.InvertEnable(inv == 1);
+                input.Start();
 
-                // Check "STOP" button touched
-                if (runStop.Touched(1, TOUCHED_COLOR))
-                    normInv.DrawAll(INACTIVE_COLOR,
-                                    INACTIVE_TEXT_COLOR);
-                else    // Restart sampling
-                {
-                    input.InvertEnable(inv == 1);
-                    input.Restart();
-                    input.IntrEnable();
-                }
+                // Waveform display
+                waveDisp.Execute(sn);
+                // Spectrum analysis and display
+                selector.Execute(sn, select);
             }
             else
                 if (method.GetTouchedNumber(select, TOUCHED_COLOR))
                     selector.Execute(sn, select);
+
+            // Check "STOP" button touched
+            if (runStop.Touched(1, TOUCHED_COLOR))
+                normInv.DrawAll(INACTIVE_COLOR, INACTIVE_TEXT_COLOR);
         }
     }
 }