Example Code

Error detection in Integration and Derivation using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW Advanced Signal Processing Toolkit
  • LabVIEW

Code and Documents

Attachment

1. Overview

This example illustrates the results obtained by changing the precision used when performing integration and derivation in LabVIEW. The VI uses a sine wave of doubles, modifies the input’s precision, and changes the number of samples.

 

2. Description

The precision of the analysis library is just a double, you can find more in the LabVIEW 7.1 Help on how those functions specifically calculate the integrals and derivatives. Please note that in LabVIEW 2009 the VIs are expanded to integrate/derive with different methods.

The LabVIEW Analysis Library offers VIs to conduct numeric integration and derivation. As with most numeric processes, small error can cause inaccuracies in results. I have an attached VI provides an example of integrating a sine wave twice and deriving it twice and how the precision and number of samples affect the results.

We are using Simpson’s Rule, of which you can calculate an error bound in order to help find out how many samples are you going to need to meet a certain accuracy. The results we are seeing are not only due to the precision, but the inherent error associated with numeric integration due to the number of samples used and the method used.

I have put together a testing VI to illustrate the fact that precision is only part of the issue. In the top portion of the block diagram I use a sine wave of 1 V represented as a double, and it matches very closely to what you see in the original screenshot of this forum. In the middle section of the block diagram we modify the input to the functions by changing the precision of the input. In the bottom of the block diagram we move back to the double precision, but change the number of samples.

As we increase the precision, the difference between the original sine wave and the final output from the two integrations and two differentiations (the error), gets less noisy, not smaller. Yet, as we increase the number of samples in the sine wave the error term gets smaller, and generally less noisy. If we just look at the first set of data that is unmodified in precision or number of samples and just increase the number of samples (third set of data) from 10,000 to 12,589 (10^4.1) the error maximum is reduced from 1.31802E-7 to 8.34427E-8 (and the standard deviation gets less too) where as if we the precision from 8 to 17 points we notice that the error does get smaller, but not as much (less significance on the standard deviation too).

 

3. Requirements

  • NI LabVIEW Professional Development System 2012 or compatible.

 

4. Steps to Implement or Execute Code

  1. Download and open the VI “Error detection in Integration and Derivation LabVIEW 2012 NIVerified.vi”
  2. Select a Precision and a value to Increase number of samples by power of ten.
  3. Run the VI.
  4. Analyze the generated waveforms and the data in the right portion of the front panel.

 

5. Additional Information or References

 

Error detection in Integration and Derivation Screenshot.PNG

 

Error detection in Integration and Derivation FP Screenshot.png

 

**The code for this example has been edited to meet the new Community Example Style Guidelines.**

Joshua B.
National Instruments

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