Similar to the JOT method suggested by @Royi, the BEADS algorithm decomposes a signal in three components:
- a trend,
- a sparse signal,
- a residual (which can be used as quality control).
I did a quick test on your first signal. BEADS is not (yet) good at the beginning and end, but it is quite fast: 0.25 seconds for the first signal. It scales almost linearly with signal size. Its parameters allow to control the smoothness of the trend. Here are the results. Parameters follow.
data1 = [signals_samples{1}];
% Filter parameters
fc = 0.0035; % fc : cut-off frequency (cycles/sample)
d = 1; % d : filter order parameter (d = 1 or 2)
% Positivity bias (peaks are positive)
r = 1; % r : asymmetry parameter
% Regularization parameters
% amp = 0.8;
amp = 0.1;
lam0 = 1*amp;
lam1 = 5*amp;
lam2 = 2*amp;
[data1Filt, dataBaseline, cost] = beads(data1, d, fc, r, lam0, lam1, lam2);
detrend
mathworks.com/help/matlab/ref/detrend.html. $\endgroup$