Scaled waves difference

Dear experts,

I am trying to understand the way wave interpolation and differences in Igor Pro works.
I will try to be as short as possible.

I have two sets waves:

spectre1 = {10,12,14,16,19,33,98, 78, 56, 33, 21,12,10, 8} —> 14 pts.
temp1 = {10, 20 ,30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,140} —> 14 pts.

spectre2 = {14,19,32,89,102,93,83, 78, 45, 30, 20,10} —> 12 pts.
temp2 = {11, 22 ,31, 41, 52, 63, 71, 82, 91, 103, 111, 122} —> 12 pts.

with different number of points.
Now I need to plot both spectra with its own temperature and make their difference. For this I first try to interpolate and scale the data using the following function :
Function InterpMe(Temp1, Temp2, spectre1,spectre2, InterpolatedSpectre1, InterpolatedSpectre2, PointsNumbers)
Wave/D Temp1, Temp2
Wave/D spectre1, spectre2
String InterpolatedSpectre1
String InterpolatedSpectre2
Variable PointsNumbers
Make/O/N=(PointsNumbers) $InterpolatedSpectre1
Make/O/N=(PointsNumbers) $InterpolatedSpectre2
Wave SpectreData1= $InterpolatedSpectre1
Wave SpectreData2= $InterpolatedSpectre2
WaveStats/Q Temp1
SetScale/I x V_min, V_max, SpectreData1
SpectreData1 = interp(x, Temp1, spectre1)
WaveStats/Q Temp2
SetScale/I x V_min, V_max, SpectreData2
SpectreData2 = interp(x, Temp2, spectre2)
End


Finally I end up with two waves, each scaled with the same number of points (let’s say 500). The only problem I have now is to make the “good” difference of this two waves.

Thanks,
T
Hi tutor,

I would suggest that the interpolation only be done over the range of points that is common to both "spectre" waves. Then the difference wave is created with this same x-scaling and the difference can be done using point values instead of scaled x values.

Your modified function is shown below. Along with a plot of the results. The difference plotted is Spectre1 - Spectre2.

You could interpolate/extrapolate both "spectre" waves over the range defined by the absolute min and max x values for both input waves, if you feel this is appropriate. That code is included, but commented out in the function below. The plot does not show this result.

Function InterpMe(Temp1, Temp2, spectre1,spectre2, InterpolatedSpectre1, InterpolatedSpectre2, PointsNumbers)

Wave/D Temp1, Temp2
Wave/D spectre1, spectre2
String InterpolatedSpectre1
String InterpolatedSpectre2
Variable PointsNumbers

Make/O/N=(PointsNumbers) $InterpolatedSpectre1
Make/O/N=(PointsNumbers) $InterpolatedSpectre2
Make/O/N=(PointsNumbers) wOutput
Wave SpectreData1= $InterpolatedSpectre1
Wave SpectreData2= $InterpolatedSpectre2

WaveStats/Q Temp1
Variable min1 = V_min
Variable max1 = V_max
WaveStats/Q Temp2
Variable min2 = V_min
Variable max2 = V_max

Variable minfinal = max(min1, min2)
Variable maxfinal = min(max1, max2)

//Variable minfinal = min(min1, min2)
//Variable maxfinal = max(max1, max2)

SetScale/I x minfinal, maxfinal, SpectreData1
SetScale/I x minfinal, maxfinal, SpectreData2
SetScale/I x minfinal, maxfinal, wOutput

SpectreData1 = interp(x, Temp1, spectre1)
SpectreData2 = interp(x, Temp2, spectre2)

wOutput[] = SpectreData1[p] - SpectreData2[p]
End


Interp.png (91.11 KB)