smooth_finite_difference

Apply smoothing method before finite difference.

pynumdiff.smooth_finite_difference.kerneldiff(x, dt, kernel='friedrichs', window_size=5, num_iterations=1, axis=0)

Differentiate by applying a smoothing kernel to the signal, then performing 2nd-order finite difference. meandiff, mediandiff, gaussiandiff, and friedrichsdiff call this function.

Parameters:
  • x (np.array[float]) – data to differentiate. May be multidimensional; see axis.

  • dt (float) – step size

  • kernel (str) – prefilter data, {'mean', 'median', 'gaussian', 'friedrichs'}

  • window_size (int) – filtering kernel size

  • num_iterations (int) – how many times to apply mean smoothing

  • 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.smooth_finite_difference.butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5, num_iterations=1, axis=0)

Perform butterworth smoothing on x with scipy.signal.filtfilt followed by second order finite difference

Parameters:
  • x (np.array[float]) – data to differentiate. May be multidimensional; see axis.

  • dt (float) – step size

  • params (list[int]) – (deprecated, prefer filter_order, cutoff_freq, and num_iterations)

  • options (dict) – (deprecated, prefer num_iterations) an empty dictionary or {‘iterate’: (bool)}

  • filter_order (int) – order of the filter

  • cutoff_freq (float) – cutoff frequency \(\in [0, 1]\). For a discrete vector, the value is normalized to the range 0-1, where 1 is the Nyquist frequency.

  • num_iterations (int) – how many times to apply smoothing

  • 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.smooth_finite_difference.meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1)

Perform mean smoothing by convolving mean kernel with x followed by second order finite difference

Deprecated, prefer kerneldiff with kernel 'mean' instead.

Parameters:
  • x (np.array[float]) – data to differentiate

  • dt (float) – step size

  • params (list[int]) – (deprecated, prefer window_size and num_iterations) [window_size] or, if 'iterate' in options, [window_size, num_iterations]

  • options (dict) – (deprecated, prefer num_iterations) an empty dictionary or {‘iterate’: (bool)}

  • window_size (int) – filter window size

  • num_iterations (int) – how many times to apply mean smoothing

Returns:

  • x_hat (np.array) – estimated (smoothed) x

  • dxdt_hat (np.array) – estimated derivative of x

pynumdiff.smooth_finite_difference.mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1)

Perform median smoothing using scipy.signal.medfilt followed by second order finite difference

Deprecated, prefer kerneldiff with kernel 'median' instead.

Parameters:
  • x (np.array[float]) – data to differentiate

  • dt (float) – step size

  • params (list[int]) – (deprecated, prefer window_size and num_iterations)

  • options (dict) – (deprecated, prefer num_iterations) an empty dictionary or {‘iterate’: (bool)}

  • window_size (int) – filter window size

  • num_iterations (int) – how many times to apply median smoothing

Returns:

  • x_hat (np.array) – estimated (smoothed) x

  • dxdt_hat (np.array) – estimated derivative of x

pynumdiff.smooth_finite_difference.gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1)

Perform gaussian smoothing by convolving gaussian kernel with x followed by second order finite difference

Deprecated, prefer kerneldiff with kernel 'gaussian' instead.

Parameters:
  • x (np.array[float]) – data to differentiate

  • dt (float) – step size

  • params (list[int]) – (deprecated, prefer window_size and num_iterations) [window_size] or, if 'iterate' in options, [window_size, num_iterations]

  • options (dict) – (deprecated, prefer num_iterations) an empty dictionary or {‘iterate’: (bool)}

  • window_size (int) – filter window size

  • num_iterations (int) – how many times to apply gaussian smoothing

Returns:

  • x_hat (np.array) – estimated (smoothed) x

  • dxdt_hat (np.array) – estimated derivative of x

pynumdiff.smooth_finite_difference.friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations=1)

Perform friedrichs smoothing by convolving friedrichs kernel with x followed by second order finite difference

Deprecated, prefer kerneldiff with kernel 'friedrichs' instead.

Parameters:
  • x (np.array[float]) – data to differentiate

  • dt (float) – step size

  • params (list[int]) – (deprecated, prefer window_size and num_iterations) [window_size] or, if 'iterate' in options, [window_size, num_iterations]

  • options (dict) – (deprecated, prefer num_iterations) an empty dictionary or {‘iterate’: (bool)}

  • window_size (int) – filter window size

  • num_iterations (int) – how many times to apply smoothing

Returns:

  • x_hat (np.array) – estimated (smoothed) x

  • dxdt_hat (np.array) – estimated derivative of x