The problem of estimating underlying trends in time series data arises in a variety of disciplines. The ℓ1 trend filtering method produces trend estimates x that are piecewise linear from the time series y.
The ℓ1 trend estimation problem can be formulated as
$$ minimize \; (1/2) ||y-x||^2_2+λ||Dx||_1, $$
with variable $x$, problem data $y$ and parameter $λ$, with $λ\geq0$
where $D$ is the second difference matrix with rows
$$ [0 \quad \dots \quad 0 \quad -1 \quad 2 \quad -1 \quad 0 \quad \dots \quad 0] $$https://www.cvxpy.org/examples/applications/l1_trend_filter.html