Trouble using fixed point type conversion in Simulink
Show older comments
Hello,
I have a fairly large system I am converting to fixed point. I have made some progress by setting the input data types accordingly, and Simulink ripples the fixed-point types through the system. If I was happy with the bit widths, I'd be finished because the fixed point output matches the reference output.
However, I am trying to reduce bit widths. In one part of the system, Simulink gives a signal the type sfix31_En3, also known as fixdt(1, 31, 3). I want to reduce this to 24 bits. The largest value is 9107852, and ceil(log2(9107852)) = 24, so I need 24 bits to the left of the binary point, plus sign bit. To get that into a 24-bit signed representation, I need fixdt(1, 24, -1), hence the LSB is 2^1 not 2^0.
I have a Data Type Conversion block set to use this data type. However, it does not work according to my expectations. What I expect to see as an output is the same as if I were to take the input signal and cast it like so:
new_sig = fi(old_sig, 1, 24, -1)
or, if instead I defined truncated = fixdt(1, 24, -1), I can do this
new_sig = fi(old_sig, truncated)
When I apply the above line to the sfix21_En3 signal logged in Simulink, the result is as I expect. But when I specify that the type conversion block use fixdt(1, 24, -1), I get a "Warning: Parameter precision loss" message:
The original value of the parameter, -1, cannot be represented exactly using the run-time data type sfix24_E1. The value
is quantized to 0. Quantization error occurred with an absolute difference of 1 and a relative difference of 100%.
Also, the signal definitely does not look right - every other sample is set to zero, where it should be between 10^5 and 10^6.
I feel like I'm missing something in the use of this type conversion block. What's the proper way to reduce the bit width of a signal and get the binary point in the right place?
Thanks for any help/advice.
Charles
Accepted Answer
More Answers (0)
Categories
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!