PDA

View Full Version : Simulink: ufix & sfix no workie with Math Function block!?!


Frequitude
06-21-2005, 07:04 AM
This is for the Engineers and Matlab enthusiasts out there.

I have a Simulink model that runs great in floating point but I want to make it run in fixed point. Most numbers in the model range from -1 to 1, so I would like to use the sfix32 or ufix32 data type to maintain maximum accuracy through binary point scaling.

Most blocks are working great with sfix32, but the Math Function block does not. It requires primitive Matlab data types, such as single, double, int8, uint32, etc. Math Function includes such functions as e^u, log(u), mod(u). These are very important and should be common to many models.

The thing is, none of these primitive fixed point formats have binary point scaling (right?). So you can't represent decimal places and are restricted to integer numbers.

How the heck can I use the Math Function Block functions on fixed-point numbers that have many decimal places?????

Thanks,
freq

adios
06-21-2005, 10:41 AM
Don't know if I'll be much help here but possibly. I assume that sfix32 and ufix32 are scaled 32 bit number formats with a binary point somewhere. If I'm right where might that binary point be out of curiosity? Anyway you can probably do all of these doing the fixed point arithimetic using uint32 but to make a long story short you'll have to maintain the binary point in your code and convert the output (I assume you're displaying results to a precision that requires a decimal point in the display) to display the results. If by mod(u) it's modulo a given number that should be fairly easy to implement.

I assume you don't want to use floating point because your target processor doesn't support it and/or for speed considerations. Is that right?

Frequitude
06-21-2005, 11:06 AM
Thanks for the input!


[ QUOTE ]
Don't know if I'll be much help here but possibly. I assume that sfix32 and ufix32 are scaled 32 bit number formats with a binary point somewhere.

[/ QUOTE ]
ufix and sfix are generalized fixed point data types that come with Mathworks's Fixed Point Toolbox. They let you specify the scaling...either binary point scaling, or slope-bias scaling. u is unsigned, s is signed, and I want to use 32bit numbers.


[ QUOTE ]
If I'm right where might that binary point be out of curiosity?

[/ QUOTE ]
Approximately 29 binary point places, give or take 1 or 2 depending on the block. For sfix32, this would give me a range of approximately -4 to 4, with a precision of 0.5^29. That is TONS for my application and data range. I'm using the Fixed Point Autoscaler to set the scaling for me.


[ QUOTE ]
Anyway you can probably do all of these doing the fixed point arithimetic using uint32 but to make a long story short you'll have to maintain the binary point in your code and convert the output (I assume you're displaying results to a precision that requires a decimal point in the display) to display the results. If by mod(u) it's modulo a given number that should be fairly easy to implement.

[/ QUOTE ]
Yeah, I was trying to avoid this. The code is being written in Simulink (boss's orders), so this would be a much bigger bitch than just writing in C.


[ QUOTE ]
I assume you don't want to use floating point because your target processor doesn't support it and/or for speed considerations. Is that right?

[/ QUOTE ]
It supports it, but my boss wants fixed point. I'm using the Motorola MPC555.



For such common functions that are in the Math Function block, I can't belive ufix and sfix won't work!!! I mean, you can filter them, fourier them, etc, but you can't use log(u)??????? /images/graemlins/confused.gif

adios
06-21-2005, 11:25 AM
See if the vendor is willing to fix this, is currently fixing it, and/or knows someone that has. See how much it would cost. Perhaps try and understand why your boss doesn't want to use floating point. Sometimes the reasons are irrational /images/graemlins/smile.gif.

Frequitude
06-21-2005, 01:24 PM
[ QUOTE ]
See if the vendor is willing to fix this, is currently fixing it, and/or knows someone that has. See how much it would cost. Perhaps try and understand why your boss doesn't want to use floating point. Sometimes the reasons are irrational /images/graemlins/smile.gif.

[/ QUOTE ]


I've sent an email to Mathworks support...but the last one took 4 months to hear back from.

As for what my boss was saying, this project is more about figuring out how to program a microcontroller using the Real-Time Workshop and to test various things along the way, i.e. fixed point support. It's not so much about getting a fully embedded solution to work. Otherwise I would have just used CodeWarrior and C!