不韋 呂 / Mbed 2 deprecated F746_AudioOutQSPI

Dependencies:   BSP_DISCO_F746NG_patch_fixed F746_GUI LCD_DISCO_F746NG QSPI_DISCO_F746NG TS_DISCO_F746NG mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FrquencyResponseDrawer.hpp Source File

FrquencyResponseDrawer.hpp

00001 //-----------------------------------------------------------
00002 //  FrqRespDrawer class (Abstract base class) -- Header
00003 //
00004 //  2016/03/30, Copyright (c) 2016 MIKAMI, Naoki
00005 //-----------------------------------------------------------
00006 
00007 #ifndef F746_FRQ_RESP_DRAWER_HPP
00008 #define F746_FRQ_RESP_DRAWER_HPP
00009 
00010 #include <complex>  // requisite for complex
00011 #include "Label.hpp"
00012 
00013 namespace Mikami
00014 {
00015     typedef complex<float> Complex; // define "Complex"
00016 
00017     class FrqRespDrawer
00018     {
00019     public:
00020         struct Params
00021         {
00022             const uint16_t ORG;     // 横軸の目盛の最小値に対応する位置
00023             const float MIN;        // 横軸の目盛の最小値
00024             const float MAX;        // 横軸の目盛の最大値
00025             const uint16_t DEC;     // 周波数の 10 倍に対応する長さ (pixels)
00026             const uint16_t ORGY;    // 縦軸の目盛の最小値に対応する位置
00027             const float MIN_DB;     // 縦軸の目盛の最小値 [dB]
00028             const float MAX_DB;     // 縦軸の目盛の最大値 [dB]
00029             const uint16_t DB10;    // 10 dB 対応する長さ (pixels)
00030             const float FS;         // 標本化周波数
00031             const uint32_t LINE_COLOR;
00032             const uint32_t AXIS_COLOR;
00033             const uint32_t BACK_COLOR;
00034             
00035             Params(uint16_t org, float min, float max, uint16_t dec,
00036                    uint16_t orgY, float minDb, float maxDb, uint16_t db10,
00037                    float fs,
00038                    uint32_t lineColor = 0xFF00B0FF,
00039                    uint32_t axisColor = LCD_COLOR_LIGHTGRAY,
00040                    uint32_t backColor = GuiBase::ENUM_BACK)
00041                 : ORG(org), MIN(min), MAX(max), DEC(dec),
00042                   ORGY(orgY), MIN_DB(minDb), MAX_DB(maxDb), DB10(db10),
00043                   FS(fs),
00044                   LINE_COLOR(lineColor),
00045                   AXIS_COLOR(axisColor),
00046                   BACK_COLOR(backColor) {}
00047         };
00048         
00049         // Constructor
00050         FrqRespDrawer(Params p)
00051             : lcd_(GuiBase::GetLcdPtr()), P_(p), DB1_(p.DB10*0.1f) {}
00052 
00053         // 周波数に対応する x 座標値の取得
00054         int X(float frq)
00055         {   return Round(P_.ORG + P_.DEC*log10f(frq/P_.MIN));  }
00056 
00057         // x 座標値を周波数に変換
00058         float PosToFrq(uint16_t x)
00059         { return P_.MIN*powf(10.0f, (x - P_.ORG)/(float)P_.DEC); }
00060 
00061         // 目盛線の描画
00062         void DrawAxis();
00063 
00064         // 横軸の目盛値の表示用
00065         void DrawCharX(uint32_t frq, int offsetY,
00066                           const char str[], sFONT &fonts = Font12,
00067                           uint32_t textColor = LCD_COLOR_WHITE)
00068         {   Label frequency(X(frq), P_.ORGY+offsetY, str, Label::CENTER); }
00069 
00070         // 縦軸の目盛値の表示
00071         void DrawNumericY(int offsetX, int offsetY, int count,
00072                           uint16_t d_dB, const char fmt[], sFONT &fonts = Font12,
00073                           uint32_t textColor = LCD_COLOR_WHITE); 
00074 
00075         // 周波数特性のグラフの描画
00076         void DrawGraph();
00077         
00078         // 周波数応答の絶対値を返す関数, 引数: z^(-1)
00079         virtual float AbsH_z(Complex u) = 0;
00080 
00081         // 消去
00082         void Erase();
00083 
00084     private:
00085         LCD_DISCO_F746NG *lcd_;
00086         const Params P_;
00087         const float DB1_;
00088 
00089         // 丸め
00090         int Round(float x) { return x + 0.5f - (x < 0); }  
00091 
00092         // 10 のべき乗かどうかの検査
00093         bool PowersOf10(float  x)
00094         { return fabsf(log10f(x) - Round(log10f(x))) < 0.01f; }
00095 
00096         // disallow copy constructor and assignment operator
00097         FrqRespDrawer(const FrqRespDrawer&);
00098         FrqRespDrawer& operator=(const FrqRespDrawer&);
00099     };
00100 }
00101 #endif  // F746_FRQ_RESP_DRAWER_HPP