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
Diff: main.cpp
- Revision:
- 8:1f4bc859bc84
- Parent:
- 7:6598a9b70e5a
- Child:
- 9:99c55850cb41
--- a/main.cpp Sun Dec 20 13:38:22 2015 +0000 +++ b/main.cpp Mon Dec 28 08:20:34 2015 +0000 @@ -2,7 +2,7 @@ // Realtime spectrum analyzer // Input: A0 (CN5) // -// 2015/12/20, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/28, Copyright (c) 2015 MIKAMI, Naoki //------------------------------------------------ #include "button_group.hpp" @@ -13,20 +13,20 @@ 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 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 x axis of waveform + const int Y_WAV = 36; // Origin for y axis of waveform + const int X0 = 40; // Origin for x axis of spectrum + const int Y0 = 234; // Origin for y axis of spectrum 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 W_DB = 60; // Range in dB to be displayed + const int X0_BTN = 340; // Holizontal position for left of buttons const int FS = 10000; // Sampling frequency: 10 kHz - const uint32_t BACK_COLOR = 0xFF006A6C; // teal green + 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; @@ -37,7 +37,7 @@ 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 + int16_t* sn = input.Get(); // Input data lcd.Clear(BACK_COLOR); @@ -68,7 +68,7 @@ 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, + Selector analyzer(disp, method, N_DATA, N_FFT, 14, 50, TOUCHED_COLOR); // Wait for "RUN" button touched @@ -84,12 +84,12 @@ { if (runStop.Touched(0, TOUCHED_COLOR)) { - input.Start(); + input.Start(inv == 1); normInv.Draw(inv, TOUCHED_COLOR); normInv.Redraw(1-inv); } if (method.GetTouchedNumber(select, TOUCHED_COLOR)) - selector.Execute(sn, select); + analyzer.Execute(sn, select); } if (runStop.GetCurrentColor(0) == TOUCHED_COLOR) @@ -99,17 +99,16 @@ if (input.Filled()) { // Restart - input.InvertEnable(inv == 1); - input.Start(); + input.Start(inv == 1); // Waveform display waveDisp.Execute(sn); // Spectrum analysis and display - selector.Execute(sn, select); + analyzer.Execute(sn, select); } else if (method.GetTouchedNumber(select, TOUCHED_COLOR)) - selector.Execute(sn, select); + analyzer.Execute(sn, select); // Check "STOP" button touched if (runStop.Touched(1, TOUCHED_COLOR))