2023-06-01 06:56 AM - edited 2023-11-20 04:11 AM
Hi,
My Controller is STM32G473RE . Sample rate is each 2.8 ms .
I have created a filter with mathlab which presented me with plain C code.
This code does exactly what i want and gives the expected results.
int16_t input[3100]={4582,4581,4573,....
double b[60] = {0.00124338459832230, 0.00125334840954137, 0.00128321129425865, 0.00133289003835827,....
void inputdata() {
for (int i = 0; i < L; i++) {
x[i]=input[i];
}
for (int i = 0; i < M + M; i++) {
_x[i] = 0;
}
for (int i = 0; i < L; i++) {
_x[i + M + M] = x[i];
}
}
void filter()
{
for (int n = M + M - 1; n < L; n++) // loop over data samples
{
double sum_b = 0; // sum of b[k]*x[n-k]
for (int k = 0, p1 = n, p2 = n-M-M+1; k < M; k++, p1--, p2++) // loop over b coefficients
{
sum_b += b[k]*(_x[p1]+_x[p2]); // update sum_b
}
testBuffer[n - M - M + 1] = sum_b; // compute output sample
}
}
void fir_task()
{
// Process the filtered output as needed
// ...
inputdata();
filter();
return ;
}
After this first results, i studied the FMAC the past days and found out that FMAC is not advantageous at such low sample rates, so choosed to use CSMIS DSP functions to optimize my FIR filter .
When i use the filter functions from CMSIS DSP i get half the aplitude and worse filtering.
__IO float32_t testBuffer[3100];
float32_t input[3100]={4582,4581,4573,4582,4591,4589,4588,4332,.....;
double b[60] = {0.00124338459832230, 0.00125334840954137,...
float32_t coeffs[60];
void fir_task()
{
arm_fir_instance_f32 S;
float32_t *input16, *output16;
static float32_t firState16[BLOCK_SIZE + NUM_TAPS - 1];
uint32_t blockSize = BLOCK_SIZE;
uint32_t numBlocks = 3100/BLOCK_SIZE;
for(int n=0;n<NUM_TAPS;n++)
{
coeffs[n] = (float32_t)b[n];
}
/* Initialize input and output buffer pointers */
input16 = &input[0];
output16 = &testBuffer[0];
/* Call FIR init function to initialize the instance structure. */
arm_fir_init_f32(&S, NUM_TAPS, &coeffs[0], &firState16[0], blockSize);
/* ----------------------------------------------------------------------
** Call the FIR process function for every blockSize samples
** ------------------------------------------------------------------- */
for(uint16_t i=0; i < numBlocks; i++)
{
arm_fir_f32(&S, input16 + (i * blockSize), output16 + (i * blockSize), blockSize);
}
getripple();
}
I also made the correct type conversions and tried the arm_fir_Q15 functions which have the same results as the float32 version.
What could be wrong?