使用固定点的复杂划分 [英] Complex division using Fixed Point

查看:80
本文介绍了使用固定点的复杂划分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在编写一个C程序,在固定点上执行2个复数的划分。

I我无法从中得到分数部分。下面是更多细节。



我有2个复数:



N = a + ib

M = c + jd



我需要在固定点做N / M(不使用浮点数)



上述复数的示例值可以是:



a = 1.55,b = 1.44,c = 1.24,d = 0.55



N = 1.55 + i(1.44)

M = 1.24 + j(0.55)



为了转换为固定点,我将这些a,b,c和d乘以2 ^ 14.

之后它们变为:

a = 0x6333,b = 0x5c28,c = 0x4f5c和d = 0x2333



然后执行N / M操作我做:

N / M =(a + ib)/(c + jd)=((a + ib)*(c - jd))/((c + jd)*(c - jd))



然后单独使用实部:

(ac + bd)/(c ^ 2 + d ^ 2)



等等..



我面临的问题是我不明白如何从小部分得到分数。

我只得到小数部分,大部分是1或0.



获得正确的方法是什么分数部分?在上面的例子中,实部应该是1.47490。但是我只能得到1.



任何人都可以帮我正确地完成固定点的复杂划分吗?



非常感谢,

~Jinoj

Hello,

I'm working on writing a C program to perform division of 2 complex numbers in Fixed Point.
I'm not able to get the fractional part from it. Below is more details on it.

I have 2 complex numbers:

N = a + ib
M = c + jd

I need to do N/M in fixed point (not using floating point)

Example values for the above complex numbers can be:

a = 1.55, b = 1.44, c = 1.24, d = 0.55

N = 1.55 + i(1.44)
M = 1.24 + j(0.55)

For converting to Fixed Point, I multiply these a, b, c and d with 2^14.
After that they become:
a = 0x6333, b = 0x5c28, c = 0x4f5c and d = 0x2333

Then to perform N/M operation I do:
N/M = (a + ib)/(c + jd) = ((a + ib) * (c - jd)) / ((c + jd) * (c - jd))

Then for real part alone:
(ac + bd) / (c^2 + d^2)

and so on..

The issue I'm facing is that I'm not understanding how to get the fractional part from the division.
I'm getting only the decimal part which is mostly either 1 or 0.

What is the correct way to get the fractional part? In the above example, the real part should be something like 1.47490. But I'm able to get only 1.

Can anyone please help me with the right way in doing the complex division for Fixed Point?

Thank you very much,
~Jinoj

推荐答案

你的问题似乎是你不喜欢没有正确实现基于整数的乘法和除法。让我们从乘法开始:



你说过,你通过乘以2 ^ 14来缩放两个操作数。然后你必须通过除以2 ^ 28来缩放结果。例如:



Your problem seems to be that you don't have the integer-based multiplication and division implemented correctly. Let's start with multiplication:

You said, you scale both operands by multiplying with 2^14. Then you have to scale the result by dividing through 2^28. For example:

double a = 1.5;
double b = 3.6;

int as = (int) (a *(2<<14));
int bs = (int) (b *(2<<14));
int rss = as * bs;

double r = rss / (2<<28);



如果你想保留在基于整数的2 ^ 14系统中,你可以通过将结果除以2 ^ 14来实现。


If you want to remain in your integer based 2^14 system you can do so by scaling the result back by dividing by 2^14.

int as = (int) (a *(2<<14));
int bs = (int) (b *(2<<14));
int rs = (as * bs) >> 14;



这样结果也将缩放2 ^ 14。您可以通过

轻松将其转换为双倍


This way the result will be scaled also by 2^14. You can easily convert it to a double by

double r = ((double)rs) / (2<<14);


两者都按2 ^ 14缩放,你应该首先将被除数除以2 ^ 14的额外因子,否则结果将是未缩放的,在你的例子中大多为0或1.这是如何做到的:


Now to division: If you want to divide two quantities that have been both scaled by 2^14, you should first scale the dividend by an additional factor of 2^14, otherwise the result will be unscaled and in your example mostly 0 or 1. Here is how to do it:

int as = (int) (a *(2<<14));
int bs = (int) (b *(2<<14));
int rs = (a << 14) / b;



再次,您的结果将按2 ^ 14缩放,并且可以转换回双倍,如上所示。



请注意在32位整数的情况下,您将被限制在数字空间中小于8的整数部分。这是因为您的初始结果将缩放2 ^ 28,整数部分只留下4位其中一个是符号位。因此,您可以考虑使用long long类型进行整数运算。


Again your result will be scaled by 2^14 and can be converted back to double as shown above.

Note that in the case of 32-bit integers, you will be limited to in the number space to an integer part of smaller than 8. This is, because your initial result will be scaled by 2^28, leaving just 4 bits for the integer part, one of which is the sign bit. Hence you might consider using type long long for your integer operations.


这篇关于使用固定点的复杂划分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆