HDL Coder linspace block for Simulink
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Tim McBrayer
2016-7-19
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 个评论
Tim McBrayer
2016-7-20
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
2016-7-21
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.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!