Igor Here is a crude function that should do the job, taking into account the fact that your wave scaling is negative. function env4(wave1,wave2,wave3,wave4,minX,maxX,numPoints) Wave wave1,wave2,wave3,wave4 Variable minX,maxX,numPoints Make/O/N=(numPoints) envWave Make/O/FREE/N=(4)/WAVE wp={wave1,wave2,wave3,wave4} Make/O/FREE/N=(4) startV,endV SetScale/I x (minX),(maxX),"", envWave Variable i,j,xx,dx,maxValue for(j=0;j<4;j++) startV[j]=DimOffset(wp[j],0) endV[j]=DimOffset(wp[j],0)+DimDelta(wp[j],0)*(DimSize(wp[j],0)-1) endfor xx=minX dx=DimDelta(envWave,0) for(i=0;i<numPoints;i+=1) maxValue=-1 for(j=0;j<4;j+=1) wave w=wp[j] if(xx>=min(startV[j],endV[j]) && xx<max(startV[j],endV[j])) if(w(xx)>maxValue) maxValue=w(xx) endif endif endfor envWave[i]=maxValue xx+=dx endfor End You can invoke this on the command line using: env4('Peak 00','Peak 10','Peak 20','Peak 30',8,-1,500) Edit: If you are actually seeking the sum of all the waves then the code is even simpler: function sum4Waves(wave1,wave2,wave3,wave4,minX,maxX,numPoints) Wave wave1,wave2,wave3,wave4 Variable minX,maxX,numPoints Make/O/N=(numPoints) sumWave=0 Make/O/FREE/N=(4)/WAVE wp={wave1,wave2,wave3,wave4} Make/O/FREE/N=(4) startV,endV SetScale/I x (minX),(maxX),"", sumWave Variable i,j,xx,dx,maxValue for(j=0;j<4;j++) startV[j]=DimOffset(wp[j],0) endV[j]=DimOffset(wp[j],0)+DimDelta(wp[j],0)*(DimSize(wp[j],0)-1) endfor xx=minX dx=DimDelta(sumWave,0) for(i=0;i<numPoints;i+=1) maxValue=0 for(j=0;j<4;j+=1) wave w=wp[j] if(xx>=min(startV[j],endV[j]) && xx<max(startV[j],endV[j])) maxValue+=w(xx) endif endfor sumWave[i]=maxValue xx+=dx endfor End I hope this helps, A.G. Log in or register to post comments December 15, 2021 at 11:49 am - Permalink
alcarar Perfect!, Thank you Log in or register to post comments December 16, 2021 at 12:04 am - Permalink
Here is a crude function that should do the job, taking into account the fact that your wave scaling is negative.
You can invoke this on the command line using:
env4('Peak 00','Peak 10','Peak 20','Peak 30',8,-1,500)
Edit:
If you are actually seeking the sum of all the waves then the code is even simpler:
I hope this helps,
A.G.
December 15, 2021 at 11:49 am - Permalink
Perfect!, Thank you
December 16, 2021 at 12:04 am - Permalink