CW Decoder (Morse code decoder) 1st release version. Only run on Nucleo-F446RE mbed board.

Dependencies:   Array_Matrix F446_AD_DA ST7565_SPI_LCD TextLCD UIT_FFT_Real

Fork of F446_MySoundMachine by 不韋 呂

Base on F446_MySoundMachine program created by 不韋 呂-san.
Thanks to 不韋 呂-san making fundamental part such as FFT and ADC high speed interrupt driven program.
I just combined LCD and show CW code.

Committer:
kenjiArai
Date:
Sun Feb 05 08:02:54 2017 +0000
Revision:
6:5e21ac9f0550
CW Decoder (Morse code decoder) 1st release version.  Only run on Nucleo-F446RE mbed board.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 6:5e21ac9f0550 1 //--------------------------------------------------------------
kenjiArai 6:5e21ac9f0550 2 // スペクトログラムで使う大域関数
kenjiArai 6:5e21ac9f0550 3 //
kenjiArai 6:5e21ac9f0550 4 // 2016/08/11, Copyright (c) 2016 MIKAMI, Naoki
kenjiArai 6:5e21ac9f0550 5 //--------------------------------------------------------------
kenjiArai 6:5e21ac9f0550 6
kenjiArai 6:5e21ac9f0550 7 #ifndef METHOD_COLLECTION_HPP
kenjiArai 6:5e21ac9f0550 8 #define METHOD_COLLECTION_HPP
kenjiArai 6:5e21ac9f0550 9
kenjiArai 6:5e21ac9f0550 10 #include "mbed.h"
kenjiArai 6:5e21ac9f0550 11 #include "NumericLabel.hpp"
kenjiArai 6:5e21ac9f0550 12 #include "Matrix.hpp"
kenjiArai 6:5e21ac9f0550 13 #include "FFT_Analysis.hpp"
kenjiArai 6:5e21ac9f0550 14
kenjiArai 6:5e21ac9f0550 15 namespace Mikami
kenjiArai 6:5e21ac9f0550 16 {
kenjiArai 6:5e21ac9f0550 17 // 色相の違いで表示
kenjiArai 6:5e21ac9f0550 18 // 0.0 <= x <= 1.0
kenjiArai 6:5e21ac9f0550 19 uint32_t HueScale(float x)
kenjiArai 6:5e21ac9f0550 20 {
kenjiArai 6:5e21ac9f0550 21 if (x >= 1) return LCD_COLOR_WHITE;
kenjiArai 6:5e21ac9f0550 22 int r = 0;
kenjiArai 6:5e21ac9f0550 23 int b = 0;
kenjiArai 6:5e21ac9f0550 24
kenjiArai 6:5e21ac9f0550 25 if (x<0.5f) b = (x<0.33f) ? 255 : -(int)(1500.0f*x) + 750;
kenjiArai 6:5e21ac9f0550 26 else r = (0.67f<x) ? 255 : (int)(1500.0f*x) - 750;
kenjiArai 6:5e21ac9f0550 27 int g = 255 - (int)(1020.0f*(x - 0.5f)*(x - 0.5f));
kenjiArai 6:5e21ac9f0550 28
kenjiArai 6:5e21ac9f0550 29 return 0xFF000000 | (((r << 8) | g) << 8) | b;
kenjiArai 6:5e21ac9f0550 30 }
kenjiArai 6:5e21ac9f0550 31
kenjiArai 6:5e21ac9f0550 32 // 座標軸
kenjiArai 6:5e21ac9f0550 33 void DrawAxis(int x0, int y0, int w0, int h0, uint32_t axisColor,
kenjiArai 6:5e21ac9f0550 34 uint16_t ms100, uint16_t px1kHz, LCD_DISCO_F746NG *lcd)
kenjiArai 6:5e21ac9f0550 35 {
kenjiArai 6:5e21ac9f0550 36 const uint16_t TICK = 5; // 目盛線の長さ
kenjiArai 6:5e21ac9f0550 37 // 横標軸
kenjiArai 6:5e21ac9f0550 38 lcd->SetTextColor(axisColor);
kenjiArai 6:5e21ac9f0550 39 lcd->DrawHLine(x0, y0+TICK, w0);
kenjiArai 6:5e21ac9f0550 40 for (int n=0; n<=w0/ms100; n++)
kenjiArai 6:5e21ac9f0550 41 if ((n % 10)== 0) lcd->DrawVLine(x0+n*ms100, y0, 5);
kenjiArai 6:5e21ac9f0550 42 else lcd->DrawVLine(x0+n*ms100, y0+3, 2);
kenjiArai 6:5e21ac9f0550 43 for (int n=0; n<=w0/ms100; n+=10)
kenjiArai 6:5e21ac9f0550 44 NumericLabel<int> num(x0+n*ms100, y0+TICK+3,
kenjiArai 6:5e21ac9f0550 45 "%1d", (int)(n*0.1f), Label::CENTER);
kenjiArai 6:5e21ac9f0550 46 Label time(x0+w0/2, y0+22, "TIME [s]", Label::CENTER);
kenjiArai 6:5e21ac9f0550 47
kenjiArai 6:5e21ac9f0550 48 // 縦標軸
kenjiArai 6:5e21ac9f0550 49 lcd->SetTextColor(axisColor);
kenjiArai 6:5e21ac9f0550 50 lcd->DrawVLine(x0-TICK, y0-h0, h0);
kenjiArai 6:5e21ac9f0550 51 for (int n=0; n<=h0/px1kHz; n++)
kenjiArai 6:5e21ac9f0550 52 lcd->DrawHLine(x0-TICK, y0-n*px1kHz, TICK);
kenjiArai 6:5e21ac9f0550 53 for (int n=0; n<=h0/px1kHz; n++)
kenjiArai 6:5e21ac9f0550 54 NumericLabel<int> num(x0-TICK-12, y0-n*px1kHz-5, "%1d", n);
kenjiArai 6:5e21ac9f0550 55 Label hz(x0-32, y0-5*px1kHz-20, "[kHz]");
kenjiArai 6:5e21ac9f0550 56 }
kenjiArai 6:5e21ac9f0550 57
kenjiArai 6:5e21ac9f0550 58 // 色と dB の関係の表示
kenjiArai 6:5e21ac9f0550 59 void ColorDb(int y0, uint32_t axisColor, LCD_DISCO_F746NG *lcd)
kenjiArai 6:5e21ac9f0550 60 {
kenjiArai 6:5e21ac9f0550 61 lcd->SetTextColor(axisColor);
kenjiArai 6:5e21ac9f0550 62 lcd->DrawVLine(455, y0-100, 100);
kenjiArai 6:5e21ac9f0550 63 for (int n=0; n<=8; n++)
kenjiArai 6:5e21ac9f0550 64 lcd->DrawHLine(455, y0-(n*100)/8, 4);
kenjiArai 6:5e21ac9f0550 65 for (int n=0; n<=4; n++)
kenjiArai 6:5e21ac9f0550 66 NumericLabel<int> num(440, y0-(n*100)/4-5, "%2d", n*20);
kenjiArai 6:5e21ac9f0550 67 Label dB(432, y0-120, "[dB]");
kenjiArai 6:5e21ac9f0550 68
kenjiArai 6:5e21ac9f0550 69 for (int n=0; n<=100; n++)
kenjiArai 6:5e21ac9f0550 70 {
kenjiArai 6:5e21ac9f0550 71 lcd->SetTextColor(HueScale(n/100.0f));
kenjiArai 6:5e21ac9f0550 72 lcd->DrawHLine(460, y0-n, 16);
kenjiArai 6:5e21ac9f0550 73 }
kenjiArai 6:5e21ac9f0550 74 }
kenjiArai 6:5e21ac9f0550 75
kenjiArai 6:5e21ac9f0550 76 // スペクトルの更新
kenjiArai 6:5e21ac9f0550 77 void SpectrumUpdate(Matrix<uint32_t> &x, FftAnalyzer &analyzer,
kenjiArai 6:5e21ac9f0550 78 const Array<float> &sn, const Array<float> &db)
kenjiArai 6:5e21ac9f0550 79 {
kenjiArai 6:5e21ac9f0550 80 // 過去のスペクトルを一つずらす
kenjiArai 6:5e21ac9f0550 81 for (int n=0; n<x.Rows()-1; n++)
kenjiArai 6:5e21ac9f0550 82 for (int k=0; k<x.Cols(); k++)
kenjiArai 6:5e21ac9f0550 83 x[n][k] = x[n+1][k];
kenjiArai 6:5e21ac9f0550 84
kenjiArai 6:5e21ac9f0550 85 // 新しいスペクトル
kenjiArai 6:5e21ac9f0550 86 analyzer.Execute(sn, db);
kenjiArai 6:5e21ac9f0550 87 const float FACTOR = 1.0f/80.0f; // 表示範囲: 0 ~ 80 dB
kenjiArai 6:5e21ac9f0550 88 for (int k=0; k<=x.Cols(); k++)
kenjiArai 6:5e21ac9f0550 89 x[x.Rows()-1][k] = HueScale(FACTOR*((db[k] > 20) ? db[k]-20 : 0));
kenjiArai 6:5e21ac9f0550 90 }
kenjiArai 6:5e21ac9f0550 91
kenjiArai 6:5e21ac9f0550 92 // スペクトルの表示
kenjiArai 6:5e21ac9f0550 93 void DisplaySpectrum(const Matrix<uint32_t> &x, int x0, int y0,
kenjiArai 6:5e21ac9f0550 94 int hBar, LCD_DISCO_F746NG *lcd)
kenjiArai 6:5e21ac9f0550 95 {
kenjiArai 6:5e21ac9f0550 96 for (int n=0; n<x.Rows(); n++)
kenjiArai 6:5e21ac9f0550 97 for (int k=0; k<x.Cols(); k++)
kenjiArai 6:5e21ac9f0550 98 {
kenjiArai 6:5e21ac9f0550 99 lcd->SetTextColor(x[n][k]);
kenjiArai 6:5e21ac9f0550 100 lcd->DrawHLine(x0+n*hBar, y0-k, hBar);
kenjiArai 6:5e21ac9f0550 101 }
kenjiArai 6:5e21ac9f0550 102 }
kenjiArai 6:5e21ac9f0550 103 }
kenjiArai 6:5e21ac9f0550 104 #endif // METHOD_COLLECTION_HPP