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
main.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2015-12-20
- Revision:
- 7:6598a9b70e5a
- Parent:
- 6:b27ef8d98edc
- Child:
- 8:1f4bc859bc84
File content as of revision 7:6598a9b70e5a:
//------------------------------------------------ // Realtime spectrum analyzer // Input: A0 (CN5) // // 2015/12/20, Copyright (c) 2015 MIKAMI, Naoki //------------------------------------------------ #include "button_group.hpp" #include "Sampler.hpp" #include "WaveformDisplay.hpp" #include "AnalysisSelector.hpp" using namespace Mikami; int main() { const int N_DATA = 260; // number of data to be analyzed const int N_FFT = 512; // number of date for FFT const int X_WAV = 44; // Origin for waveform of x axis const int Y_WAV = 36; // Origin for waveform of y axis const int X0 = 40; // Origin for spectrum of x axis const int Y0 = 234; // Origin for spectrum of y axis const float DB1 = 2.4f; // Pixels for 1 dB const int BIN = 1; // Pixels per bin const int W_DB = 60; // Width in dB to be displayed const int X0_BTN = 340; // Origin for button of x axis const int FS = 10000; // Sampling frequency: 10 kHz const uint32_t BACK_COLOR = 0xFF006A6C; // teal green const uint32_t INACTIVE_COLOR = BACK_COLOR & 0xD0FFFFFF; const uint32_t TOUCHED_COLOR = 0xFF7F7FFF; const uint32_t ORIGINAL_COLOR = 0xFF0068B7; 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 Sampler input(A0, FS, N_DATA); // Object for sampling int16_t* sn = input.Get(); // input data lcd.Clear(BACK_COLOR); // Setting of button group const string RUN_STOP[2] = {"RUN", "STOP"}; ButtonGroup runStop(lcd, ts, X0_BTN, 10, 60, 40, ORIGINAL_COLOR, BACK_COLOR, 2, RUN_STOP, 5, 0, 2); runStop.Draw(1, INACTIVE_COLOR, INACTIVE_TEXT_COLOR); const string NORM_INV[2] = {"NORM", "INV"}; ButtonGroup normInv(lcd, ts, X0_BTN, 65, 60, 40, ORIGINAL_COLOR, BACK_COLOR, 2, NORM_INV, 5, 0, 2); normInv.DrawAll(INACTIVE_COLOR, INACTIVE_TEXT_COLOR); const string METHOD[3] = {"FFT", "Linear Pred.", "Cepstrum"}; ButtonGroup method(lcd, ts, X0_BTN, 120, 125, 40, ORIGINAL_COLOR, BACK_COLOR, 3, METHOD, 0, 5, 1); method.DrawAll(INACTIVE_COLOR, INACTIVE_TEXT_COLOR); // End of button group setting WaveformDisplay waveDisp(lcd, X_WAV, Y_WAV, N_DATA, 10, AXIS_COLOR, LINE_COLOR, BACK_COLOR); SpectrumDisplay disp(lcd, N_FFT, X0, Y0, DB1, BIN, W_DB, FS, AXIS_COLOR, LINE_COLOR, BACK_COLOR); // Linear prediction: order = 14 // Cepstral smoothing: lifter length = 50 Selector selector(disp, method, N_DATA, N_FFT, 14, 50, 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.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()) { // Restart input.InvertEnable(inv == 1); input.Start(); // 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); } } }