Baseline Fitting

Baselines is a baseline fitting utility for spectroscopic data.

New for Version 4

  • Baselines now includes all of the baseline types from the ArcHull and BaselineSpline projects.
  • A lot of the code has been rewritten and the user interface updated.
  • Some code bottlenecks have been fixed. The result is that the baseline preview is updated more smoothly in response to changing settings, dragging nodes or moving cursors.
  • Preferences are now saved in a package preferences file and are easily editable.
  • Subrange fitting provides an easy way to adjust the output of the automatic baseline algorithms, and can used to treat different regions of interest separately. See usage notes for more details.
  • New "marquee buttons" for quick input, and SetVariable controls for precise adjustment of fitting range.
  • Improved algorithm for guessing node positions for spline type baselines. Hold down the shift key when clicking the reset button to snap-to-trace.
  • Node editing mode can be toggled using a new graph window button. The button is moveable in Igor 8+ and transparent in Igor 9.
  • A user-defined function can be used for both masked and automatic iterative fitting.
  • New manual baselines use cursors for input.
  • Wave assignments for large waves are multithreaded.
  • A help file is included in the package and can be opened via a control panel button.

How to use the Baseline Fitting package

To get started, plot all of the waves that need baseline correction in a graph window. The waves may be vertically offset as you please. Select 'Baselines' from the analysis menu to attach the 'Baseline Controls' panel to the top graph. Traces in the graph will be recolored (unless the trace recoloring option is turned off in the settings panel) so that the selected trace, together with a preview of the baseline and baseline-subtracted waves, are the only non-grey traces. Traces are reset to their original colors when the 'Baseline Controls' panel is closed. Select a spectrum and baseline type from the popup menus in the control panel. The four tabs select between four 'families' of baseline algorithms: masked function fitting, manual function fitting, automatic baselines that process the input data to estimate a baseline, and spline baselines that are interpolated between node positions selected by the user. Baselines works with both waveform and x-y traces, but not with 2D waves. Clicking on the cog icon opens a control panel where you can adjust the settings for baseline fitting. Close the main 'Baseline Controls' panel to clean up after fitting. Note that baselines uses cursors C through J, so don't try to use them for other purposes in the baseline fitting graph window.

Baseline Functions

Most of Igor Pro's built-in curve fitting functions can be selected as a baseline fit function. The fit coefficients are stored in the wave W_Coef, in case you need them for further processing. Some additional functions are selectable in the masked- and automatic-fitting tabs. These are described in the following sections.

Some baseline functions have a 'peak' option. When the 'Peak' checkbox is checked, the first coefficient of the fit function is set to the baseline reference value, meaning that these are peak functions with no vertical offset. The fit coefficents are described in the help for built-in curve fitting functions.

A user-defined fit function can be added by editing the last three functions in the procedure file. Your function will be available in the baseline type popups in the masked-region and auto tabs.

Masked Fitting

Use the graph marquee tool (click and drag) to select a region of the spectrum, then use the + and - buttons (buttons adjacent to the marquee or the ones in the control panel) to add or remove a fitting region. The baseline is determined by a leastsquares fit of the chosen function to data that fall within the selected regions.

The tangent baseline (mask tab) will attempt to find a horizontal tangent if one fit region is selected, and a common tangent if two regions are selected. Each region is fitted with a cubic function, so the fit will be successful only if the selected regions can each be fit nicely with a cubic function, and if a horizontal or common tangent can be found with contact points within the selected regions. The coefficents for the tangent line are stored in W_Coef and are written to the wavenotes of output waves, together with the coordinates of the tangent points.

Manual Fitting

The manual baselines allow you to create a baseline by positioning the cursors. The constant, line, and poly functions create a baseline that passes though all of the cursor positions. For Gaussian and Lorentzian functions, one cursor sets the baseline y-offset, the other sets the peak position and height, and the horizontal distance separating the cursors sets the peak width parameter. For sinusoidal baselines, the amplitude is set by the vertical offset of the two cursors and the number of complete cycles that should appear between the cursors can be selected in the popup menu.

Auto Fitting

The arc hull type baseline adds to the spectrum a circular arc with adjustable depth (ie., the spectrum is bent), and the lower portion of a convex hull is calculated for the resultant spectrum. The baseline consists of the sum of the arc and the convex hull. Adjust arc depth using the SetVariable control to find an optimal value. Arc depth increments by 10% of its value and has y-axis units. Setting arc depth to zero creates a convex hull (a.k.a. 'rubber band') type baseline. For X-Y data, the X wave needs to be monatonic for arc hull calculation. Note that baseline segments can be convex or concave depending on the sign of the depth variable. The arc hull algorithm is not iterative.

Spline: baseline is a cubic spline using the convex hull as nodes. When arc depth is non-zero the nodes are more like a subset of alphashape vertices. Adjust Smooth and Depth parameters to produce an optimal number of nodes.

Iterative: the function selected in the Fit Func popup is fitted iteratively. Any fit point with a negative residual (positive if the negative peaks checkbox is selected) is replaced by the corresponding point from the input data after each iteration, thus eliminating points with a positive residual, so ultimately eliminating peaks from the fit. The fit output is used as the input for the next iteration. The algorithm is similar to that described by Lieber and Mahadevan-Jansen (2003) Applied Spectroscopy 57: 1363-1367. For the first eight iterations only points with a residual above 50% of the greatest residual are eliminated.

Pre-smoothing: the baseline is calculated for a smoothed copy of the spectrum, then subtracted from the original. With the right choice of smoothing factor, the baseline will pass through spectroscopic noise rather than underlying the noise. Note that the baseline-subtracted output is not smoothed with respect to the original data, the smoothing is used only for calculating the baseline.

Negative Peaks: subtract the top part of the convex hull, or fit to the top of the spectrum. Useful for dealing with downward facing peaks, or for when you have a reverse-scaled vertical axis. The negative peaks setting is also adjustable in the settings panel, and affects the guesses for y positions of spline nodes.

Use Convex Hull at Start: In the first iteration, the baseline function is fit to the lower (upper for negative peaks) part of a convex hull of the input data. For some spectra this reduces the influence of peaks on the iterative baseline output.

Spline Baselines

When 'edit mode' is selected the nodes can be moved. The spline updates as the nodes are repositioned. In edit mode you can add a new node at any position on the graph by positioning the mouse cursor and clicking while holding down the control key. Nodes may be deleted by clicking them with the option key held down. Clicking the (moveable) button in the graph window will toggle between node editing mode and 'normal' mode where you can interact with the graph as usual. Cubic and smoothing splines are calculated using Igor's Interpolate2 operation. Cubic splines are calculated with 'natural' ends. When a spline type baseline is subtracted the node positions are saved in a 2D wave and can be later reloaded. Selecting a trace will reposition the nodes by adjusting their vertical positions. Clicking the node reset button resets horizontal and vertical node positions. The default algorithm guesses node positions by first fitting an auto-type baseline. Clicking the reset button with the shift key held down will position the nodes on the trace rather than guessing their positions. The horizontal positions are not changed unless there are insufficient nodes within the x-range of the new trace.

Subrange Fitting

Enable subrange fitting by clicking the checkbox and select a subrange by adjusting the values in the setvariable controls or by dragging the vertical cursors. When a baseline is subtracted, points within the selected range of any existing output wave are overwritten. For baselines in the mask, manual and spline families, this setting affects only the baseline subtraction process: the baseline calculation includes masked regions, cursors or nodes outside of the selected region. For algorithmic baselines (Auto tab), the data within the selected region are used to calculate the baseline, so adjusting the output range also changes the baseline. Spline nodes are not saved for subranges.

If a baseline has already been subtracted from the selected trace, points outside of the subrange will be filled with the existing values in both the baseline and baseline-subtracted output preview.

Subtracting Baselines

The 'Subtract' button will make copies of baseline and baseline-subtracted waves. The output waves can be saved in either the current data folder, or in the same location as the input data wave. The names of the output waves are formed from the input wavename, together with a suffix as defined in the settings panel. Use the subrange setting to subtract baselines in a piecemeal fashion.

All-at-once fitting cycles through all of the traces in the plot, fitting a baseline using the current settings. Baselines and baseline-subtracted waves are created for each trace. All-at-once spline fitting guesses a y-position for the nodes for each trace.

Note that output waves with the baseline and subtracted-wave suffixes defined in the settings cannot be chosen as data waves for baseline fitting. If you want to subtract a sequence of baselines from one wave, edit the suffix in the settings panel after each baseline subtraction, or rename the output baseline-subtracted waves between fits.

Baseline fit parameters are saved in the wavenotes of output waves. When a baseline subrange is subtracted, the baseline parameters for the subrange are appended to the wavenotes of the output waves.

Installing this package

  • Consider using the IgorExchange Installer to install Baselines.ipf in the User Procedures folder.
  • The Procedure Loader can be used to load or unload files stored in the User Procedures folder.

Project Details

Current Project Release

Baselines IGOR.7.00.x-4.62

Release File: Baselines462.zip
Version: IGOR.7.00.x-4.62
Version Date: Fri, 04/29/2022 - 12:15 am
Version Major: 4
Version Patch Level: 62
OS Compatibility: Windows Mac-Intel
Release Notes:

Adds optional initialization parameters for starting baselines from an external function, e.g. baselines#initialise(tab=2,type=15,trace="foo").

View All Releases

If anyone is watching this space and would like to test a pre-release version of this project, let me know. It's a major rewrite, and there will likely be bugs. Once the worst of the bugs are shaken out I will release as version 4.

This is a pre-release beta for version 4.

Edit: version 4 is released.

This is a terrific contribution, Tony!

I just recommended it to a customer needing bulk baseline removal using the mask feature.

Thanks, Jim.

I'm glad to hear that others are finding it useful. I'm always curious to find out what kind of spectroscopic data other people use this project for. My colleagues and I use it mainly for baseline-correcting infrared and Raman spectra.

Hi Tony,

Absolutely fabulous and really timely since I am reviewing some fitting algorithms for XRD data.

 

Question: If I wanted to start with a simple hull arc baseline using the default settings, what would the procedure be to be able to call it from a function?  I would like to set up on some representative samples and then batch process a large number of spectra.

 

Andy

Hi Andy,

I'm glad that you like it!

All of the code is based around the GUI, so if you want to call a function without running the GUI I don't think that will work. Almost all functions take a structure as a parameter, so you'd have to do some tinkering if you want to call functions from your own code.

Or perhaps you want to invoke the GUI from your own function? That is as simple as building a graph and calling baselines#initialise(). You could simulate some GUI actions by loading the structure for a control and passing it to the control procedure, or there may be some other way to do it. Some more details about what you have in mind would be helpful.

Dear Tony,

We tried Baseline Fitting IGOR.6.30.x-3.13 on our Igor 6.37, but it failed to compile (see attached screenshot). Is there a version compatible with Igor 6.37? Thank you very much.

error.png

Version 3.13 was missing a line of code at the top of the file:

#include <Readback ModifyStr>

The omission was fixed in the next release, but I see that the next release ended support for Igor 6.x. Adding the #include line to baselines,ipf should fix that particular problem. Sorry for the inconvenience.

If you find that the baseline fitting user interface works well for your needs, I recommend an upgrade to Igor 9. There were some significant improvements for Baselines version 4.x. You can make a comparison by installing the demo version of the current Igor release and the most recent version of the Baseline Fitting package.

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More