Example Code

Interpolation: Map new Y values from one XY file onto the corresponding X values of another file.

Code and Documents

Attachment

Functional Description

This VI opens two ASCII XY files which have very similar X values, for example, a simulation of a cyclic voltammogram and corresponding experimental data.  The VI then generate a new Y value (from the second file's data) for every X value in the first file.  The result is a set of XY data points that correspond to the data in the second file, but which can be compared point-by-point with the data in the first file.  The two files do not have to have the same number of points.

Caveats and Additional Notes

This program is useful when one needs to do a point by point comparison (e.g. a subtraction or something) of two files which have different X-axis intervals.  The intervals do not have to be regular.

3 VI's are included in the attached zip file.

general file display.vi  opens just about any ASCII file which has XY values in it in a pair of columns.  You can switch the X and Y axes with a toggle switch.  It can deal with tab delimiters, spaces or commas, and it ignores header lines.  It opens the "Fast Scan CV.vi" files, EG&G PAR M270 CV files, Ocean optics spectra, and probably a bunch more.  A pretty robust vi.

interpolate.vi will solve the equation y=mx+b from a pair of XY values, and it will return a new Y value in response to a new X value.

interpolate data sets.vi  is the main program.  For every X value in the first data set, it will find the two X values from the second data set between which the X value from the first data set fits.  It then calls interpolate.vi to find the new Y value from the second data set's Y values by linear interpolation.

Sample files are included.

may28_de.prn is the text output from Carlo Nervi's ESP2.4 for an EE mechanism for the same X-range as the experimental file.

MAY28DE is an experimental CV which shows interesting electron transfer catalysis effects discussed in J. Am. Chem. Soc. 1998, 119, 2804.

This program is based on a Quickbasic program I developed in the mid-1990's.  the Quickbasic program was very finicky in terms of getting the exact file format correct, but I have included it in the zip file for completeness.  Interestingly the Quickbasic code is a lot less complex than the vi, partially because the use of some "spaghetti" code... apologies.

More information on previous uses has been included in my blog.

Previous and current (CHE 0911537) support by NSF is gratefully acknowledged for this work.

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

Contributors