function dsp_filters_fir, coefficients parameters

Technical questions regarding the XTC tools and programming with XMOS.
tom3
Member++
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

function dsp_filters_fir, coefficients parameters

Post by tom3 »

Hello

I want to use the function dsp_filters_fir.l(lib dsp)

One of the parameters is a int32_t array which comtains the filter coefficients. The coefficients have to be represented in Q fixed- point format. ( like this : Q28(0.5))
I tried to generate some values and then add them in the int32_t array by using the Q tag. By running the code, i noticed that the programms doesn't consider the modifed array. Note that i fist define the int32_t array as empyty and then i fill it .

Code: Select all

 int32_t array[length];
 float coeffs[length];
 for (int i =0; i<=length; i++)
 {
       array[i]=Q15(coeff[i])  
 }
 dsp_filters_fir(.......) ;  
As i said , it seems that the program doesn't consider the loop and use direcltly the empty array. The other parameters of the dsp_filter function are not a problem because everything is working fine when i directly define the int32_t array with all the coefficients in Q fixed point format.

Does somebody know where the problem is and how i can fix it ? I'm not sure if it has something to do with the conversion or seómething else

Thank you

Regards

Tom


lmariotti
Member++
Posts: 27
Joined: Mon Nov 21, 2022 5:38 pm

Post by lmariotti »

Not an XMOS expert here, but from the posted code:

Code: Select all

int32_t arr[length];
for (int i =0; i<=length; i++)
  ...
goes out of array bounds.
As said in https://www.xmos.ai/download/XMOS-Progr ... on)(E).pdf (5.2.2 Bounds checking) this cause a runtime error. Have you maybe checked for runtime errors?

Q28() is just a macro defined as

Code: Select all

#define Q15(f) (int)((signed long long)((f) * ((unsigned long long)1 << (15+20)) + (1<<19)) >> 20)
it should work as expected
tom3
Member++
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

Post by tom3 »

Hello

Yes the macro is already defined in lib dsp this is what i'm trying to use. As i said the programm doesn't consider the loop
( the right code is :

Code: Select all

(int i =0; i<=length-1; i++) 
)
But that is not the main problem , i don't know if i can use this macro in a loop.
RitchRock
XCore Addict
Posts: 189
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Besides the array going out of bounds, I wonder how your program is structured - are you blocking an audio task while coefficients are being computed? You might try offloading coefficient creation to a parallel task and then only sending them to your DSP task when they have been computed.
User avatar
CousinItt
Respected Member
Posts: 365
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

The usual idiom for looping over arrays in C is something like

Code: Select all

 for(int i = 0; i < length; i++)
 {
       // do something
 }
Also there are two variable names coeff and coeffs being used.

However, the main thing is that the coefficient array has to be initialised to something meaningful before the loop converting it to the Q format, or the fixed-point coefficients defined directly, e.g.

Code: Select all

array[0] = Q15(1.0);
 // etc...