From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-06-2011 06:59 PM
I'm trying to understand how Mathscript's automatic data type feature is working when I use the function gensignal in my code. In the attached VI called "Gensignal Alone," the correct data type 1D DBL is automatically determined. But in the VI "Waveform Simulator," where gensignal is embedded in an if-else statement, Mathscript incorrectly chooses 2D DBL. I realize I can override this choice with the correct 1D DBL, but I'm wondering why the if-else statement causes this 2D data type choice by LabVIEW, and concerned that there might be some hidden error in my code forcing this choice.
09-07-2011 12:08 PM
I've made some progress in my understanding and found that the AD array automatic data type in the Waveform Simulator VI results from the fact that the x-array produced by all of the if-else cases are row vectors, but gensignal creates the x-array as a column vector. My question now is why the function calls in the Mathscript Node sometimes produce row vectors, while other times column vectors and if there is a way to control that.
09-08-2011 11:09 AM
Hi John,
you can just change the gensignal line to:
x=(A*gensignal('square', 1/f, stop, step))'
" ' " is a transpose function.
What the function returns is specific to each function. You can find a reference for all the mathscript functions, complete with return parameters in the LabVIEW help.
09-09-2011 07:40 AM
Thanks, Jesse. Is there a consistent pattern followed in the Mathscript functions, that allows a programmer to know whether a function will produce a row or a column vector as it output. This information is not included in the help window of the Mathscript finctions, only the data type is given. The ony way I was able to figure out what was happening was to use the Context Help and place the mouse cursor over each variable within the Mathscript Node after it was programmed. If there is no consistent pattern for output variable production now, are there plans to eventually make all function, say, produce row vectors? Or is there some reason that it is useful for the cosine function to produce a row vector and the gensignal function to produce a column vector?
09-09-2011 10:12 AM - edited 09-09-2011 10:12 AM
I just went through the waveform generation pallete. It appears that the functions there return row vectors, excepting gensignal. I will look into it little more and see if I can find a reason for this.
You can probe what is going on the the mathscript node though. Simply right click in the node and select "Probe" to create a probe. You can then see very easily whether a return parameter is a row or column
04-17-2012 05:40 PM
I am also playing around with gensignal within a mathscript node using elseif cases, and have figured out that I need to transpose the data. I have compared A*sin(2*pi*f*t) with A*transpose(x), where x is obtained from gensignal, in the Mathscript window and they are the same. While I can plot a nice sinewave using the former, only a flat line gets plotted with the latter. Any ideas?
Thanks so much.
04-18-2012 09:17 PM
Hi M Vrinkle,
It looks like your stop and step paramaters are what are causing the problem. When the first gensignal creating the sine wave uses them, they are not re-initialized causing the flatline for the square wave. Either re-initialize the step and stop paramaters or simply remove them from the function's parameters.
Hope this helps!
04-19-2012 05:05 PM
Hi Aldo A,
Great, it works! I followed your suggestion and removed the step and stop parameters from the gensignal parameters. Now I would like to try your other suggestion. What would be a good way to re-initialize the step and stop parameters?
Thanks for the fast response!
M Vrinkle
04-20-2012 06:25 PM
Hi M Vrinkle,
One of the options you have since your code is not complex is that you can just add the code snippet:
start = 0
step = delta_t
stop = (N-1)*delta_t
after each of the conditional branches (elseif) to re-initialize the step/stop variables before you call gensignal.
i.e.
elseif s==3
start = 0
step = delta_t
stop = (N-1)*delta_t
x = gensignal('square', delta_t, stop, step)
x = transpose(x)
Let me know if this helps!