cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Q15 fir

matas
Associate II
Posted on December 17, 2015 at 17:33

Hi, Q15 fir caused me some confusion, while everyhting runs succesfully with F32 fir. Q15 fir initialization structure demands, that you pass a Q15 pointer, pointing to filter coefficients. The problem is FIR coefficients are fractional and look something like this -0.31973721625633605, 0.36052556748732778. How do I point to these coefficients with q15 pointer. Even in IAR q15 description, the cofficients are showed like this {0.3, -0.8, 0.3, 0}.  Is there a way to turn q15 into a fractional integer? if yes how?

Foo Bar
6 REPLIES 6
Posted on December 17, 2015 at 19:05

Multiply by 32768?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John F.
Senior
Posted on December 18, 2015 at 08:55

CMSIS DSP even has a function for it :

arm_float_to_q15 (float32_t *pSrc, q15_t *pDst, uint32_t blockSize) Converts the elements of the floating-point vector to Q15 vector.

matas
Associate II
Posted on December 18, 2015 at 10:41

Yes I've tried that method, but interestingly it converts float coefficients: -5.53856603E-2, 8.89228701E-1, -5.53856603E-2 to q15_t 0, 14913, 0 and after arm_fir_q15 it goes to HardFault_Handler.

Foo Bar
Posted on December 18, 2015 at 18:39

Data passed on the stack, FPU enabled?

If you show your code it might be more apparent what's going on.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 18, 2015 at 18:47

#include <
windows.h
>
#include <
stdio.h
>
#include <
math.h
>
typedef signed short int16_t;
#define Q15(x) (int16_t)(3270 * x)
int16_t Coeff[3] = { Q15(-5.53856603E-2), Q15(8.89228701E-1), Q15(-5.53856603E-2) };
int main(int argc, char **argv)
{
int i;
for(i=0; i<3; i++)
{
printf(''%04X : %ef
'', Coeff[i] & 0xFFFF, (double)Coeff[i] * (1.0 / 3270));
}
return(1);
}

F8EA : -5.535889e-002f
71D2 : 8.892212e-001f
F8EA : -5.535889e-002f

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John F.
Senior
Posted on December 21, 2015 at 12:22

For confirmation:

float Source[] = {-5.53856603E-2f, 8.89228701E-1f, -5.53856603E-2f};
q15_t Destination[3];
arm_float_to_q15(Source, Destination, 3);

result = Destination[0xF8E9, 0x71D2, 0xF8E9]