Wave math question

Hi, this is a fairly simple question, but I was having trouble finding an answer so I figured I would just ask.

In my program, I want to subtract one wave from another. However the way my data is collected causes the waves to be aligned by x value, not by point (i.e. zero time does not fall on the same point for each wave). If I just subtract the waves normally (wave3=wave1-wave2), it subtracts by point and my waves are not aligned.

Is there a simple way to subtract waves by x instead of by point?

Thanks
-Alex
Assuming they have the same x-scale but have an offset, you could shift one before subtracting them.

Do you have x-waves? if so you could interpolate wave2 at the x-values of wave 1 and subtract.

variable i, x
wave wave1, wave1x, wave2, wave2x, wave3
for(i=0; i<numpnts(wave1); i+=1)
  x = wave1x[i]
  wave3 = wave1 - interp(x, wave2x, wave2)
endfor
If you have set the X scaling of wave3 appropriately, then you should be able to do
wave3 = wave1(x) - wave2(x)
The round parentheses indicate indexing by X value.

If the X scaling of the three waves is not coincident, you may want to take a look at the Wave Arithmetic package: Analysis menu->Packages->Wave Arithmetic. There is a demo: File->Example Experiments->Analysis->Wave Arithmetic Panel Demo.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
As John noted there is difficulty if the x ranges of the waves are not equal. If you do
wave3 = wave1(x) - wave2(x)

you will get an error if any X value of wave3 is out of range for either wave1 or wave2.

You can do this:
wave3 = NaN
wave3(x0,x1) = wave1(x) - wave2(x)

where x0 is the smallest x value that is valid for both wave1 and wave2 and x1 is the largest X value that is valid for both wave1 and wave2.

Or you can construct wave3 and set its X scaling so that its range of X values is valid for both wave1 and wave2.

As John noted, Wave Arithmetic Panel Demo handles this for you. It also handles the case of XY pairs, I think.