mbed OS 5 version of sample program indicating the usage of CMSIS-DSP which supports NEON
Dependencies: mbed-dsp-neon
Information
Japanese version of description is stated at last half of this page.
このページの後半に日本語版の説明があります。
mbed OS 5 version of sample program indicating the usage of CMSIS-DSP which supports NEON
Overview
This sample program shows the example for usage of CMSIS-DSP supporting NEON.
Concretely, in this program, mbed-dsp-neon is used instead of mbed-dsp and FIR filter based on SciPy FIR Filter is carried out.
Input signal and referenced output are implemented in data.cpp.
With respect to the default configuration of serial communication (e.g. baud rate), please refer to the link below:
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Note that only ARM Compiler 5 is available at present for building this program.
mbed OS 5版NEON対応CMSIS-DSPサンプルプログラム
概要
本プログラムはNEON対応CMSIS-DSPの使用例を示すサンプルプログラムです。
具体的には、mbed-dspライブラリの代わりにmbed-dsp-neonを用いてSciPy FIR Filterで示すFIRフィルタ処理を行います。
data.cppには入力信号データと基準出力データが記載されています。
デフォルトのシリアル通信(ボーレート等)設定に関しては以下のリンクを参照してください。
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
なお、現時点で本プログラムをビルド可能なコンパイルはARMコンパイラ 5 のみですのでご注意ください。
main.cpp@0:0397f7370803, 2017-02-23 (annotated)
- Committer:
- Osamu Nakamura
- Date:
- Thu Feb 23 13:40:48 2017 +0900
- Revision:
- 0:0397f7370803
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Osamu Nakamura |
0:0397f7370803 | 1 | #include "arm_math.h" |
Osamu Nakamura |
0:0397f7370803 | 2 | #include "math_helper.h" |
Osamu Nakamura |
0:0397f7370803 | 3 | #include <stdio.h> |
Osamu Nakamura |
0:0397f7370803 | 4 | |
Osamu Nakamura |
0:0397f7370803 | 5 | #define BLOCK_SIZE 32 |
Osamu Nakamura |
0:0397f7370803 | 6 | #define NUM_BLOCKS 10 |
Osamu Nakamura |
0:0397f7370803 | 7 | |
Osamu Nakamura |
0:0397f7370803 | 8 | #define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS) |
Osamu Nakamura |
0:0397f7370803 | 9 | |
Osamu Nakamura |
0:0397f7370803 | 10 | #define SNR_THRESHOLD_F32 140.0f |
Osamu Nakamura |
0:0397f7370803 | 11 | #define NUM_TAPS 29 |
Osamu Nakamura |
0:0397f7370803 | 12 | |
Osamu Nakamura |
0:0397f7370803 | 13 | /* ------------------------------------------------------------------- |
Osamu Nakamura |
0:0397f7370803 | 14 | * The input signal and reference output (computed with MATLAB) |
Osamu Nakamura |
0:0397f7370803 | 15 | * are defined externally in arm_fir_lpf_data.c. |
Osamu Nakamura |
0:0397f7370803 | 16 | * ------------------------------------------------------------------- */ |
Osamu Nakamura |
0:0397f7370803 | 17 | extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; |
Osamu Nakamura |
0:0397f7370803 | 18 | extern float32_t refOutput[TEST_LENGTH_SAMPLES]; |
Osamu Nakamura |
0:0397f7370803 | 19 | |
Osamu Nakamura |
0:0397f7370803 | 20 | /* ------------------------------------------------------------------- |
Osamu Nakamura |
0:0397f7370803 | 21 | * Declare State buffer of size (numTaps + blockSize - 1) |
Osamu Nakamura |
0:0397f7370803 | 22 | * ------------------------------------------------------------------- */ |
Osamu Nakamura |
0:0397f7370803 | 23 | static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; |
Osamu Nakamura |
0:0397f7370803 | 24 | |
Osamu Nakamura |
0:0397f7370803 | 25 | /* ---------------------------------------------------------------------- |
Osamu Nakamura |
0:0397f7370803 | 26 | * FIR Coefficients buffer generated using fir1() MATLAB function. |
Osamu Nakamura |
0:0397f7370803 | 27 | * fir1(28, 6/24) |
Osamu Nakamura |
0:0397f7370803 | 28 | * ------------------------------------------------------------------- */ |
Osamu Nakamura |
0:0397f7370803 | 29 | const float32_t firCoeffs32[NUM_TAPS] = { |
Osamu Nakamura |
0:0397f7370803 | 30 | -0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, |
Osamu Nakamura |
0:0397f7370803 | 31 | +0.0085302217f, -0.0000000000f, -0.0173976984f, -0.0341458607f, -0.0333591565f, |
Osamu Nakamura |
0:0397f7370803 | 32 | +0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, |
Osamu Nakamura |
0:0397f7370803 | 33 | +0.2229246956f, +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, |
Osamu Nakamura |
0:0397f7370803 | 34 | -0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, +0.0080754303f, |
Osamu Nakamura |
0:0397f7370803 | 35 | +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f |
Osamu Nakamura |
0:0397f7370803 | 36 | }; |
Osamu Nakamura |
0:0397f7370803 | 37 | |
Osamu Nakamura |
0:0397f7370803 | 38 | /* ---------------------------------------------------------------------- |
Osamu Nakamura |
0:0397f7370803 | 39 | * FIR LPF Example |
Osamu Nakamura |
0:0397f7370803 | 40 | * ------------------------------------------------------------------- */ |
Osamu Nakamura |
0:0397f7370803 | 41 | int32_t main(void) { |
Osamu Nakamura |
0:0397f7370803 | 42 | /* Call FIR init function to initialize the instance structure. */ |
Osamu Nakamura |
0:0397f7370803 | 43 | arm_fir_instance_f32 S; |
Osamu Nakamura |
0:0397f7370803 | 44 | arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], BLOCK_SIZE); |
Osamu Nakamura |
0:0397f7370803 | 45 | |
Osamu Nakamura |
0:0397f7370803 | 46 | /* ---------------------------------------------------------------------- |
Osamu Nakamura |
0:0397f7370803 | 47 | * Call the FIR process function for every blockSize samples |
Osamu Nakamura |
0:0397f7370803 | 48 | * ------------------------------------------------------------------- */ |
Osamu Nakamura |
0:0397f7370803 | 49 | for (uint32_t i=0; i < NUM_BLOCKS; i++) { |
Osamu Nakamura |
0:0397f7370803 | 50 | float32_t* signal = testInput_f32_1kHz_15kHz + (i * BLOCK_SIZE); |
Osamu Nakamura |
0:0397f7370803 | 51 | arm_fir_f32(&S, signal, signal, BLOCK_SIZE); |
Osamu Nakamura |
0:0397f7370803 | 52 | } |
Osamu Nakamura |
0:0397f7370803 | 53 | |
Osamu Nakamura |
0:0397f7370803 | 54 | /* ---------------------------------------------------------------------- |
Osamu Nakamura |
0:0397f7370803 | 55 | * Compare the generated output against the reference output computed |
Osamu Nakamura |
0:0397f7370803 | 56 | * in MATLAB. |
Osamu Nakamura |
0:0397f7370803 | 57 | * ------------------------------------------------------------------- */ |
Osamu Nakamura |
0:0397f7370803 | 58 | float32_t snr = arm_snr_f32(refOutput, testInput_f32_1kHz_15kHz, TEST_LENGTH_SAMPLES); |
Osamu Nakamura |
0:0397f7370803 | 59 | printf("snr: %f\n\r", snr); |
Osamu Nakamura |
0:0397f7370803 | 60 | if (snr < SNR_THRESHOLD_F32) { |
Osamu Nakamura |
0:0397f7370803 | 61 | printf("Failed\n\r"); |
Osamu Nakamura |
0:0397f7370803 | 62 | } else { |
Osamu Nakamura |
0:0397f7370803 | 63 | printf("Success\n\r"); |
Osamu Nakamura |
0:0397f7370803 | 64 | } |
Osamu Nakamura |
0:0397f7370803 | 65 | } |