LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Derivate a waveform from a Function generator

I want to use the derivate of a waveform from a Function generator in a Formula node,  but unfortunatelly I dont no how can i do this. I need the exact value of the derivate ("qpg" input variable) to use in the equation in the Formula Node.

 

I found a Derivate sub VI, but it gives me the derivate as a vector so i cant wire it as an input to the Formula node.

 

I attached pictures about my VI.

 

 

0 Kudos
Message 1 of 5
(3,229 Views)

0101.JPG

02.JPG

0 Kudos
Message 2 of 5
(3,228 Views)

You can indeed wire an array to a formula node input.  To connect the wire -- there's no special command, etc.

 

formula node.png

0 Kudos
Message 3 of 5
(3,210 Views)

Why do you want to use a formula node for such simple calculations? Just use the arithmetic primitives from the Numeric palette. 

 

If you want to go the opposite direction from what Zwired1 suggested, you can use Index Array to get a particular element from the Derivative VI or you can put the formula node inside a for loop with autoindexing to calculate the same thing you would get with array inputs and outputs.

 

You use of a scalar indicator for Numeric and a local variable shows a lack of understanding of LabVIEW's data structures and preferred programming techniques.The output of the Function Generator is a waveform datatype, which is a cluster of at least three elements: t0 = the start time of the waveform, dt = the time interval between elements, Y = array of elements, and optional attributes.  The default settings generate a Y array of 1000 elements. Of the 1002 possible values in the waveform, which one is displayed in Numeric? Is it the one you want?

 

Local variables should vary rarely be used in LV. They are not truly variables but are remote access points for the indicator terminal. They are slow, generate extra data copies, and are prone to race conditions. In fact you have a race condition in the code segment shown in your image. The value of the Numeric local variable (wired to qg) will almost certainly be read before the Function Generator VI produces an output to the indicator terminal.

 

Lynn

0 Kudos
Message 4 of 5
(3,175 Views)

As I understand it, you are using a Waveform Generator VI, and want (in addition to the Waveform) an additional output that is (an estimate of) the derivative of the Waveform.

 

If you consider the Waveform Generator as a "black box", something whose internals you don't know, but something that produces a new output every delta-t time increment (I'm going to call this "dt"), then you really do need to estimate the derivative.  Note that since you cannot "predict the future", to estimate the derivative, you need the current data and previous data.  One very common estimate for the derivative x'(t) at time t is (x(t) - x(t-dt))/dt, that is, the difference between the current point and the previous point, divided by the time increment.  For a waveform generator, this will probably be a pretty good estimate, as the data should be relatively "smooth" and noise-free.  Do note, however, that this estimate is really over the time interval t-dt and t, so you could consider it shifted backward in time by dt/2.

 

If you want a more accurate estimate of the derivative, one "centered" on the current time, t, then your formula needs to take into account not only the current value and past values but also future values.  This is the reason many "derivative functions" use vectors, as this contains past and present values (with some worry about what to do at the beginning and end of the data).

 

On the other hand, if you are generating the data yourself (that is, if you have a VI that you input t and it outputs f(t)) and you have a "nice" function f (say a sinusoid or other non-random function), you can get the "exact" derivative just by programming it.  For example, if f(t) = sin (omega * t), then f'(t) = omega * cos (omega * t).

 

Bob Schor

0 Kudos
Message 5 of 5
(3,142 Views)