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

 채택된 답변

Tim McBrayer
Tim McBrayer 2016년 7월 19일

0 개 추천

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

DN
DN 2016년 7월 19일
Thanks Tim, I see what you're saying, but the only problem I can see with it is that it (the constant block) cannot take any variable inputs, can it (unless I'm missing something and you just put your variables inside)? So say for example you need y = linspace(2*dt, 5*T, 100), where at each simulation step you might have two different end-points each sim time due to dt and T. Obviously always spaced 100 slices, but your two end points changes. How would you go about doing that then?
Thanks for your help
Tim McBrayer
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
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개)

제품

질문:

DN
2016년 7월 19일

댓글:

DN
2016년 7월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by