With a support entitlement you can also get direct access to our team of highly-qualified Arm experts 24-hours a day
Open a support case
Hi!We're trying to use the CMSIS DSP library to filter a real-time signal using the CMSIS dsp fir function. We are using the STM32746ZG board.
We've calculated the coefficients in C and they are correct according to MATLAB. We're feeding these into the arm_fir_init_f32() and we cannot get it to work. When the filter order is 2, i.e. coefficients are 0,1,0 - The output is the same as the input. When we increase the order the output becomes mostly noise. The filter coefficients doesn't seem to be used at all.
ADCBUFFER and DACBUFFER are circular buffers using DMA with length = 1000.ADC init:
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T6_TRGO;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
htim6.Instance = TIM6;
htim6.Init.Prescaler = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = tim6Period;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
System clock: 192MHzHCLK: 192MHzAPB1 peripheral clocks: 12MHzAPB1 timer clocks: 24MHzAPB2 peripheral clocks: 48MHzAPB2 timer clocks: 96MHz
Using DSP FIR:
float32_t * firStateF32 = calloc(sizeof(float32_t) * (blocksize+numTaps-1), 1);
arm_fir_init_f32(&S, numTaps, filterCoeff, firStateF32, blockSize);
arm_fir_f32(&S, ADCBUFFER, DACBUFFER, blockSize);
The array filterCoeff is generated by another function (using sample rate = 800kHz) and ordered as described in the CMSIS DSP lib info.
What is missing to get the arm_fir_f32() to work properly?Thanks in advance!
This picture shows the array filterCoeff, fs=8000, fc=2000, lowpass, blackman window.The generated coefficients are the same as given by the FIR window method in MATLAB.The picture below shows input ADCBUFFER (blue) and output DACBUFFER (yellow) for an order two high pass filter. The input frequency is 1kHz and the cutoff frequency is 50kHz. The output is not attenuated as expected.
The picture below shows the same but with the filter order increased to 6.