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.
You are viewing an older revision! See the latest version
Homepage
Information
FftTest - Interface 2015年4月号 第1部 第7章 のソフトウェア
Program for Section 7 in April 2015 issue of Interface
(Japanese electronics magazine)
概要¶
このプログラムは、
- ハイパスフィルタ、ローパスフィルタ、ノッチフィルタ を行うFilterTestクラス、
- FFT (256点) を行うFftTestクラス、 波形をUSBシリアル通信でホストへ送信するmain関数で構成されています。
FilterTest.h, FilterTest.cpp¶
- A-Dサンプリング - 1 kSPS
- ハイパスフィルタ(遮断周波数 0.5 Hz、1次バターワース)
- ローパスフィルタ(遮断周波数 30 Hz、2次バターワース)
- ノッチフィルタ(中心周波数 50 Hz、2次)
FftTest.h, FftTest.cpp¶
- 256点FFT演算 - クーリー-テューキー アルゴリズム 基数-2 時間間引き
- ハン窓(ハニング窓適用)
- パワー値計算
- 振幅値計算
- 振幅値正規化(実効値にスケーリング)
main.cpp¶
- データ送信レート - 200 SPS
- メインループ - ポーリングにより、サンプリング、フィルタ処理完了フラグがセットされたら、
また、FFT完了フラグがセットされたらUSBシリアル通信経由で、ホストへ送信する
シリアル通信フォーマット¶
(※)誌面ではパケットサイズ 64 byteとなっていますが、
64 byteでは、PCのUSBドライバが 4096 byteまで保持し、波形が滑らかに描画できないため、
Ver.1.0.2で、32 byteに変更しています。
- 34byte固定長パケット方式
- 波形データパケット、FFTパケットの2種類
| 波形データパケット | FFTパケット | |
| 0x00 | パケットヘッダ(固定値0xAA) | |
| 0x01 | データ種別ID(0x01: 波形データ) | |
| 0x02 | パケット番号(0 - 99繰り返し) | |
| 0x03 | ペイロードサイズ(固定値30) | |
| 0x04 - 0x21 | 波形データ(short, big endian) |
Description¶
This contains FilterTest class and main function.
FilterTest class:
- High pass filter, Low pass, Notch filter
Main function:
- Send waveform to host via USB serial class.
FilterTest.h, FilterTest.cpp¶
- A-D sampling - 1 kSPS
- High pass filter - Cut off frequency 0.5 Hz, first order butterworth
- Low pass filter - Cut off frequency 30 Hz, second order butterworth
- Notch filter - Center frequency 50 Hz, second order
main.cpp¶
- Data sending rate - 1 kSPS
- Executing start procedure method
- Main loop - sending waveform data via USB serial interface when detecting ready flag.
Packet format for USB serial interface¶
- Packet size: 34 bytes(fixed)
- One type of packet waveform packet
| Waveform packet | |
| 0x00 | Packet header (0xAA (fixed)) |
| 0x01 | Data type ID (0x01: Waveform ID) |
| 0x02 | Packet number (0 - 99) |
| 0x03 | Payload size (30 (fixed)) |
| 0x04 - 0x21 | Waveform data (short, big endian) |