No photo version of "F746_SpectralAnalysis_Example".

Dependencies:   BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Tue Nov 24 12:34:55 2015 +0000
Commit message:
1

Changed in this revision

BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
BUTTON_GROUP.lib Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/FFT_Analysis.cpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/FFT_Analysis.hpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/Hamming.hpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/LPC_Analysis.cpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/LPC_Analysis.hpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/LinearPrediction.cpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/LinearPrediction.hpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/SpectrumDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
SpactrumAnalysisClasses/SpectrumDisplay.hpp Show annotated file Show diff for this revision Revisions of this file
TS_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
UIT_FFT_Real.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
my_class_and_function/waveform_display.hpp Show annotated file Show diff for this revision Revisions of this file
vowel_data.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9d7f931c704a BSP_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG.lib	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/#c9112f0c67e3
diff -r 000000000000 -r 9d7f931c704a BUTTON_GROUP.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BUTTON_GROUP.lib	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MikamiUitOpen/code/BUTTON_GROUP/#d99d9c0324b7
diff -r 000000000000 -r 9d7f931c704a LCD_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F746NG.lib	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/FFT_Analysis.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/FFT_Analysis.cpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,53 @@
+//-------------------------------------------------------
+// Class for spectrum analysis using FFT
+// Copyright (c) 2015 MIKAMI, Naoki,  2015/10/26
+//-------------------------------------------------------
+
+#include "FFT_Analysis.hpp"
+
+namespace Mikami
+{
+    FftAnalyzer::FftAnalyzer(int nData, int nFft)
+            : N_DATA_(nData), N_FFT_(nFft),
+              hm_(nData-1, nFft), fft_(nFft)
+    {
+        xData = new float[nData];       // Data to be analyzed
+        xFft = new float[nFft];         // Input for FFT
+        yFft = new Complex[nFft/2+1];   // Output of FFT
+        normY = new float[nFft/2+1];    // Powerspectrum
+    }
+   
+    FftAnalyzer::~FftAnalyzer()
+    {
+        delete[] xData;
+        delete[] xFft;
+        delete[] yFft;
+        delete[] normY;
+    }
+
+    void FftAnalyzer::Execute(float xn[], float db[])
+    {
+        // Differencing
+        for (int n=0; n<N_DATA_-1; n++)
+            xData[n] = xn[n+1] - xn[n];
+
+        hm_.Execute(xData, xFft);    // Windowing and zero-padding
+        fft_.Execute(xFft, yFft);    // Execute FFT
+
+        // Squared magnitude
+        for (int n=0; n<=N_FFT_/2; n++)
+            normY[n] = Sqr(yFft[n].real()) + Sqr(yFft[n].imag());
+            
+        // Search maximum
+        float max = 0;
+        for (int n=0; n<=N_FFT_/2; n++)
+            max = (max > normY[n]) ? max : normY[n];
+        float invMax = 1.0f/max;
+
+        // Translate to dB
+        for (int n=0; n<=N_FFT_/2; n++)
+            db[n] = 10.0f*log10f(invMax*normY[n]);
+    }
+}
+
+
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/FFT_Analysis.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/FFT_Analysis.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,38 @@
+//-------------------------------------------------------
+// Class for spectrum analysis using FFT (Header)
+// Copyright (c) 2015 MIKAMI, Naoki,  2015/10/26
+//-------------------------------------------------------
+
+#ifndef FFT_ANALYZER_HPP
+#define FFT_ANALYZER_HPP
+
+#include "fftReal.hpp"
+#include "Hamming.hpp"
+
+namespace Mikami
+{
+    class FftAnalyzer
+    {
+    public:
+        FftAnalyzer(int nData, int nFft);
+        ~FftAnalyzer();
+        void Execute(float xn[], float db[]);
+
+    private:
+        const int N_DATA_;
+        const int N_FFT_;
+
+        HammingWindow hm_;
+        FftReal fft_;
+
+        float* xData;   // Data to be analyzed
+        float* xFft;    // Input for FFT
+        Complex* yFft;  // Output of FFT
+        float* normY;   // Powerspectrum
+
+        float Sqr(float x) { return x*x; }
+    };
+}
+
+#endif  // FFT_ANALYZER_HPP
+
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/Hamming.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/Hamming.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,44 @@
+//-------------------------------------------------------------------
+// Hamming windowing with zero-padding
+// Copyright (c) 2014 MIKAMI, Naoki,  2014/12/21
+//-------------------------------------------------------------------
+
+#ifndef HAMMING_WINDOW_HPP
+#define HAMMING_WINDOW_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    class HammingWindow
+    {
+    private:
+        const int N_;
+        const int NFFT_;
+                
+        float* w_;
+
+    public:
+        // Constructor
+        HammingWindow(uint16_t nData, uint16_t nFft)
+                : N_(nData), NFFT_(nFft)
+        {
+            w_ = new float[nData];
+            float pi2L = 6.283185f/(float)nData;
+            for (int k=0; k<nData; k++)
+                w_[k] = 0.54f - 0.46f*cosf(k*pi2L);
+        }
+        
+        // Destructor
+        ~HammingWindow() {delete[] w_;}
+        
+        // Windowing
+        void Execute(const float x[], float y[])
+        {
+            for (int n=0; n<N_; n++) y[n] = x[n]*w_[n];
+            for (int n=N_; n<NFFT_; n++) y[n] = 0;
+        }
+    };
+}
+#endif  // HAMMING_WINDOW_HPP
+
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/LPC_Analysis.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/LPC_Analysis.cpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,62 @@
+//-------------------------------------------------------
+// Class for spectrum analysis using linear prediction
+// Copyright (c) 2015 MIKAMI, Naoki,  2015/10/26
+//-------------------------------------------------------
+
+#include "LPC_Analysis.hpp"
+
+namespace Mikami
+{
+    LpcAnalyzer::LpcAnalyzer(int nData, int order, int nFft)
+        : N_DATA_(nData), ORDER_(order), N_FFT_(nFft),
+          hm_(nData-1, nData-1), lp_(nData-1, order),
+          fft_(nFft)
+    {
+        xData_ = new float[nData];      // Data to be analyzed
+        an_ = new float[order];         // Linear-predictive coefficients
+        xFft_ = new float[nFft];        // Input for FFT
+        yFft_ = new Complex[nFft/2+1];  // Output of FFT
+        normY_ = new float[nFft/2+1];   // Powerspectrum
+    }
+
+    LpcAnalyzer::~LpcAnalyzer()
+    {
+        delete[] xData_;
+        delete[] an_;
+        delete[] xFft_;
+        delete[] yFft_;
+        delete[] normY_;
+    }
+
+    void LpcAnalyzer::Execute(float xn[], float db[])
+    {
+        // Differencing
+        for (int n=0; n<N_DATA_-1; n++)
+            xData_[n] = xn[n+1] - xn[n];
+
+        hm_.Execute(xData_, xData_); // Windowing
+        float em;
+        lp_.Execute(xData_, an_, em);
+
+        // To spectrum
+        xFft_[0] = 1.0f;
+        for (int n=0; n<ORDER_; n++) xFft_[n+1] = -an_[n];
+        for (int n=ORDER_+1; n<N_FFT_; n++) xFft_[n] = 0.0f;
+        fft_.Execute(xFft_, yFft_); // Execute FFT
+
+        // Squared magnitude
+        for (int n=0; n<=N_FFT_/2; n++)
+            normY_[n] = 1.0f/(Sqr(yFft_[n].real()) + Sqr(yFft_[n].imag()));
+
+        // Search maximum
+        float max = 0;
+        for (int n=0; n<=N_FFT_/2; n++)
+            max = (max > normY_[n]) ? max : normY_[n];
+        float invMax = 1.0f/max;
+
+        // Translate to dB
+        for (int n=0; n<=N_FFT_/2; n++)
+            db[n] = 10.0f*log10f(invMax*normY_[n]);
+    }
+}
+
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/LPC_Analysis.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/LPC_Analysis.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,40 @@
+//---------------------------------------------------------------
+// Class for spectrum analysis using linear prediction (Header)
+// Copyright (c) 2014 MIKAMI, Naoki,  2014/12/30
+//---------------------------------------------------------------
+
+#ifndef LPC_ANALYZER_HPP
+#define LPC_ANALYZER_HPP
+
+#include "fftReal.hpp"
+#include "Hamming.hpp"
+#include "LinearPrediction.hpp"
+
+namespace Mikami
+{
+    class LpcAnalyzer
+    {
+    public:
+        LpcAnalyzer(int nData, int order, int nFft);
+        ~LpcAnalyzer();
+        void Execute(float xn[], float db[]);
+    private:
+        const int N_DATA_;
+        const int ORDER_;
+        const int N_FFT_;
+
+        HammingWindow hm_;
+        LinearPred lp_;
+        FftReal fft_;
+
+        float* xData_;   // Data to be analyzed
+        float* an_;
+        float* xFft_;    // Input for FFT
+        Complex* yFft_;  // Output of FFT
+        float* normY_;   // Powerspectrum
+
+        float Sqr(float x) { return x*x; }
+    };
+}
+#endif  // LPC_ANALYZER_HPP
+
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/LinearPrediction.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/LinearPrediction.cpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,72 @@
+//-----------------------------------------------------
+// Class for linear prediction
+// Copyright (c) 2014 MIKAMI, Naoki,  2014/12/30
+//-----------------------------------------------------
+
+#include "LinearPrediction.hpp"
+
+namespace Mikami
+{
+    LinearPred::LinearPred(int nData, int order)
+        : N_DATA_(nData), ORDER_(order)
+    {
+        r_ = new float[order+1];    // for auto-correlation
+        k_ = new float[order];      // for PARCOR coefficients
+        am_ = new float[order];     // working area
+    }
+
+    LinearPred::~LinearPred()
+    {
+        delete[] r_;
+        delete[] k_;
+        delete[] am_;
+    }
+
+    // Calculate linear-predictive coefficients
+    bool LinearPred::Execute(const float x[], float a[],
+                             float &em)
+    {
+        AutoCorr(x);
+        return Durbin(a, em);
+    }
+
+    // Calculate auto-correlation
+    void LinearPred::AutoCorr(const float x[])
+    {
+        for (int j=0; j<=ORDER_; j++)
+        {
+            r_[j] = 0.0;
+            for (int n=0; n<N_DATA_-j; n++)
+                r_[j] = r_[j] + x[n]*x[n+j];
+        }
+    }
+
+    // Levinson-Durbin algorithm
+    bool LinearPred::Durbin(float a[], float &em)
+    {
+        // Initialization
+        em = r_[0];
+
+        // Repeat
+        for (int m=0; m<ORDER_; m++)
+        {
+            float w = r_[m+1];
+            for (int j=0; j<=m-1; j++)
+                w = w - r_[m-j]*a[j];
+
+            k_[m] = w/em;
+            em = em*(1 - k_[m]*k_[m]);
+
+            if (em < 0) break;      // Error for negative squared sum of residual
+
+            a[m] = k_[m];
+            for (int j=0; j<=m-1; j++)
+                am_[j] = a[j];
+            for (int j=0; j<=m-1; j++)
+                a[j] = am_[j] - k_[m]*am_[m-j-1];
+        }
+
+        if (em < 0) return false;
+        else        return true;
+    }
+}
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/LinearPrediction.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/LinearPrediction.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,31 @@
+//-----------------------------------------------------
+// Class for linear prediction (Header)
+// Copyright (c) 2014 MIKAMI, Naoki,  2014/12/30
+//-----------------------------------------------------
+
+#ifndef LINEAR_PREDICTION_HPP
+#define LINEAR_PREDICTION_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    class LinearPred
+    {
+    public:
+        LinearPred(int nData, int order);
+        ~LinearPred();
+        bool Execute(const float x[], float a[], float &em);
+    public:
+        const uint16_t N_DATA_;
+        const uint16_t ORDER_;
+
+        float* r_;
+        float* k_;
+        float* am_;
+
+        void AutoCorr(const float x[]);
+        bool Durbin(float a[], float &em);
+    };
+}
+#endif  // LINEAR_PREDICTION_HPP
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/SpectrumDisplay.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/SpectrumDisplay.cpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,106 @@
+//-------------------------------------------------------
+// Class for display spectrum
+// Copyright (c) 2015 MIKAMI, Naoki,  2015/10/27
+//-------------------------------------------------------
+
+#include "SpectrumDisplay.hpp"
+
+namespace Mikami
+{
+    SpectrumDisplay::SpectrumDisplay(
+            LCD_DISCO_F746NG &lcd,
+            int nFft, int x0, int y0,
+            float db1, int bin, float maxDb, int fs)
+        : N_FFT_(nFft), X0_(x0), Y0_(y0),
+          DB1_(db1), BIN_(bin), MAX_DB_(maxDb), FS_(fs),
+          LCD_(&lcd)
+    {
+        AxisX();
+        AxisY();
+    }
+
+    void SpectrumDisplay::BarChart(float db[], uint32_t backColor)
+    {
+        const float OFFSET = 60.0f;
+        for (int n=1; n<=N_FFT_/2; n++)
+        {
+            float h = ((db[n] + OFFSET) >= 0)? db[n] + OFFSET : 0;
+            
+            int y = Y0_ - (int)(h*DB1_);
+            LCD_->SetTextColor(LCD_COLOR_CYAN);
+            LCD_->DrawLine(X0_+n, Y0_-1, X0_+n, y);
+            LCD_->SetTextColor(backColor);
+            LCD_->DrawLine(X0_+n, y-1, X0_+n, Y0_-(int)(MAX_DB_*DB1_));
+        }
+        LCD_->SetTextColor(LCD_COLOR_YELLOW);
+        LCD_->DrawLine(X0_, Y0_, X0_+BIN_*N_FFT_/2, Y0_);
+    }
+
+    void SpectrumDisplay::LineChart(float db[], uint32_t backColor)
+    {
+        const float OFFSET = 60.0f;
+        LCD_->SetTextColor(backColor);
+        LCD_->FillRect(X0_+1, Y0_-(int)(MAX_DB_*DB1_),
+                       N_FFT_*BIN_/2, MAX_DB_*DB1_);
+
+        float h = ((db[1] + OFFSET) > 0)? db[1] + OFFSET : 0;
+        int y1 = Y0_ - (int)(h*DB1_);
+        for (int n=1; n<N_FFT_/2; n++)
+        {
+            float h2 = ((db[n+1] + OFFSET) > 0)? db[n+1] + OFFSET : 0;
+            if (h2 > MAX_DB_) h2 = MAX_DB_;
+            int y2 = Y0_ - (int)(h2*DB1_);
+            LCD_->SetTextColor(LCD_COLOR_CYAN);
+            LCD_->DrawLine(X0_+n, y1, X0_+n+1, y2);
+            y1 = y2;
+        }
+        LCD_->SetTextColor(LCD_COLOR_YELLOW);
+        LCD_->DrawLine(X0_, Y0_, X0_+BIN_*N_FFT_/2, Y0_);
+    }
+
+    // Clear Spectrum
+    void SpectrumDisplay::Clear(uint32_t backColor)
+    {
+        LCD_->SetTextColor(backColor);
+        LCD_->FillRect(X0_+1, Y0_-(int)(MAX_DB_*DB1_),
+                       N_FFT_*BIN_/2, MAX_DB_*DB1_);
+    }
+
+    // x-axis
+    void SpectrumDisplay::AxisX()
+    {
+        LCD_->SetFont(&Font12);
+
+        LCD_->SetTextColor(LCD_COLOR_YELLOW);
+        LCD_->DrawLine(X0_, Y0_, X0_+BIN_*N_FFT_/2, Y0_);
+        float dx = BIN_*(N_FFT_*1000.0f)/(float)FS_;
+        for (int n=0; n<=(FS_/1000)/2; n++)
+        {
+            int xTick = X0_ + (int)(dx*n + 0.5f);
+            char s[5];
+            sprintf(s, "%d", n);
+            LCD_->DisplayStringAt(xTick-3, Y0_+10, (uint8_t *)s, LEFT_MODE);
+            LCD_->DrawLine(xTick, Y0_, xTick, Y0_+5);
+        }
+        LCD_->DisplayStringAt(X0_+74, Y0_+24, (uint8_t *)"Frequency [kHz]", LEFT_MODE);
+    }
+
+    // y-axis
+    void SpectrumDisplay::AxisY()
+    {
+        LCD_->SetFont(&Font12);
+        
+        LCD_->SetTextColor(LCD_COLOR_YELLOW);
+        LCD_->DrawLine(X0_, Y0_+5, X0_, Y0_-(int)(MAX_DB_*DB1_));
+        for (int n=0; n<=(int)MAX_DB_; n+=20)
+        {
+            int yTick = Y0_-(int)(DB1_*n);
+            char s[5];
+            sprintf(s, "%3d", n-60);
+            LCD_->DisplayStringAt(X0_-30, yTick-5, (uint8_t *)s, LEFT_MODE);
+            LCD_->DrawLine(X0_-5, yTick, X0_, yTick);
+        }
+        LCD_->DisplayStringAt(X0_-27, Y0_-(int)(DB1_*MAX_DB_)-18, (uint8_t *)"[dB]", LEFT_MODE);
+    }
+}
+
diff -r 000000000000 -r 9d7f931c704a SpactrumAnalysisClasses/SpectrumDisplay.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpactrumAnalysisClasses/SpectrumDisplay.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,38 @@
+//-------------------------------------------------------
+// Class for display spectrum
+// Copyright (c) 2015 MIKAMI, Naoki,  2015/10/26
+//-------------------------------------------------------
+
+#ifndef SPECTRUM_DISPLAY_HPP
+#define SPECTRUM_DISPLAY_HPP
+
+#include "LCD_DISCO_F746NG.h"
+
+namespace Mikami
+{
+    class SpectrumDisplay
+    {
+    public:
+        SpectrumDisplay(LCD_DISCO_F746NG &lcd,
+                        int nFft, int x0, int y0,
+                        float db1, int bin, float maxDb, int fs);
+        void BarChart(float db[], uint32_t backColor);
+        void LineChart(float db[], uint32_t backColor);
+        void Clear(uint32_t backColor);
+
+    private:
+        const int N_FFT_;       // number of date for FFT
+        const int X0_;          // Origin for x axis
+        const int Y0_;          // Origin for y axis
+        const float DB1_;       // Pixels for 1 dB
+        const int BIN_;         // Pixels per bin
+        const float MAX_DB_;    // Maximum dB
+        const int FS_;          // Sampling frequency: 10 kHz
+
+        LCD_DISCO_F746NG *const LCD_;
+
+        void AxisX();       // x-axis
+        void AxisY();       // y-axis
+    };
+}
+#endif  // SPECTRUM_DISPLAY_HPP
diff -r 000000000000 -r 9d7f931c704a TS_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TS_DISCO_F746NG.lib	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/TS_DISCO_F746NG/#fe0cf5e2960f
diff -r 000000000000 -r 9d7f931c704a UIT_FFT_Real.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UIT_FFT_Real.lib	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MikamiUitOpen/code/UIT_FFT_Real/#559a63853f3f
diff -r 000000000000 -r 9d7f931c704a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,91 @@
+//-----------------------------------------------------------
+//  Demo waveform and spectrum display
+//      Tap the screen to begin the spectrum analyzer 
+//  No photo version of "F746_SpectralAnalysis_Example"
+//
+//  2015/11/24, Copyright (c) 2015 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#include "vowel_data.hpp"
+#include "button_group.hpp"
+#include "waveform_display.hpp"
+#include "FFT_Analysis.hpp"
+#include "SpectrumDisplay.hpp"
+#include "LPC_Analysis.hpp"
+
+using namespace Mikami;
+
+const int N_FFT_ = 512;     // number of date for FFT
+const int X0_ = 50;         // Origin for x axis
+const int Y0_ = 236;        // Origin for 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 FS_ = 8000;       // Sampling frequency: 8 kHz
+
+LCD_DISCO_F746NG lcd_;
+TS_DISCO_F746NG ts_;
+
+FftAnalyzer fft_(N_DATA_, N_FFT_);      // using FFT
+LpcAnalyzer lpc_(N_DATA_, 10, N_FFT_);  // using linear prediction
+
+int main()
+{
+    int16_t sn[N_DATA_];
+    float sn_f[N_DATA_];
+    float db1[N_FFT_/2+1];  // Log powerspectrum using FFT
+    float db2[N_FFT_/2+1];  // Log powerspectrum using linear prediction
+
+    uint32_t backColor = 0xFF006A6C;            // teal green
+    lcd_.Clear(backColor);
+
+    const string AIUEO[5] = {"/a/", "/i/", "/u/", "/e/", "/o/"};
+    ButtonGroup aiueo(lcd_, ts_, 430, 15, 50, 40,
+                      LCD_COLOR_BLUE, backColor,
+                      5, AIUEO, 0, 10, 1, Font16);
+
+    const string METHOD[3] = {"FFT (Bar)", "FFT (Line)", "LP"};
+    ButtonGroup method(lcd_, ts_, 340, 15, 80, 40,
+                       LCD_COLOR_BLUE, backColor,
+                       3, METHOD, 0, 10, 1, Font12);
+    uint32_t inActive = backColor & 0xD0FFFFFF;
+    for (int n=0; n<3; n++) method.Draw(n, inActive, LCD_COLOR_LIGHTGRAY);
+
+    SpectrumDisplay disp(lcd_, N_FFT_, X0_, Y0_, DB1_, BIN_, W_DB, FS_);
+    bool dataOk = false;
+    while (true)
+    {
+        int vowel;
+        if (aiueo.GetTouchedNumber(vowel, 0xFF0000B0))
+        {
+            for (int n=0; n<N_DATA_; n++) sn[n] = sn_[vowel][n];
+                WaveformDisplay(lcd_, 50, 40, sn, N_DATA_, backColor);
+
+            for (int n=0; n<N_DATA_; n++) sn_f[n] = sn[n];
+            fft_.Execute(sn_f, db1);
+            lpc_.Execute(sn_f, db2);
+            dataOk = true;
+            disp.Clear(backColor);
+            for (int n=0; n<3; n++) method.Redraw(n);
+        }
+
+        if (dataOk)
+        {
+            int k;
+            if (method.GetTouchedNumber(k, 0xFF0000B0))
+            {
+                switch (k)
+                {
+                    case 0: disp.BarChart(db1, backColor);
+                            break;
+                    case 1: disp.LineChart(db1, backColor);
+                            break;
+                    case 2: disp.LineChart(db2, backColor);
+                            break;
+                }   
+            }
+        }
+        wait(0.1);
+    }
+}
diff -r 000000000000 -r 9d7f931c704a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file
diff -r 000000000000 -r 9d7f931c704a my_class_and_function/waveform_display.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/my_class_and_function/waveform_display.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,36 @@
+//-----------------------------------------------------------
+//  Function for waveform display
+//
+//  2015/10/26, Copyright (c) 2015 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#ifndef F746_WAVEFORM_DISPLAY_HPP
+#define F746_WAVEFORM_DISPLAY_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    void WaveformDisplay(LCD_DISCO_F746NG &lcd, uint16_t x0, uint16_t y0,
+                         int16_t xn[], int nData, uint32_t backColor)
+    {
+        lcd.SetTextColor(backColor);
+        lcd.FillRect(x0, y0-32, nData, 64);
+
+        lcd.SetTextColor(LCD_COLOR_BLUE);
+        lcd.DrawLine(x0-5, y0, x0+nData+5, y0);
+        
+        lcd.SetTextColor(LCD_COLOR_CYAN);
+        uint16_t x1 = x0;
+        uint16_t y1 = y0 - (xn[0] >> 9);
+        for (int n=1; n<nData; n++)
+        {
+            uint16_t x2 = x0 + n;
+            uint16_t y2 = y0 - (xn[n] >> 9);
+            lcd.DrawLine(x1, y1, x2, y2);
+            x1 = x2;
+            y1 = y2;
+        }
+    }
+}
+#endif  // F746_WAVEFORM_DISPLAY_HPP
\ No newline at end of file
diff -r 000000000000 -r 9d7f931c704a vowel_data.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vowel_data.hpp	Tue Nov 24 12:34:55 2015 +0000
@@ -0,0 +1,147 @@
+//-----------------------------------------------------------
+//  Data /a/, /i/, /u/, /e/, /o/, uttered by Mikami
+//
+//  2015/10/25, Copyright (c) 2015 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#include "mbed.h"
+
+const int N_DATA_ = 260;
+const int N_VOWEL_ = 5;
+    
+int16_t sn_[N_VOWEL_][N_DATA_] = {
+// /a/
+    {   678,   1808,   3163,   3687,   3159,   2025,   1091,   1040,   1831,   2507,
+       2433,   1386,   -420,  -2049,  -2857,  -2848,  -2281,  -1523,  -1327,  -1532,
+      -1968,  -2404,  -2646,  -2197,   -306,   3093,   6833,   8946,   8288,   4647,
+       -199,  -4034,  -5234,  -3905,  -1060,   1633,   3212,   4051,   4495,   4809,
+       4877,   3846,   1386,  -1842,  -4461,  -5158,  -3298,    269,   3922,   6130,
+       6098,   4531,   2626,   1311,    884,    792,    436,    -56,   -134,    476,
+       1798,   2939,   3135,   2392,   1240,    467,    579,   1252,   1681,   1365,
+        142,  -1530,  -2915,  -3578,  -3352,  -2750,  -2218,  -2018,  -2286,  -2896,
+      -3377,  -3499,  -2855,   -635,   2966,   6380,   8099,   6898,   3012,  -1708,
+      -5052,  -5923,  -4354,  -1508,   1004,   2609,   3391,   3846,   4227,   4138,
+       2834,    213,  -3008,  -5436,  -5669,  -3446,    227,   3759,   5572,   5178,
+       3373,   1654,    901,    943,    963,    388,   -490,   -992,   -232,   1375,
+       2812,   3216,   2481,   1327,    577,    706,   1308,   1598,   1057,   -247,
+      -1753,  -2874,  -3289,  -3013,  -2389,  -1783,  -1610,  -1981,  -2666,  -3301,
+      -3589,  -2802,   -558,   3267,   7097,   9035,   8017,   4154,   -890,  -4616,
+      -5651,  -4204,  -1228,   1602,   3432,   4355,   4871,   5181,   5052,   3729,
+        951,  -2437,  -4982,  -5382,  -3069,    862,   4649,   6790,   6670,   4897,
+       2809,   1377,    860,    749,    472,    188,    337,   1172,   2574,   3758,
+       3921,   2999,   1744,    986,   1137,   1885,   2344,   1974,    687,  -1042,
+      -2436,  -3047,  -2838,  -2123,  -1442,  -1118,  -1367,  -2042,  -2834,  -3323,
+      -2991,  -1279,   2114,   6037,   8593,   8470,   5262,    451,  -3798,  -5608,
+      -4777,  -2136,    709,   2779,   3903,   4464,   4848,   4862,   3791,   1264,
+      -2119,  -4993,  -5966,  -4310,   -737,   3167,   5689,   5993,   4481,   2470,
+        896,    244,    208,      2,   -452,   -560,    -47,   1151,   2509,   3011,
+       2452,   1363,    489,    415,   1026,   1439,   1141,     73,  -1534,  -2913,
+      -3581,  -3487,  -2929,  -2356,  -2052,  -2109,  -2577,  -3219,  -3602,  -3788},
+// /i/
+    { -1649,   1006,   2359,   5814,   7821,  10065,  10793,  13247,  12944,  13648,
+      12191,  12374,  10170,   8621,   6120,   4951,   1836,    117,  -1743,  -2352,
+      -1343,  -3370,  -1563,    731,   1114,   2068,   5869,   6335,   7771,   8996,
+      10433,  10239,   9595,   9078,   8717,   5589,   3599,   2183,   -958,  -3681,
+      -5139,  -6796,  -8692,  -9700, -10177, -10381, -11287, -10315, -10015, -10304,
+      -9530,  -8301,  -9153,  -8280,  -8282,  -8982,  -8445,  -8536,  -9077,  -8069,
+      -7978,  -6972,  -4852,  -3858,   -277,    893,   3951,   6416,   8904,   9740,
+      12556,  12688,  13471,  13142,  12616,  11593,   9863,   7715,   6153,   3893,
+       1203,     35,   -980,   -784,  -2811,  -1108,    117,    627,   1403,   4654,
+       5294,   6707,   8190,   9684,   9589,   9342,   9279,   8697,   6356,   4626,
+       3192,    185,  -2059,  -3712,  -5514,  -7488,  -8447,  -9413,  -9851, -10692,
+     -10151,  -9957,  -9887,  -9672,  -8567,  -8342,  -8555,  -8256,  -8371,  -8705,
+      -8264,  -9071,  -8709,  -7519,  -8276,  -5951,  -4450,  -2459,    345,   1902,
+       5150,   7781,   9133,  10847,  13421,  12777,  13552,  13119,  12488,  10743,
+       9011,   6984,   5456,   2310,    640,   -252,  -1718,  -2350,  -1621,  -1496,
+       -514,   1138,   2207,   4502,   5712,   7172,   8639,   9480,   9150,   9837,
+       8648,   7627,   5959,   4019,   1616,   -471,  -2863,  -4612,  -6325,  -7737,
+      -8994,  -9541, -10017, -10377, -10046, -10147,  -9296,  -9148,  -8763,  -8362,
+      -8374,  -7998,  -8896,  -8976,  -7836,  -9400,  -8880,  -7321,  -7633,  -6317,
+      -3940,  -2394,    644,   1990,   4797,   8072,   8959,  10486,  12986,  13024,
+      12686,  13099,  11802,  10857,   8342,   6890,   5070,   2739,     85,     50,
+      -1747,  -2150,  -1564,  -1223,   -606,   1496,   2138,   4299,   5892,   6879,
+       8470,   9308,   9117,   9414,   8680,   7281,   6108,   3748,   1787,   -368,
+      -2709,  -4667,  -5972,  -7747,  -8721,  -9539,  -9872, -10217, -10171,  -9648,
+      -9270,  -9234,  -8203,  -8390,  -8123,  -7753,  -8098,  -8265,  -8037,  -7919,
+      -8762,  -7399,  -7657,  -6363,  -4617,  -3997,   -476,   1507,   2463,   6244},
+//  /u/
+    {  -942,    755,   2663,   4658,   6227,   7737,   8663,   9057,   8904,   8542,
+       7799,   6531,   5050,   3276,   1359,   -606,  -2048,  -3225,  -4010,  -4470,
+      -3878,  -1932,   1314,   4840,   8069,  10435,  11960,  12723,  13113,  12984,
+      12041,  10229,   7437,   3948,     67,  -3394,  -6289,  -8309,  -9705, -10420,
+     -10726, -10985, -10251,  -8799,  -7503,  -6951,  -6800,  -7109,  -7717,  -7850,
+      -7522,  -7407,  -7450,  -7680,  -8214,  -8476,  -8204,  -7279,  -6042,  -4686,
+      -3227,  -1792,   -272,   1440,   3548,   5541,   7257,   8514,   9189,   9171,
+       8656,   8091,   7126,   5838,   4115,   2292,    136,  -1722,  -3156,  -3899,
+      -4506,  -4190,  -2730,     15,   3253,   6397,   9181,  10996,  12341,  13055,
+      13425,  12703,  11368,   8977,   5936,   2308,   -997,  -4081,  -6384,  -8168,
+      -9275,  -9489,  -9447,  -8860,  -7770,  -6518,  -5929,  -5693,  -5729,  -5865,
+      -6070,  -5875,  -5976,  -6355,  -6729,  -6866,  -6883,  -6624,  -5957,  -5101,
+      -4142,  -3117,  -1710,   -172,   1696,   3688,   5718,   7330,   8664,   9732,
+      10375,  10583,  10339,   9749,   8443,   6865,   5008,   3264,   1468,     66,
+      -1187,  -2048,  -2727,  -2341,   -888,   2028,   5575,   8895,  11554,  13184,
+      14325,  14770,  15038,  14366,  12983,  10352,   7130,   3358,    -51,  -3004,
+      -5211,  -6921,  -7929,  -8248,  -8211,  -7612,  -6652,  -5689,  -5163,  -4695,
+      -4826,  -5103,  -5336,  -5179,  -5201,  -5260,  -5351,  -5577,  -5855,  -5673,
+      -4906,  -4050,  -2992,  -1952,   -656,    521,   2067,   3778,   5690,   7102,
+       8378,   9214,   9547,   9343,   8943,   8253,   6982,   5477,   3713,   1937,
+        -37,  -1381,  -2506,  -3146,  -3691,  -3003,  -1452,   1498,   4756,   8030,
+      10500,  12081,  13117,  13463,  13452,  12520,  11017,   8305,   5088,   1205,
+      -2234,  -5381,  -7625,  -9497, -10635, -11318, -11300, -10592,  -9611,  -8852,
+      -8301,  -7840,  -7875,  -7935,  -8142,  -8192,  -8475,  -8743,  -9019,  -9116,
+      -9238,  -8956,  -8415,  -7610,  -6654,  -5393,  -3873,  -2250,   -429,   1500,
+       3390,   5024,   6420,   7331,   7763,   7529,   6976,   5891,   4530,   2803},
+//  /e/
+    { -2236,    255,   1677,   1489,   2009,   3197,   3714,   3649,   2885,   3152,
+       4048,   3498,   1963,   1775,   2352,   2036,   1100,    772,   1042,   1640,
+       1702,   1112,   1535,   4340,   6984,   5954,   5437,   7831,   8140,   5213,
+       3529,   3368,   2539,   1391,    314,   -254,    574,    991,   -376,  -1182,
+       -766,  -1451,  -2626,  -2959,  -3396,  -4222,  -4810,  -5843,  -6854,  -7263,
+      -8138,  -8883,  -7469,  -6535,  -7245,  -6827,  -4811,  -3394,  -2857,  -1873,
+       -352,   1311,   2273,   2358,   2929,   4091,   4072,   2838,   2541,   3707,
+       3463,   2018,   1512,   2048,   2180,   1765,   1151,   1088,   2000,   2360,
+       1805,   2537,   5095,   6993,   6127,   6114,   7608,   7089,   4755,   3280,
+       2724,   2122,   1452,    339,      1,    925,    971,   -315,  -1135,  -1186,
+      -1801,  -2536,  -3329,  -4099,  -4144,  -4668,  -6413,  -7110,  -6636,  -7954,
+      -8864,  -7392,  -7754,  -7508,  -4885,  -4878,  -5345,  -2857,  -1266,   -961,
+        677,   1813,   1609,   2944,   4345,   3435,   2576,   3792,   4552,   3430,
+       2531,   2406,   2552,   2378,   1608,    666,   1130,   1935,   1517,    729,
+       2168,   4781,   6835,   6687,   6409,   7910,   8418,   5755,   3311,   3146,
+       2607,   1083,      4,     55,    653,    760,   -147,  -1129,  -1130,  -1145,
+      -2204,  -3341,  -3455,  -3327,  -4390,  -5741,  -6474,  -6729,  -6700,  -7917,
+      -8978,  -7757,  -6308,  -7159,  -7045,  -4975,  -3727,  -3346,  -2179,   -572,
+        945,   1819,   2265,   2993,   4355,   4654,   3451,   3823,   4978,   4012,
+       2452,   2324,   2281,   1625,   1176,    638,    461,   1407,   1872,   2113,
+       2998,   5629,   8321,   7649,   6604,   8155,   8072,   4737,   2696,   2470,
+       1662,    657,     75,   -178,    530,   1021,   -271,  -1614,  -1090,   -965,
+      -2455,  -3681,  -3685,  -3538,  -4205,  -5894,  -7054,  -6716,  -7355,  -9337,
+      -9378,  -7472,  -6627,  -6951,  -6473,  -4962,  -3378,  -2513,  -1746,   -157,
+       1437,   2448,   2867,   3532,   4347,   4114,   3475,   4152,   4385,   3117,
+       2364,   2501,   2132,   1562,   1406,   1088,   1217,   1848,   2317,   3498},
+//  /o/
+    {  2281,   3885,   5730,   7791,   9718,  10605,  10297,   8722,   5989,   2618,
+       -276,  -2523,  -3473,  -3103,  -2200,   -943,     -3,    343,     69,   -576,
+      -1614,  -2470,  -3060,  -3570,  -3846,  -4159,  -4661,  -5360,  -6089,  -7031,
+      -7705,  -8053,  -8210,  -7737,  -6855,  -5701,  -4348,  -2897,  -1926,  -1071,
+       -724,   -738,   -672,   -592,    -59,    945,   2398,   3877,   5337,   6376,
+       6717,   6542,   5655,   4433,   3024,   1744,    717,    127,    -87,   -109,
+        149,    355,    622,    896,   1162,   1581,   2315,   3789,   6203,   8452,
+      10847,  12112,  11649,   9797,   6396,   2298,  -1476,  -3966,  -5145,  -4423,
+      -2848,  -1070,    602,   1194,    966,     21,  -1275,  -2635,  -3484,  -4115,
+      -4458,  -4532,  -4857,  -5262,  -5840,  -6501,  -7284,  -7604,  -7885,  -7707,
+      -6889,  -5934,  -4664,  -3394,  -2266,  -1469,   -873,   -712,   -700,   -509,
+       -150,    601,   1876,   3343,   4740,   6052,   6705,   6760,   6232,   5148,
+       3775,   2448,   1267,    394,     24,   -121,    -13,    330,    554,    908,
+       1183,   1623,   2036,   3613,   5705,   7782,  10548,  11711,  11915,  10426,
+       7394,   3418,   -318,  -3299,  -4953,  -4501,  -3566,  -1645,    -76,    678,
+        783,     89,  -1072,  -2264,  -2947,  -3775,  -3956,  -4224,  -4616,  -5001,
+      -5742,  -6461,  -7105,  -7512,  -7908,  -7711,  -7227,  -6354,  -5078,  -4020,
+      -2828,  -1967,  -1465,  -1259,  -1166,  -1184,   -962,   -197,    651,   2244,
+       3793,   5302,   6482,   7121,   7056,   6380,   5405,   3820,   2518,   1182,
+        189,   -331,   -591,   -550,   -359,    112,    413,    982,   1605,   2423,
+       4390,   6282,   8722,  11027,  11969,  11813,   9918,   6636,   2521,  -1066,
+      -4149,  -5370,  -5047,  -3920,  -1882,   -311,    654,    842,    290,   -950,
+      -2009,  -3040,  -3917,  -4220,  -4704,  -5096,  -5516,  -6094,  -6765,  -7258,
+      -7822,  -8065,  -7753,  -7256,  -6199,  -4987,  -3772,  -2716,  -1804,  -1527,
+      -1320,  -1278,  -1468,  -1043,   -394,    802,   2455,   4260,   5820,   7083,
+       7711,   7368,   6653,   5163,   3472,   1889,    474,   -516,   -984,  -1022}};