
lab 1 code
Dependencies: CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG
signal_processing.cpp
- Committer:
- bmazzeo
- Date:
- 2020-01-01
- Revision:
- 27:0d65cfcc9001
- Parent:
- 25:5412779376a7
- Child:
- 28:fe7747b89fb3
File content as of revision 27:0d65cfcc9001:
/** ****************************************************************************** * @file signal_processing.c * @author Brian Mazzeo * @date 2020 * @brief This file provides a set of code for signal processing in 487. * Parts are taken from example code from STMIcroelectronics ****************************************************************************** * @attention * This code was specifically developed for BYU ECEn 487 course * Introduction to Digital Signal Processing. * * ****************************************************************************** */ #include "mbed.h" #include "stm32746g_discovery_lcd.h" #include "arm_math.h" /* ---------------------------------------------------------------------- ** Defines for signal processing ** ------------------------------------------------------------------- */ #define AUDIO_BLOCK_SAMPLES ((uint32_t)128) // Number of samples (L and R) in audio block (each samples is 16 bits) #define NUM_TAPS 29 /* ---------------------------------------------------------------------- ** FIR Coefficients buffer generated using fdatool MATLAB function. ** lowpass filter to passband 1 kHz, stopband 2 kHz ** ------------------------------------------------------------------- */ const float32_t firCoeffs32[29] = { 0.0106548937, 0.00951616466, 0.008600869216, 0.002842310816,-0.007469337899, -0.01967334561, -0.02897886001, -0.0296635218, -0.01692939363, 0.01112444047, 0.05218170211, 0.09966956824, 0.1441507041, 0.1758090258, 0.1872722059, 0.1758090258, 0.1441507041, 0.09966956824, 0.05218170211, 0.01112444047, -0.01692939363, -0.0296635218, -0.02897886001, -0.01967334561,-0.007469337899, 0.002842310816, 0.008600869216, 0.00951616466, 0.0106548937 }; /* ------------------------------------------------------------------- * Declare State buffer of size (numTaps + blockSize - 1) * ------------------------------------------------------------------- */ static float32_t firStateF32[AUDIO_BLOCK_SAMPLES + NUM_TAPS - 1]; static float32_t output_array_F32[AUDIO_BLOCK_SAMPLES]; /* Important to have the structure outside of the execution so it can be initialized */ arm_fir_instance_f32 S; /** * @brief Initialize filter structures to be used in loops later * @retval None */ void initalize_signal_processing(void) { /* Call FIR init function to initialize the instance structure. */ arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], AUDIO_BLOCK_SAMPLES); } /** * @brief Process audio channel signals * @param L_channel: Pointer to Left channel data (float) * @param R_channel: Pointer to Right channel data (float) * @param Signal_Length: length of data to process * @retval None */ void process_audio_channel_signals(float* L_channel, float* R_channel, uint16_t Signal_Length) { char buf[40]; BSP_LCD_SetTextColor(LCD_COLOR_CYAN); sprintf(buf, "Processing Signals" ); BSP_LCD_DisplayStringAt(0, 150, (uint8_t *) buf, LEFT_MODE); uint32_t i; arm_status status; float32_t *inputF32, *outputF32; inputF32 = L_channel; outputF32 = &output_array_F32[0]; /* ---------------------------------------------------------------------- ** Call the FIR process function for every blockSize samples ** ------------------------------------------------------------------- */ arm_fir_f32(&S, inputF32, outputF32, AUDIO_BLOCK_SAMPLES); /* The following just passes things from the input to the output */ float32_t* L_chan_mem_address; float32_t* R_chan_mem_address; float32_t L_audio_value; float32_t R_audio_value; L_chan_mem_address = L_channel; R_chan_mem_address = R_channel; for (i=0; i<Signal_Length; i++) { //L_audio_value = *L_chan_mem_address; L_audio_value = output_array_F32[i]; *L_chan_mem_address = L_audio_value; L_chan_mem_address++; R_audio_value = *R_chan_mem_address; *R_chan_mem_address = R_audio_value; R_chan_mem_address++; } }