Emilio Monti
/
cmsis_dsp_fir
Example FIR filter using the CMSIS DSP API
main.cpp@0:840b7af4eace, 2012-03-12 (annotated)
- Committer:
- emilmont
- Date:
- Mon Mar 12 11:34:49 2012 +0000
- Revision:
- 0:840b7af4eace
- Child:
- 1:9442dff3bfdc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 0:840b7af4eace | 1 | #include <stdio.h> |
emilmont | 0:840b7af4eace | 2 | #include "arm_math.h" |
emilmont | 0:840b7af4eace | 3 | #include "math_helper.h" |
emilmont | 0:840b7af4eace | 4 | |
emilmont | 0:840b7af4eace | 5 | #define BLOCK_SIZE 32 |
emilmont | 0:840b7af4eace | 6 | #define NUM_BLOCKS 10 |
emilmont | 0:840b7af4eace | 7 | #define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS) |
emilmont | 0:840b7af4eace | 8 | |
emilmont | 0:840b7af4eace | 9 | #define NUM_TAPS 29 |
emilmont | 0:840b7af4eace | 10 | #define SNR_THRESHOLD_F32 140.0f |
emilmont | 0:840b7af4eace | 11 | |
emilmont | 0:840b7af4eace | 12 | // The input signal and reference output |
emilmont | 0:840b7af4eace | 13 | extern float32_t output[TEST_LENGTH_SAMPLES]; |
emilmont | 0:840b7af4eace | 14 | extern float32_t expected_output[TEST_LENGTH_SAMPLES]; |
emilmont | 0:840b7af4eace | 15 | |
emilmont | 0:840b7af4eace | 16 | // Declare FIR State buffer of size (numTaps + blockSize - 1) |
emilmont | 0:840b7af4eace | 17 | float32_t fir_state[BLOCK_SIZE + NUM_TAPS - 1]; |
emilmont | 0:840b7af4eace | 18 | |
emilmont | 0:840b7af4eace | 19 | // FIR Coefficients |
emilmont | 0:840b7af4eace | 20 | const float32_t fir_coeff[NUM_TAPS] = { |
emilmont | 0:840b7af4eace | 21 | -0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, |
emilmont | 0:840b7af4eace | 22 | +0.0085302217f, -0.0000000000f, -0.0173976984f, -0.0341458607f, -0.0333591565f, |
emilmont | 0:840b7af4eace | 23 | +0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, |
emilmont | 0:840b7af4eace | 24 | +0.2229246956f, +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, |
emilmont | 0:840b7af4eace | 25 | -0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, +0.0080754303f, |
emilmont | 0:840b7af4eace | 26 | +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f |
emilmont | 0:840b7af4eace | 27 | }; |
emilmont | 0:840b7af4eace | 28 | |
emilmont | 0:840b7af4eace | 29 | int32_t main(void) { |
emilmont | 0:840b7af4eace | 30 | // Call FIR init function to initialize the instance structure. |
emilmont | 0:840b7af4eace | 31 | arm_fir_instance_f32 fir; |
emilmont | 0:840b7af4eace | 32 | arm_fir_init_f32(&fir, NUM_TAPS, (float32_t *)fir_coeff, fir_state, BLOCK_SIZE); |
emilmont | 0:840b7af4eace | 33 | |
emilmont | 0:840b7af4eace | 34 | // Call the FIR process function for every BLOCK_SIZE samples |
emilmont | 0:840b7af4eace | 35 | for (uint32_t i=0; i < NUM_BLOCKS; i++) { |
emilmont | 0:840b7af4eace | 36 | float32_t* signal = output + (i * BLOCK_SIZE); |
emilmont | 0:840b7af4eace | 37 | arm_fir_f32(&fir, signal, signal, BLOCK_SIZE); |
emilmont | 0:840b7af4eace | 38 | } |
emilmont | 0:840b7af4eace | 39 | |
emilmont | 0:840b7af4eace | 40 | // Compare the generated output against the reference |
emilmont | 0:840b7af4eace | 41 | float32_t snr = arm_snr_f32(expected_output, output, TEST_LENGTH_SAMPLES); |
emilmont | 0:840b7af4eace | 42 | printf("snr: %f\n\r", snr); |
emilmont | 0:840b7af4eace | 43 | if (snr < SNR_THRESHOLD_F32) { |
emilmont | 0:840b7af4eace | 44 | printf("Failed\n\r"); |
emilmont | 0:840b7af4eace | 45 | } else { |
emilmont | 0:840b7af4eace | 46 | printf("Success\n\r"); |
emilmont | 0:840b7af4eace | 47 | } |
emilmont | 0:840b7af4eace | 48 | } |