LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic Data Type Selection for gensignal

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.

Download All
0 Kudos
Message 1 of 9
(7,135 Views)

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.

0 Kudos
Message 2 of 9
(7,121 Views)

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

 

 

Jesse Dennis
Engineer
INTP
0 Kudos
Message 3 of 9
(7,101 Views)

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?

0 Kudos
Message 4 of 9
(7,091 Views)

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 

Jesse Dennis
Engineer
INTP
0 Kudos
Message 5 of 9
(7,082 Views)

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.

0 Kudos
Message 6 of 9
(6,998 Views)

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.

 

StopStep.png

 

Hope this helps!

 

 

Aldo A
Applications Engineer
National Instruments
0 Kudos
Message 7 of 9
(6,982 Views)

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

0 Kudos
Message 8 of 9
(6,975 Views)

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!

 

 

Aldo A
Applications Engineer
National Instruments
0 Kudos
Message 9 of 9
(6,959 Views)