Last active
May 15, 2024 02:12
-
-
Save lnacquaroli/e251ab8309da23f328f8bd350dc246c4 to your computer and use it in GitHub Desktop.
Baseline correction on data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Asymmetric Least Squares Smoothing by P. Eilers and H. Boelens in 2005 | |
For a more options and detailed implementation, see https://github.com/charlesll/Spectra.jl/blob/master/src/baseline.jl | |
Requires using LinearAlgebra and SparseArrays | |
""" | |
function baselineCorrection(y, lam, p, ninter=10) | |
L = length(y) | |
eyeL = Matrix(1.0I, L, L) | |
D = sparse(diff(diff(eyeL, dims=2), dims=2)) | |
w = ones(L) | |
q = 0.0 | |
for _ in 1 : ninter | |
W = spdiagm(0 => w) | |
q = \(W + lam * D * D', w.*y) | |
w = p * (y .> q) + (1 - p) * (y .< q) | |
end | |
return q | |
end |
Ups, thanks for catching that up. Corrected!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your Julia version of ALS smoothing. I notice that the
niter
should agree with the parameterninter
in your code.