interp1#
Piecewise interpolation with various methods (linear, nearest, next, previous, spline).
-
template<typename OpX, typename OpV, typename OpXQ>
auto matx::interp1(const OpX &x, const OpV &v, const OpXQ &xq, InterpMethod method = InterpMethod::LINEAR)# Interpolation operator with specified method
- Template Parameters:
OpX – Type of sample points vector
OpV – Type of sample values vector
OpXQ – Type of query points
- Parameters:
x – Sample points (must be sorted in ascending order)
v – Sample values (must be the same size as x)
xq – Query points where to interpolate
method – Interpolation method (LINEAR, NEAREST, NEXT, PREV, SPLINE)
- Returns:
Operator that interpolates values at query points
Interpolation Methods#
-
enum class matx::InterpMethod#
Interpolation method enumeration.
Specifies the algorithm to use when performing interpolation between sample points.
Values:
-
enumerator LINEAR#
Linear interpolation between adjacent points.
-
enumerator NEAREST#
Uses the value at the nearest sample point.
-
enumerator NEXT#
Uses the value at the next sample point.
-
enumerator PREV#
Uses the value at the previous sample point.
-
enumerator SPLINE#
Cubic spline interpolation, using not-a-knot boundary conditions.
-
enumerator LINEAR#
Examples#
Linear Interpolation (default):
auto x = make_tensor<TestType>({5});
x.SetVals({0.0, 1.0, 3.0, 3.5, 4.0});
auto v = make_tensor<TestType>({5});
v.SetVals({0.0, 2.0, 1.0, 3.0, 4.0});
auto xq = make_tensor<TestType>({6});
xq.SetVals({-1.0, 0.0, 0.25, 1.0, 1.5, 5.0});
auto out_linear = make_tensor<TestType>({xq.Size(0)});
(out_linear = interp1(x, v, xq, InterpMethod::LINEAR)).run(exec);
Nearest Neighbor Interpolation:
auto out_nearest = make_tensor<TestType>({xq.Size(0)});
(out_nearest = interp1(x, v, xq, InterpMethod::NEAREST)).run(exec);