NI Home > Community > NI Discussion Forums

LabVIEW MathScript RT Module

Showing results for 
Search instead for 
Do you mean 
Reply
Member
John Essick
Posts: 7
0 Kudos

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.

Member
John Essick
Posts: 7
0 Kudos

Re: Automatic Data Type Selection for gensignal

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.

Active Participant
Jesse_D
Posts: 485
0 Kudos

Re: Automatic Data Type Selection for gensignal

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
Product Support Engineer
National Instruments

Member
John Essick
Posts: 7
0 Kudos

Re: Automatic Data Type Selection for gensignal

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?

Active Participant
Jesse_D
Posts: 485
0 Kudos

Re: Automatic Data Type Selection for gensignal

[ Edited ]

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
Product Support Engineer
National Instruments

Member
M_Vrinkle
Posts: 21
0 Kudos

Re: Automatic Data Type Selection for gensignal

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.

Member
Aldo_A
Posts: 160
0 Kudos

Re: Automatic Data Type Selection for gensignal

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
Member
M_Vrinkle
Posts: 21
0 Kudos

Re: Automatic Data Type Selection for gensignal

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

Member
Aldo_A
Posts: 160
0 Kudos

Re: Automatic Data Type Selection for gensignal

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