LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Performing Math funcitons on graphs of differnt sizes

Solved!
Go to solution

I will be performing some math on various graphs  

examples:

subtracting a noise graph from a signal graph -  Two measurements both in the form of a graph ( which is just a 2d array) being subtracted from each other

or multiplying two graphs together - in my case used to multiply standard observer graphs against a light spectrum measurement (output is to calculate color coordinates of the measured light spectrum)

 

Main point being, these graphs could be different sized arrays.  One graph could have a resolution of 0.1 on the x-axis and another could go up by say 10.  I can make it so both would start and stop at the same point (range from 350nm to 800nm) but one graph may be more precise than the other.

 

My thought is that I would make some code that uses linear interpolation and some other logic to "fill in the blanks" on each graph and make them so they are same sized arrays with the same X axis points.  That way I can perform any kind of math by just wiring the arrays to basic math components.  But I wanted to make sure there is not some easy solution already out there that I'm overlooking. 

 

Any ideas ?  Or should I just make my own..

 

 

0 Kudos
Message 1 of 8
(2,985 Views)

You are on the right track making your arrays the same size. If your higher sampled array is an integer factor denser than your other array, you could use decimate array but only configured at edit time. Otherwise you can use a mix of threshold and interpolate array to get the corresponding values.

 

 

Message 2 of 8
(2,973 Views)

Where does the x-information come from? Are these xy graphs?

 

All you probably need is a new x-ramp (using ramp pattern), then use "interpolate array" to create the new dataset. This is especially easy the data data is an array of xy points (else you might also need a threshold array somewhere).

 

Can you attach a simple Vi containing typical data?

0 Kudos
Message 3 of 8
(2,972 Views)

yes I am basically using an XY array, there are two 1D arrays bundled into a cluster to view them on a graph. the X data comes from the instrument and is an array ranging from around 330 to 800 (nano meters).

 

Attached is a sample of the light signal XY data (1024 samples) and a constant I've called the "Standard Observer XY " (99 points) used for part of a calculation.  Both have different start and stop X points (wavelength) and different sample rates.

 

In this case i would want to multiply the two sets of data, but the number of samples needs to match and the values of x would also.  So missing data needs to be interpolated.  Ideally in the end i would end up with a vi that takes any input waveform and spits out a modified waveform that fits a definition ( startX, stopX, XstepSize).  this way the same vi could be used as a "Wave Form Manipulator.vi" to preconfigure each waveform before starting any math on it.  

0 Kudos
Message 4 of 8
(2,947 Views)
Solution
Accepted by topic author Tim30

See if this works for you.

resample.png

 

(Just a very rough draft. Modify as needed.)

 

Message 5 of 8
(2,934 Views)

Maybe I'm over thinking it and needed some lunch...  Here I used "linear interpolation 1D" to make the best guess.  I tried using interpolate 1D Array without much luck...  Guess I would just fit one curve to the others "X array" (Xi) to create the new Xi, Yi that has the matching sample times.  and chop off anything below the specified Xmin and anything above the specified Xmax...

 

 

 

0 Kudos
Message 6 of 8
(2,933 Views)

Thanks Altenbach,  I'll check that out also.

0 Kudos
Message 7 of 8
(2,931 Views)

Ya this works great.  Actually it gives the exact same results as using "Interpolate 1D.vi" except for the trail off at the end..

 

If anyone wants it, attached was the final check of the two methods.

0 Kudos
Message 8 of 8
(2,916 Views)