Baseline Fitting

Hello,

I am writing an integration macro that will mimic the integration function of the GC used in our lab. I am also finished but all I need now is to write the code for a better baseline. Currently, I have it set to finding the minimal value between all of the peaks and just using that y minimal value as the straight line baseline. However, I wish to be more precise by making a baseline that will form straight lines between each local minimum between each peak. I have already written the code to find the local minimums between each peak. Now, I just wish to curve fit lines between each local minimum so that this can be used as a baseline (the baseline is essentially going to be a piecewise function where each section is simply a straight line from each local minimum). My idea right now currently is to break up the wave into sections based on the local minimums using the Duplicate/R=[startP, endP] function in a loop, then curve fitting each section using a line curvefit based on the 2 end points, and finally combining each linear section into the full "piecewise" baseline using the Concatenate function. I do not know how to write this code specifically so any help is greatly appreciated!
That algorithm reminds me a lot of the algorithm used in TN #020-B: Peak Areas.

See your Igor Pro Folder/Technical Notes/Igor Tech Notes/TN020-B Peak Areas folder.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
hernants wrote:
My idea right now currently is to break up the wave into sections based on the local minimums using the Duplicate/R=[startP, endP] function in a loop, then curve fitting each section using a line curvefit based on the 2 end points, and finally combining each linear section into the full "piecewise" baseline using the Concatenate function. I do not know how to write this code specifically so any help is greatly appreciated!


It sounds like you want a baseline matching the scaling of the original data set, but with linear segments between the peaks in the original data. If that is the case, then take a look at using interpolate2 with linear interpolation on the set of minimum values between peaks.
If I understand correctly and you have only two points, which form the start and end, from which you would like to generate the linear background in each section then you don't need a fit. Just calculate the linear section piecewise from the two points (x1,y1) and (x2,y2) using: y = (x-x1)*(y2-y1)/(x2-x1)+x1
for(...)
    Variable x1 = ..., y1= ....
    Variable x2 = ..., y2= ....
    my_background(x1,x2) = (x-x1)*(y2-y1)/(x2-x1)+x1
endfor