Skip to content
Advertisement

How to subtract baseline from spectrum with rising tail in python?

I have a spectrum that I want to subtract a baseline from. The spectrum data are:

JavaScript

I’ve taken only every 20th data point from the actual data file, but the general shape is preserved.

JavaScript

Original_spectrum

enter image description here

There is a clear tail in around the high x values. Assume the tail is an artifact and needs to be removed. I’ve tried solutions using the ALS algorithm by P. Eilers, a rubberband approach, and the peakutils package, but these end up subtracting the tail and creating a rise around the low x values or not creating a suitable baseline.

ALS algorithim, in this example I am using lam=1E6 and p=0.001; these were the best parameters I was able to manually find:

JavaScript

ALS_plot
enter image description here

Rubberband approach:

JavaScript

Rubber_plot
enter image description here

peakutils package:

JavaScript

Peakutils_plot
enter image description here

Are there any suggestions, aside from masking the low x value data, for constructing a baseline and subtracting the tail without creating a rise in the low x values?

Advertisement

Answer

I found a set of similar ALS algorithms here. One of these algorithms, asymmetrically reweighted penalized least squares smoothing (arpls), gives a slightly better fit than als.

JavaScript

ARPLS plot

enter image description here

Fortunately, this improvement becomes better when using the data from the entire spectrum:

enter image description here

Note the parameters for either algorithm were different. For now, I think the arpls algorithm is as close as I can get, at least for spectra that look like this. We’ll see how robust the algorithm can fit spectra with different shapes. Of course, I am always open to suggestions or improvements!

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement