2015-12-17 08:33 AM
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?
2015-12-17 10:05 AM
Multiply by 32768?
2015-12-17 11:55 PM
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.2015-12-18 01:41 AM
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.
2015-12-18 09:39 AM
Data passed on the stack, FPU enabled?
If you show your code it might be more apparent what's going on.2015-12-18 09:47 AM
#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
2015-12-21 03:22 AM
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]