Example Code

Uneven Integration of f(x) Over a Specified x-Range

Code and Documents

Attachment

Summary:

LabVIEW provides two basic functions for numeric integration:  the Numeric Integration.vi, and the Uneven Numeric Integration.vi.

The Numeric Integration.vi will compute an integral for an input array with a specified interval size (dt in the case of this VI).  The VI assumes an even interval spacing for all points in the input array.

The Uneven Numeric Integration.vi  computes an integral from an array of values and their corresponding horizontal-axis values (again T for this VI).

Note:  These VI’s place the values for the T array on the x-axis, and X array on the y-axis to give you a curve defined by an array of (T, X) data points.  I assume that this comes from the time-based acquisition that is traditionally thought of in DAQ systems which places time on the x-axis and some value array on the y-axis.

I ran into a case where I had a stream of acquired data in an array, for which I wanted to integrate multiple segments of the data between non-integer endpoint indexes.  To do this, I would need to extract only the sub-array data that I wanted to integrate, and then interpolate to fractional array index values to create the endpoints before calling the Uneven Numeric Integration.vi.  I decided to create a handy set of sub-VI’s that allow me to do just that.

Function:

The VI takes an uneven interval array of x-values, an array of corresponding y-values, and floating point start and end range values of “a” and “b”.  The VI then finds the (x,y) values for each endpoint, extracts the sub-array over the a-b interval, and calls the Uneven Numeric Integration.vi to compute the integral.

Steps to execute code:

  1. Drop a copy of the VI on your block diagram.
  2. Wire up inputs for your x-values, y-values, and range a, b.
  3. Inspect the returned integration result and enjoy!

  NOTE:  I have also included

Screenshots:

Integration (array) screenshot.png

VI Snippet:

Integration (array) snippet.png

VI attached below

NOTE:  I have also included front-end VI’s that use the same technique and allow integration at a specified center location and a specified width, and integration with a waveform as an input.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors