Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed
main.cpp
00001 //----------------------------------------------------------- 00002 // Demo waveform and spectrum display 00003 // Tap the screen to begin the spectrum analyzer 00004 // No photo version of "F746_SpectralAnalysis_Example" 00005 // 00006 // 2015/11/24, Copyright (c) 2015 MIKAMI, Naoki 00007 //----------------------------------------------------------- 00008 00009 #include "vowel_data.hpp" 00010 #include "button_group.hpp" 00011 #include "waveform_display.hpp" 00012 #include "FFT_Analysis.hpp" 00013 #include "SpectrumDisplay.hpp" 00014 #include "LPC_Analysis.hpp" 00015 00016 using namespace Mikami; 00017 00018 const int N_FFT_ = 512; // number of date for FFT 00019 const int X0_ = 50; // Origin for x axis 00020 const int Y0_ = 236; // Origin for y axis 00021 const float DB1_ = 2.4f; // Pixels for 1 dB 00022 const int BIN_ = 1; // Pixels per bin 00023 const int W_DB = 60; // Width in dB to be displayed 00024 00025 const int FS_ = 8000; // Sampling frequency: 8 kHz 00026 00027 LCD_DISCO_F746NG lcd_; 00028 TS_DISCO_F746NG ts_; 00029 00030 FftAnalyzer fft_(N_DATA_, N_FFT_); // using FFT 00031 LpcAnalyzer lpc_(N_DATA_, 10, N_FFT_); // using linear prediction 00032 00033 int main() 00034 { 00035 int16_t sn[N_DATA_]; 00036 float sn_f[N_DATA_]; 00037 float db1[N_FFT_/2+1]; // Log powerspectrum using FFT 00038 float db2[N_FFT_/2+1]; // Log powerspectrum using linear prediction 00039 00040 uint32_t backColor = 0xFF006A6C; // teal green 00041 lcd_.Clear(backColor); 00042 00043 const string AIUEO[5] = {"/a/", "/i/", "/u/", "/e/", "/o/"}; 00044 ButtonGroup aiueo(lcd_, ts_, 430, 15, 50, 40, 00045 LCD_COLOR_BLUE, backColor, 00046 5, AIUEO, 0, 10, 1, Font16); 00047 00048 const string METHOD[3] = {"FFT (Bar)", "FFT (Line)", "LP"}; 00049 ButtonGroup method(lcd_, ts_, 340, 15, 80, 40, 00050 LCD_COLOR_BLUE, backColor, 00051 3, METHOD, 0, 10, 1, Font12); 00052 uint32_t inActive = backColor & 0xD0FFFFFF; 00053 for (int n=0; n<3; n++) method.Draw(n, inActive, LCD_COLOR_LIGHTGRAY); 00054 00055 SpectrumDisplay disp(lcd_, N_FFT_, X0_, Y0_, DB1_, BIN_, W_DB, FS_); 00056 bool dataOk = false; 00057 while (true) 00058 { 00059 int vowel; 00060 if (aiueo.GetTouchedNumber(vowel, 0xFF0000B0)) 00061 { 00062 for (int n=0; n<N_DATA_; n++) sn[n] = sn_[vowel][n]; 00063 WaveformDisplay(lcd_, 50, 40, sn, N_DATA_, backColor); 00064 00065 for (int n=0; n<N_DATA_; n++) sn_f[n] = sn[n]; 00066 fft_.Execute(sn_f, db1); 00067 lpc_.Execute(sn_f, db2); 00068 dataOk = true; 00069 disp.Clear(backColor); 00070 for (int n=0; n<3; n++) method.Redraw(n); 00071 } 00072 00073 if (dataOk) 00074 { 00075 int k; 00076 if (method.GetTouchedNumber(k, 0xFF0000B0)) 00077 { 00078 switch (k) 00079 { 00080 case 0: disp.BarChart(db1, backColor); 00081 break; 00082 case 1: disp.LineChart(db1, backColor); 00083 break; 00084 case 2: disp.LineChart(db2, backColor); 00085 break; 00086 } 00087 } 00088 } 00089 wait(0.1); 00090 } 00091 }
Generated on Mon Jul 18 2022 10:22:00 by
1.7.2