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 F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed
Fork of F746_SD_GraphicEqualizer by
Revision 3:c3976d34cde9, committed 2016-05-01
- Comitter:
- MikamiUitOpen
- Date:
- Sun May 01 14:13:51 2016 +0000
- Parent:
- 2:2a5c93bf729a
- Child:
- 4:14f401cb069a
- Commit message:
- 4
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FrequencyResponseDrawer.lib Sun May 01 14:13:51 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/MikamiUitOpen/code/FrequencyResponseDrawer/#0bc63b49e2a3
--- a/MyClasses_Functions/FrequancyResponseBase.hpp Sun May 01 02:44:30 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -//------------------------------------------------------ -// FrqRespDrawer クラスで周波数特性を描画する際に使う -// 周波数応答に対応するクラスの抽象基底クラス -// -// 2016/04/27, Copyright (c) 2016 MIKAMI, Naoki -//------------------------------------------------------ - -#ifndef FREQUENCY_RESPONSE_BASE_HPP -#define FREQUENCY_RESPONSE_BASE_HPP - -#include <complex> // requisite for complex - -namespace Mikami -{ - typedef complex<float> Complex; // define "Complex" - - class FrequencyResponse - { - public: - // 周波数応答の絶対値を返す関数, 引数: z^(-1) - virtual float AbsH_z(Complex u) = 0; - - protected: - FrequencyResponse() {} - }; -} -#endif // F746_FREQUENCY_RESPONSE_BASE_HPP
--- a/MyClasses_Functions/FrquencyResponseDrawer.cpp Sun May 01 02:44:30 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -//----------------------------------------------------------- -// 周波数が対数スケールの周波数特性を描画するクラス -// FrqRespDrawer class -// -// 2016/05/01, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "FrquencyResponseDrawer.hpp" - -namespace Mikami -{ - // 目盛線の描画 - void FrqRespDrawer::DrawAxis() - { - uint16_t height = DB1_*(MAX_DB_ - MIN_DB_); - int logMin = (int)floorf(log10f(MIN_)); - int loop = (int)floorf(log10f(MAX_)) - logMin; - - lcd_->SetTextColor(AXIS_COLOR_); - uint16_t y0 = ORGY_ - height; - lcd_->DrawVLine(X(MIN_), y0, height); // 最小値に対応する線 - - float du = powf(10.0, logMin); // 座標値の増分 - float u1 = (floorf(MIN_/du) + 1.0f)*du; // 最小値に対応する線の次の座標値 - - for (int n=0; n<=loop; n++) - { - float uMax = (10.0f*du < MAX_) ? 10.0f*du : MAX_; - for (float u=u1; u<uMax*0.99f; u+=du) - lcd_->DrawVLine(X(u), y0, height); - - du = uMax; // 値の増分を 10 倍する - u1 = du; // 次の for ループ の最初の値 - } - - lcd_->DrawVLine(X(MAX_), y0, height); // 最大値に対応する線 - - uint16_t width = X(MAX_) - X(MIN_); - int count = Round((MAX_DB_ - MIN_DB_)/(Y_SPACE_/DB1_)); - for (int n=0; n<= count; n++) - lcd_->DrawHLine(X(MIN_), Round(ORGY_-Y_SPACE_*n), width); - } - - // 横軸の目盛値の表示 - void FrqRespDrawer::DrawNumericX(AxisX_Char xChar[], int nDisp, int offsetY, - string str, sFONT &fonts, uint32_t textColor) - { - for (int n=0; n<nDisp; n++) - Label frq(X(xChar[n].frq), ORGY_+offsetY, - xChar[n].str, Label::CENTER); - uint16_t x0 = ORGX_ + (uint16_t)(DEC_*log10f(MAX_/MIN_))/2; - Label l_frq(x0, ORGY_+20, str, Label::CENTER); - } - - // 縦軸の目盛値の表示 - void FrqRespDrawer::DrawNumericY(int offsetX, int offsetY, uint16_t d_dB, - const char fmt[], sFONT &fonts, - uint32_t textColor, string str) - { - uint16_t x0 = ORGX_ + offsetX; - uint16_t y0 = ORGY_ + offsetY; - int count = Round((MAX_DB_ - MIN_DB_)/d_dB); - - for (int n=0; n<=count; n++) - NumericLabel<int> num(x0, y0-n*d_dB*DB1_, - fmt, (int)(MIN_DB_+d_dB*n)); - Label l_dB(x0, y0-count*d_dB*DB1_-12, str); - } - - // 周波数特性のグラフの描画 - void FrqRespDrawer::DrawGraph(FrequencyResponse *frqResp, uint32_t color) - { - lcd_->SetTextColor(color); - uint16_t width = X(MAX_) - X(MIN_); - uint16_t x1 = 0; - uint16_t y1 = 0; - float pi2FsM = -6.283185f/FS_; // -2*PI*Ts - for (int n=0; n<=width; n++) - { - float frq = PosToFrq(n+ORGX_); - uint16_t x2 = X(frq); - float absHz = frqResp->AbsH_z(exp(Complex(0, pi2FsM*frq))); - float dB = (absHz > 0.001f) ? 20.0f*log10f(absHz) : MIN_DB_; - uint16_t y2 = ORGY_ - Round((dB - MIN_DB_)*DB1_); - if (y2 > ORGY_) y2 = ORGY_; - - if (n != 0) lcd_->DrawLine(x1, y1, x2, y2); - - x1 = x2; - y1 = y2; - } - lcd_->SetTextColor(AXIS_COLOR_); - lcd_->DrawHLine(X(MIN_), ORGY_, width+1); - } - - // 消去 - void FrqRespDrawer::Erase() - { - lcd_->SetTextColor(BACK_COLOR_); - uint16_t height = DB1_*(MAX_DB_ - MIN_DB_); - lcd_->FillRect(ORGX_, ORGY_- height, X(MAX_)-X(MIN_)+1, height+1); - } -} - -
--- a/MyClasses_Functions/FrquencyResponseDrawer.hpp Sun May 01 02:44:30 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -//----------------------------------------------------------- -// 周波数が対数スケールの周波数特性を描画するクラス -// FrqRespDrawer class Header -// -// 2016/05/01, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_FRQ_RESP_DRAWER_HPP -#define F746_FRQ_RESP_DRAWER_HPP - -#include "NumericLabel.hpp" -#include "FrequancyResponseBase.hpp" - -namespace Mikami -{ - class FrqRespDrawer - { - public: - // 横軸の目盛値を描画する際に使う構造体 - struct AxisX_Char { uint16_t frq; string str; }; - - // Constructor - FrqRespDrawer(uint16_t org, float min, float max, uint16_t dec, - uint16_t orgY, float minDb, float maxDb, - float db1Pixel, float ySpace, float fs, - uint32_t lineColor = 0xFF00B0FF, - uint32_t axisColor = LCD_COLOR_LIGHTGRAY, - uint32_t backColor = GuiBase::ENUM_BACK) - : lcd_(GuiBase::GetLcdPtr()), - ORGX_(org), MIN_(min), MAX_(max), DEC_(dec), - ORGY_(orgY), MIN_DB_(minDb), MAX_DB_(maxDb), - DB1_(db1Pixel), Y_SPACE_(db1Pixel*ySpace), FS_(fs), - LINE_COLOR_(lineColor), - AXIS_COLOR_(axisColor), - BACK_COLOR_(backColor) {} - - // 周波数に対応する x 座標値の取得 - int X(float frq) - { return Round(ORGX_ + DEC_*log10f(frq/MIN_)); } - - // x 座標値を周波数に変換 - float PosToFrq(uint16_t x) - { return MIN_*powf(10.0f, (x - ORGX_)/(float)DEC_); } - - // 目盛線の描画 - void DrawAxis(); - - // 横軸の目盛値の表示 - void DrawNumericX(AxisX_Char xChar[], int nDisp, int offsetY, - string str, sFONT &fonts = Font12, - uint32_t textColor = LCD_COLOR_WHITE); - - // 縦軸の目盛値の表示 - void DrawNumericY(int offsetX, int offsetY, uint16_t d_dB, - const char fmt[], sFONT &fonts = Font12, - uint32_t textColor = LCD_COLOR_WHITE, - string str = "[dB]"); - - // 周波数特性のグラフの描画 - void DrawGraph(FrequencyResponse *frqResp, uint32_t color); - void DrawGraph(FrequencyResponse *frqResp) - { DrawGraph(frqResp, LINE_COLOR_);} - - // 消去 - void Erase(); - - private: - LCD_DISCO_F746NG *lcd_; - const uint16_t ORGX_; // 横軸の目盛の最小値に対応する位置 - const float MIN_; // 横軸の目盛の最小値 - const float MAX_; // 横軸の目盛の最大値 - const uint16_t DEC_; // 周波数の 10 倍に対応する長さ (pixels) - const uint16_t ORGY_; // 縦軸の目盛の最小値に対応する位置 - const float MIN_DB_; // 縦軸の目盛の最小値 [dB] - const float MAX_DB_; // 縦軸の目盛の最大値 [dB] - const float DB1_; // 1 dB に対応する pixels 数 - const float Y_SPACE_; // 縦軸の目盛線の間隔に対応する pixels 数 - const float FS_; // 標本化周波数 - const uint32_t LINE_COLOR_; - const uint32_t AXIS_COLOR_; - const uint32_t BACK_COLOR_; - - // 丸め - int Round(float x) { return x + 0.5f - (x < 0); } - - // 10 のべき乗かどうかの検査 - bool PowersOf10(float x) - { return fabsf(log10f(x) - Round(log10f(x))) < 0.01f; } - - // disallow copy constructor and assignment operator - FrqRespDrawer(const FrqRespDrawer&); - FrqRespDrawer& operator=(const FrqRespDrawer&); - }; -} -#endif // F746_FRQ_RESP_DRAWER_HPP