Sum Scaled Waves of Different Lengths
Posted May 7th, 2008 by jjweimer
This function sums scaled waves of different lengths.
dwave = destination wave
wlist = string list of waves to sum
Different lengths are handled by the Interpolate2 operation.
Example
Make three waves using the table edit. Assume they are named wave0, wave1, and wave2 with 6, 3, and 9 points respectively. Add data to the waves. Execute the following three commands on the command line.
SetScale/P x 1,0.5,"", wave2 SetScale/P x 0,2,"", wave1 SumWavesInX(wave2,"wave0;wave1;")
Function
Function SumWavesInX(dwave, wlist) wave dwave string wlist variable ic, np, nt, sn string theOne nt = ItemsInList(wlist) duplicate/O dwave tmp_dwave, tmp_swave tmp_dwave=0 tmp_swave=0 np = numpnts(dwave) for (ic=0;ic<nt;ic+=1) theOne = StringFromList(ic,wlist) wave swave = $theOne sn = numpnts(swave) if (sn!=np) interpolate2/I=3/Y=tmp_swave swave else tmp_swave = swave endif tmp_dwave+=tmp_swave endfor dwave = tmp_dwave killwaves/Z tmp_dwave, tmp_swave return 0 end
