开发者

Fixed Point Development

开发者 https://www.devze.com 2023-03-14 12:54 出处:网络
I\'m working on some fixed point coding these days. If I have a bunch of 16 bit samples fr开发者_Python百科om an ADC and I do multiplication with a 16 bit filter coefficient, the result could be a 32

I'm working on some fixed point coding these days.

If I have a bunch of 16 bit samples fr开发者_Python百科om an ADC and I do multiplication with a 16 bit filter coefficient, the result could be a 32 bit fixed point number right? Now that's fine because I'm targeting a 32 bit fixed point DSP. However, if I want to multiply that by another 16 bit fixed point coefficient or something then I get overflow right? So does that mean I need to do intermediate truncation? Eventually I'll be truncating anyway because I need to send the result to a 16 bit DAC.

Does anyone have experience with doing this in MATLAB?

EDIT I do have fixed point toolbox. What I don't understand is that right now if I set up a number with a 16 bit word length, then set the max product length to 16, then multiply it by another 16 bit word it gives me an error? If I have to perform all the truncations to prevent an error how does the fixed point toolbox even really help me? I guess I'm looking for an example on how to use the fixed point toolbox to ensure best possible rounding/overflow conditions given that my inputs are 16 bits and I have 32 bit registers.

Thanks


As you noted, a 16-bit multiply can result in a 32-bit result. In continuing, I'm assuming you're fixed-point notation is 16.16.

In order to perform your second multiplication, you should first shift the initial mul's result back down by 16 bits. Since the result is now back into the desired 16.16 format, you may proceed with the second mul ("...if I want to multiply that by another 16 bit fixed point coefficient..."). After this second multiplication, shift the result down by 16 bits to restore the 16.16 notation.

Before shipping the value out the DAC, I would expect that you need to leave fixed-point notation and revert to integer form. To do this, simply shift the value down by 16 bits. Before leaving fixed-point notation, you might consider rounding the result. Assuming a positive fixed-point number, this can be accomplished by adding 0.5f to the result prior to the final right shift. (In 16.16, 0.5f is 2^15.)

As always, sequential fixed-point arithmetic operations should be studied closely to avoid overflowing the left hand side. The operations may be re-ordered or factored to prevent overflow. There are a number of good tutorials on the web that can help tutorial.

As for performing fixed-point math in matlab, the bitshift functions are easy enough to use: reference. Of course, the fixed-point toolbox makes this all the more easy.

0

精彩评论

暂无评论...
验证码 换一张
取 消