Smoothing#
Smoothing aims to reduce high-frequency noise in 1D continua. spm1d provides only rudimentary Gaussian smoothing through spm1d.util.smooth:
import numpy as np
import spm1d
np.random.seed( 0 )
y0 = np.random.randn( 5, 101 ) # five random continua
y = spm1d.util.smooth( y0, fwhm=10 ) # Gaussian kernel with FWHM = 10 domain points
Refer to third-party packages like scipy.signal for more comprehensive smoothing options.
Note that smoothing is different from smoothness estimation.
Boundaries#
spm1d.util.smooth regards each observation as circular. Values near one end are therefore mixed with values near the other end. This is appropriate for circular data such as gait cycles. For other data scipy.ndimage.gaussian_filter1d can instead extend each continuum’s end values beyond the boundaries with mode='nearest'. The figure below depicts a step function smoothed using the two methods.
from scipy.ndimage import gaussian_filter1d
sd = 10 / np.sqrt( 8 * np.log( 2 ) ) # kernel standard deviation for FWHM = 10
y = gaussian_filter1d( y0, sd, mode='nearest' )