HDL Coder linspace block for Simulink
12 views (last 30 days)
Show older comments
Hi, does anyone know if there is already a linspace() block for HDL coder which I can use in a Simulink design. I know you can just use a "user defined function block", given most HDL Coder Matlab scripts you see contain a linspace() command somewhere anyway, so it's nothing revolutionary, but I was wondering more from a aesthetically pleasing point of view to keep everything within Simulink if there is no block already in a library which I cant see.
Thanks in advance
0 Comments
Accepted Answer
Tim McBrayer
on 19 Jul 2016
As I understand it you want a constant value in Simulink that emulates the linspace command. If this is what you are asking for, you can just use a Constant block, where the constant value is specified using the linspace function.
For example, if a Constant block has its constant value set to:
linspace(0, 7, 16)
You get a 16-element vector evenly spaced over the range [0, 7] as the output.
3 Comments
Tim McBrayer
on 20 Jul 2016
That does add another wrinkle to this, doesn't it? I'm not sure that the new requirement is easy to do in hardware. You want an arbitrary range to be divided into an arbitrary number of segments, at runtime, in hardware. This is generally going to require division, which many synthesis tools don't directly support. HDL Coder supports an iterative approximation of division using Newton-Raphson algorithm.
If your number of segments is a fixed value so that the denominator evaluates to an integer power of 2, the division may be able to be implemented by a right shift of the appropriate distance; synthesis tools will even do this for you.
If I were you I'd think about what it is you need these linspace values for, what hardware it may make, and if there is a serial approach (linspace is inherently parallel) to reach your goal.
DN
on 21 Jul 2016
Eehmm...I think you misunderstand with the 1st paragraph, 2nd one I agree....but 1st paragraph it's not "divided into arbitrary number of segments". Look at the equation, 100 is fixed, only the range changes, which can just be persistent variables, right? You must just make sure you your tick your variable size in your output ports of your user defined function block.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!