Numerical Tools (pysdic.numeric)#
The submodule pysdic.numeric provides low-level numerical tools on 1D signals sampled at given abscissas (e.g. the
times of the frames): finite differences and polynomial fitting. They are not exported in the pysdic namespace:
from pysdic.numeric import assemble_finite_difference_matrix, fit_polynomial
They are used, for example, by pysdic.SDICTemporalRegularizationTerm (finite difference matrix on the actual
times of the frames).
Finite differences#
The finite difference coefficients \(c_k\) approximate the derivative of order \(n\) of a function at a point \(t\) from its values at the points \(t_k\) of a stencil:
The coefficients are computed for any (non-uniform) stencil with the algorithm of Fornberg, and the stencils can be centered, forward or backward.
Coefficients#
compute_finite_difference_coefficients: Coefficients of a derivative of any order on any stencil (Fornberg).
compute_forward_finite_difference_coefficients: Coefficients on a forward stencil.
compute_backward_finite_difference_coefficients: Coefficients on a backward stencil.
compute_central_finite_difference_coefficients: Coefficients on a centered stencil.
Matrices#
The matrix \(D\) of a finite difference over a whole signal, \(f^{(n)} \approx D f\) (one row per evaluated point), for example to build a linear regularization term.
assemble_finite_difference_matrix: Matrix of a derivative on non-uniform abscissas, with centered stencils inside and one-sided stencils at the boundaries.
assemble_forward_finite_difference_matrix: Matrix with forward stencils.
assemble_backward_finite_difference_matrix: Matrix with backward stencils.
assemble_central_finite_difference_matrix: Matrix with centered stencils.
Application to a signal#
apply_forward_finite_difference: Derivative of a signal with forward stencils.
apply_backward_finite_difference: Derivative of a signal with backward stencils.
apply_central_finite_difference: Derivative of a signal with centered stencils.
Polynomial fitting#
Fit a polynomial to sampled values in the least squares sense and evaluate it, e.g. to extrapolate a displacement from the previous frames.
fit_polynomial: Coefficients of the least squares polynomial of a given degree through sampled values.
evaluate_polynomial: Values of a polynomial at given abscissas.
polynomial_predict: Fit a polynomial and evaluate it at new abscissas in one call.