Ura
Dependencies: CMSIS_DSP_401 mbed
Diff: main.cpp
- Revision:
- 0:b712470aea1d
- Child:
- 1:9b1df0b2507d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 30 16:13:41 2014 +0000 @@ -0,0 +1,81 @@ +#include "mbed.h" +#include "arm_math.h" +#include "math_helper.h" +#include <stdio.h> + + +#define BLOCK_SIZE 32 +#define NUM_BLOCKS 10 +#define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS) +#define TEST_LENGTH_SAMPLES 312 +#define SNR_THRESHOLD_F32 140.0f +#define NUM_TAPS 29 + +Serial pc(SERIAL_TX, SERIAL_RX); + +/* ------------------------------------------------------------------- +* The input signal and reference output (computed with MATLAB) +* are defined externally in arm_fir_lpf_data.c. +* ------------------------------------------------------------------- */ + +extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; +extern float32_t refOutput[TEST_LENGTH_SAMPLES]; + +/* ------------------------------------------------------------------- +* Declare State buffer of size (numTaps + blockSize - 1) +* ------------------------------------------------------------------- */ + +static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; + +/* ---------------------------------------------------------------------- +* FIR Coefficients buffer generated using fir1() MATLAB function. +* fir1(28, 6/24) +* ------------------------------------------------------------------- */ + +const float32_t firCoeffs32[NUM_TAPS] = { +-0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, ++0.0085302217f, -0.0000000000f, -0.0173976984f, -0.0341458607f, -0.0333591565f, ++0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, ++0.2229246956f, +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, +-0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, +0.0080754303f, ++0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f +}; +/* ---------------------------------------------------------------------- +* FIR LPF Example +* ------------------------------------------------------------------- */ +int main(void) { +/* Call FIR init function to initialize the instance structure. */ +arm_fir_instance_f32 S; +arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], BLOCK_SIZE); +/* ---------------------------------------------------------------------- +* Call the FIR process function for every blockSize samples +* ------------------------------------------------------------------- */ +for (uint32_t i=0; i < NUM_BLOCKS; i++) { +float32_t* signal = testInput_f32_1kHz_15kHz + (i * BLOCK_SIZE); +arm_fir_f32(&S, signal, signal, BLOCK_SIZE); +} +/* ---------------------------------------------------------------------- +* Compare the generated output against the reference output computed +* in MATLAB. +* ------------------------------------------------------------------- */ +//float32_t snr = arm_snr_f32((float*)refOutput, (float*)testInput_f32_1kHz_15kHz, (unsigned)TEST_LENGTH_SAMPLES); + +float32_t snr; +unsigned int b; +arm_max_f32( testInput_f32_1kHz_15kHz,TEST_LENGTH_SAMPLES, &snr, &b); + + +pc.printf("snr: %f\n\r", snr); +while(1) +{ + if (snr < SNR_THRESHOLD_F32) { + pc.printf("Failed\n\r"); + pc.printf("snr: %f\n\r", snr); + } else { + pc.printf("Success\n\r"); + pc.printf("snr: %f\n\r", snr); + } +} + + +} \ No newline at end of file