Not applicable
Jul 03, 2017
01:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 03, 2017
01:25 AM
Hello All,
I want to use square root api provided with math library :
int16_t XMC_MATH_CORDIC_Q15_Sqrt(int16_t x) and
int32_t XMC_MATH_CORDIC_Q31_Sqrt(int32_t x)
But I am not getting the desired results.
Is there any changes has to be made for getting the result, like some sort of number format?
Suppose I want to find the square root of 144 and 34567. what steps I have to follow to get the desired result?
Argument x has to be converted in which data format and result will be in which format?
Please guide me!
Regards,
Tinchu
I want to use square root api provided with math library :
int16_t XMC_MATH_CORDIC_Q15_Sqrt(int16_t x) and
int32_t XMC_MATH_CORDIC_Q31_Sqrt(int32_t x)
But I am not getting the desired results.
Is there any changes has to be made for getting the result, like some sort of number format?
Suppose I want to find the square root of 144 and 34567. what steps I have to follow to get the desired result?
Argument x has to be converted in which data format and result will be in which format?
Please guide me!
Regards,
Tinchu
- Tags:
- IFX
15 Replies
Jul 03, 2017
08:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 03, 2017
08:27 AM
The function names say all.
Q15 and Q31 format.
Q15 and Q31 format.
Not applicable
Jul 03, 2017
10:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 03, 2017
10:28 AM
Q15 and Q31 format for argument or return value or for both?
Have you used these API?
If yes then could you please share some code
Have you used these API?
If yes then could you please share some code
Not applicable
Jul 03, 2017
10:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 03, 2017
10:02 PM
Any one could please tell me how to use sqrt api in math.h
If I want to find the square root of
144
200
1000
50000
which API should I use and how to interpret the result
If I want to find the square root of
144
200
1000
50000
which API should I use and how to interpret the result
Jul 04, 2017
01:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 04, 2017
01:31 AM
Hi,
The functions as explained receive and return Q31 or Q15. In these format you can represent numbers in the range (1.0,-1.0). So you will need to use scaling factors.
If you want to use the sqrt from the standard library:
Here the result should be the same as in the first example 0x40000000 is quivalent to 0.5F in signed Q31.
Regards,
Jesus
The functions as explained receive and return Q31 or Q15. In these format you can represent numbers in the range (1.0,-1.0). So you will need to use scaling factors.
#include
#include "xmc_math.h"
__STATIC_INLINE float q15_to_float(int16_t a) { return (float)a / 0x8000; }
__STATIC_INLINE float q31_to_float(int32_t a) { return (float)a / 0x80000000; }
__STATIC_INLINE int32_t float_to_q15(float a) { return (int16_t)((a * 0x8000) + 0.5); }
__STATIC_INLINE int32_t float_to_q31(float a) { return (int32_t)((a * 0x80000000) + 0.5); }
int main(void)
{
int32_t a;
float b;
a = XMC_MATH_CORDIC_Q31_Sqrt(0x40000000);
b = q31_to_float(a);
...
If you want to use the sqrt from the standard library:
#include
int main(void)
{
float b;
b = sqrtf(0.5F);
...
Here the result should be the same as in the first example 0x40000000 is quivalent to 0.5F in signed Q31.
Regards,
Jesus
Jul 04, 2017
02:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 04, 2017
02:12 AM
BTW: If you want to use floating point in cortex M0, you may want to give a try at https://www.quinapalus.com/qfplib.html
Not applicable
Jul 04, 2017
03:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 04, 2017
03:31 AM
@jferreira : Thanks for your kind reply
In both cases I am getting result zero.
You can try any number and see the result.
For finding the square root of 144 and 34567, Am i following the correct rule shown above?
Could you please guide me for the above two values
float f;
int32_t x, y;
f = 144.0;
y = float_to_q15(f);
x = XMC_MATH_CORDIC_Q15_Sqrt((int16_t)y);
y = q15_to_float((int16_t)x);
f = 34567.0;
y = float_to_q31(f);
x = XMC_MATH_CORDIC_Q31_Sqrt(y);
y = q31_to_float((int32_t)x);
In both cases I am getting result zero.
You can try any number and see the result.
For finding the square root of 144 and 34567, Am i following the correct rule shown above?
Could you please guide me for the above two values
Not applicable
Jul 05, 2017
12:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 05, 2017
12:49 AM
Any one to help and guide me?
Jul 05, 2017
10:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 05, 2017
10:00 AM
You don't understand Q Format.
It could only represent [-1,1) range.
You will need to normalize the input and output.
It could only represent [-1,1) range.
You will need to normalize the input and output.
Not applicable
Jul 05, 2017
10:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 05, 2017
10:11 AM
So for 144 and 34567, I have to use
float_to_Q15(144) and float_to_Q31(34567) first before calling sqrt function?
How will I get values -1 To 1 for 144 and 34567?
I couldnt understand this logic.
Please guide me what need to be done for any value.
float_to_Q15(144) and float_to_Q31(34567) first before calling sqrt function?
How will I get values -1 To 1 for 144 and 34567?
I couldnt understand this logic.
Please guide me what need to be done for any value.
Not applicable
Jul 05, 2017
11:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 05, 2017
11:00 PM
Any one who can tell me how can I convert any number like 200, 1000 ... to Q15 or Q31 format?
Jul 06, 2017
08:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 06, 2017
08:48 AM
Conversion
Float to Q
To convert a number from floating point to Qm.n format:
Multiply the floating point number by 2n
Round to the nearest integer
Q to float
To convert a number from Qm.n format to floating point:
Convert the number to floating point as if it were an integer, in other words remove the binary point
Multiply by 2?n
Float to Q
To convert a number from floating point to Qm.n format:
Multiply the floating point number by 2n
Round to the nearest integer
Q to float
To convert a number from Qm.n format to floating point:
Convert the number to floating point as if it were an integer, in other words remove the binary point
Multiply by 2?n
Jul 06, 2017
08:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 06, 2017
08:49 AM
Not applicable
Jul 06, 2017
10:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 06, 2017
10:15 AM
@aurixuser previously as per you
Now if I try to change 200 to Q15
But this value is greater than 1. Moreover 200 is not a floating point number, so is it required to change it to Q format?
Its a request can you please give me an example for just one value like 200, 1500 to find the square root using API defined in math.h
So that not only me but others can also understand the concept.
You don't understand Q Format.
It could only represent [-1,1) range.
You will need to normalize the input and output.
Now if I try to change 200 to Q15
200 * 2^15 = 200 * 32768 = 6553600
But this value is greater than 1. Moreover 200 is not a floating point number, so is it required to change it to Q format?
Its a request can you please give me an example for just one value like 200, 1500 to find the square root using API defined in math.h
So that not only me but others can also understand the concept.
Jul 07, 2017
08:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 07, 2017
08:33 AM
For example.
//First , normalization
float v1_f = 200/32767.0;
float v2_f = 32767/2147483647.0;
//second, convert the normalized results into Q Format
v1_q15 = float_to_q15(v1_f);
v2_q31 = float_to_q31(v2_f);
//Third, do the Q format math
......
....
//Finally, convert the result of Q Format math into the final float result if you need, it is optional
float result_1_f = q15_to_float(result_1_q15);
float result_2_f = q31_to_float(result_2_q31);
//First , normalization
float v1_f = 200/32767.0;
float v2_f = 32767/2147483647.0;
//second, convert the normalized results into Q Format
v1_q15 = float_to_q15(v1_f);
v2_q31 = float_to_q31(v2_f);
//Third, do the Q format math
......
....
//Finally, convert the result of Q Format math into the final float result if you need, it is optional
float result_1_f = q15_to_float(result_1_q15);
float result_2_f = q31_to_float(result_2_q31);
Aug 08, 2019
02:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 08, 2019
02:22 PM
It is incredible, how a beginner user couldn't receive any descent support in this forum. I am very dissapointed with the kind of answers from an advanced user.