阅读:2493回复:11
搞不清: 关于C语言DSP编程的定标?
54定点DSP
1。在程序中可否出现FLOAT 类型变量?小数都定标了 2。在程序中可以定几次标?或者每个数的标值程序员都必须记住? 3。定标后溢出咋办? 比如 0。2定标Q15为0X2000(8192),此时程序中若有10*0.2则变为 10*8192〉32767溢出,因此,是否定标时还要考虑这种情况? |
|
沙发#
发布于:2003-08-19 20:03
C54x C support floats. It is IEEE format, I think, it is a 32 bits number.
Q15 etc. is just a integer representation of float. You use int as type. It can definetely overflow. |
|
板凳#
发布于:2003-08-19 20:08
to use the Q15 multiplying, try
(int)(((long)(x*Q15))>>15) |
|
地板#
发布于:2003-08-19 22:43
我的意思是自己用C写的程序,究竟是看作定点还是浮点程序?
比如 看作定点, 则sin_tab{a,b,..}中的a,b必须定标.。这也是 常 见的例子。 看作浮点,sin_tab{a,b,..}中的a,b还必须定标吗?c54不是支持浮点吗? 请指教!! |
|
地下室#
发布于:2003-08-20 08:35
\'Well, I do not think C54 has build in float support on the HW/asm level, except some related instructions such as norm and exp. Yes, the C54 c has float, that is done using compiler and very MIPS expensive.
You can think Q12, Q15 whatever you like, fixed point float or integer. C54 treat it as integer only, so you have to do the bookkeep yourself. as to sin_tab, I am not familiar with the one you talked about, but I wonder if there is a sin_tab with 2^12/4 or even 2^15/4 elements for 54. You just need to calculate the appropriate index. |
|
5楼#
发布于:2003-08-20 09:05
我觉得是否用C语言编写的是定点模拟程序,因此需将小数定标.。也就是说,在定点DSP的C程序中式无法象计算机的C语言那样随意使用小数。
上有一点不明的是,正弦表中1。0北定标为32767,这样的话,岂不是1。0+1。0〉32767溢出了吗? |
|
6楼#
发布于:2003-08-20 14:54
对C54x而言,如果用C编写程序,用小数是可以的,而且没什莫太多的限制。不过,编译器会将1.0这样的小数看成Float类型,当然程序效率比起用定点数就低很多廖。
Yingying, 偶没见过“fixed point float“这样的数字^_^ There are two types of decimal fraction: Fixed point number Float point number |
|
7楼#
发布于:2003-08-21 02:03
soory, my mistake, what I meant is:
\"it is fix point or float.\" or \'float or integer\' just got them cascaded. f1.0<==>32765 is Q15.I do not think that Q15 in C54 is used in sin table though, because it needs to reach at least pi/2. In C54, all the float mul (I am not sure about adds and subs, but I guess that it must be the same) are implemented in functions similar to xx$$MUL, which are implemented in rts.lib, you can step in to see how they do it. If possible, avoid float in C54 except in initialization and configuration. Use int or int32 for processing. |
|
8楼#
发布于:2003-08-21 20:10
能否用汉语解释,这样比较容易看懂。
还是以一个例子来说吧:要实现2.1*1.2=? 浮点程序:float a=2.1,b=1.2 ,c; c=a*b; 定点程序:现在底下定标q14后,再乘,将结果去标。 使用浮点还是定点程序?谢谢 |
|
9楼#
发布于:2003-08-21 21:36
Sorry, can not input Chinese...
1. I\'ve shown you the code for fixed point math: Say you have two Q14 of INT16, x_Q14 and y_Q14 (INT16) ( (((INT32)x_Q14)*y_Q14)>>14) On C54 c, I think INT16 is int and INT32 is long 2. You can not do 2.1*1.2 in Q14 on a 16 bits number. Q14 number can not exceed 2.0 on 16 bits. You have to make sure that it won\'t overflow and you have to keep its resolution. That is why it is pain to use. |
|
10楼#
发布于:2003-08-21 22:58
By the way, x_Q14 does not need to be a Q14 number, it can be any 16 bits integer, it can even be 32 bits integer if it won\'t overflow.
The idea is simple: You use (y_Q14/2^14) to represent your float you want to multiply,and during calculation, you use 32 bits to store the intermediate result, and use >>14 to do a quick division. You can expand the idea to any other systems. The thing to remember, you have to do the bookkeeping, knowing all the number systems you are using and convert back if necessary. Also, you have to know the range for both x and y_Q14 so that you can make sure that it won\'t overflow! Good luck |
|
11楼#
发布于:2003-08-22 12:58
54定点DSP
1。在程序中可否出现FLOAT 类型变量?小数都定标了 : //一般情况下不用FLOAT 类型变量。// 2。在程序中可以定几次标?或者每个数的标值程序员都必须记住? // 对,这一定要记住// 3。定标后溢出咋办? 比如 0。2定标Q15为0X2000(8192),此时程序中若有10*0.2则变为 10*8192〉32767溢出,因此,是否定标时还要考虑这种情况? // 这没有益出,由于54X A,B累加器都是40位,所以,你上面的 数没有益出,但是注意的是,在计算这两个数的乘机后,要除 32768,以便把乘积数定标为Q15?// // 不明白的地方,你再说好了。// |
|