basis_fit
Methods based on fitting basis functions to data
- pynumdiff.basis_fit.rbfdiff(x, dt_or_t, sigma=1, lmbd=0.01, axis=0)
Find smoothed function and derivative estimates by fitting noisy data with radial-basis-functions. Naively, fill a matrix with basis function samples and solve a linear inverse problem against the data, but truncate tiny values to make columns sparse. Each basis function “hill” is topped with a “tower” of height
lmbdto reach noisy data samples, and the final smoothed reconstruction is found by razing these and only keeping the hills.- Parameters:
x (np.array[float]) – data to differentiate. May be multidimensional; see
axis.dt_or_t (float or array[float]) – This function supports variable step size. This parameter is either the constant \(\Delta t\) if given as a single float, or data locations if given as an array of same length as
x.sigma (float) – controls width of radial basis functions
lmbd (float) – controls smoothness
axis (int) – data dimension along which differentiation is performed
- Returns:
x_hat (np.array) – estimated (smoothed) x
dxdt_hat (np.array) – estimated derivative of x
- pynumdiff.basis_fit.spectraldiff(x, dt, params=None, options=None, high_freq_cutoff=None, even_extension=True, pad_to_zero_dxdt=True, axis=0)
Take a derivative in the Fourier domain, with high frequency attentuation.
- Parameters:
x (np.array[float]) – data to differentiate. May be multidimensional; see
axis.dt (float) – step size
params (list[float] or float) – (deprecated, prefer
high_freq_cutoff)options (dict) – (deprecated, prefer
even_extensionandpad_to_zero_dxdt) a dictionary consisting of {‘even_extension’: (bool), ‘pad_to_zero_dxdt’: (bool)}high_freq_cutoff (float) – The high frequency cutoff as a multiple of the Nyquist frequency: Should be between 0 and 1. Frequencies below this threshold will be kept, and above will be zeroed.
even_extension (bool) – if True, extend the data with an even extension so signal starts and ends at the same value.
pad_to_zero_dxdt (bool) – if True, extend the data with extra regions that smoothly force the derivative to zero before taking FFT.
- Returns:
x_hat (np.array) – estimated (smoothed) x
dxdt_hat (np.array) – estimated derivative of x