Automation of Baseline Subtraction and Smoothing for Multiple Waves

Hi there,

I'm working on a procedure that will allow me to do a baseline subtraction followed by a smoothing of the baseline corrected waves. I have completed the first part by using a "wrapper function" but am unsure how to appropriately add the Smooth portion to it.

Here is the procedure I have so far:

#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function BaselineSubtraction(w1,leftmark, rightmark,rangetype)

    WAVE w1
    VARIABLE leftmark, rightmark, rangetype
   
    String outputName= NameOfWave(w1) +"_baselined"
   
    if (rangetype<1470 || rangetype>1472)
        return -1
    endif
   
    Duplicate/o w1 $outputName
    Wave output = $outputName
   
    if (rangetype==0)
        WaveStats/Q output
    endif
   
    if (rangetype==1470)
        WaveStats/Q/R=[leftmark,rightmark] output
    endif
   
    if (rangetype==1472)
        WaveStats/Q/R=(leftmark,rightmark) output
    endif
   
    output= output - V_min
    print V_min
End

FUNCTION SubtractAll(wname, fnum, leftmark, rightmark, rangetype)

    STRING wname
    VARIABLE fnum, leftmark, rightmark, rangetype
    VARIABLE i
    STRING w1
   
    for(i=1; i<=fnum; i=i+1)
        w1 = wname+num2str(i)
       
        BaselineSubtraction($(w1),leftmark, rightmark,rangetype)
       
    endfor

End


Let me know if you have any ideas/suggestions.

Thanks!
You just need to add the smooth step in the line after the bg subtraction.

    //...
    output -= V_min  // This is better than output = output - V_min
    Smooth 1, output  // I don't know what smoothing you want to do
    print V_min
End


If you want to keep the "bg subtracted but not smoothed" wave you need to duplicate output and then smooth that wave, otherwise this will work.
As an aside, I would suggest that you look at the range of wave names that you will be dealing with. Igor has a limit of 31 characters for names and your "_baseline" suffix is a bit lengthy. Just to avoid potential problems, I would shorten it to "_BL" or something along the same line.
    String outputName= NameOfWave(w1)[0,27] +"_BL"

--Jim Prouty
Software Engineer, WaveMetrics, Inc.