ModifiedSincFilter#

class chemotools.smooth.ModifiedSincFilter(window_length: int = 21, n: int = 6, alpha: float = 4.0, use_corrections: bool = True, mode: Literal['mirror', 'constant', 'nearest', 'wrap', 'interp'] = 'interp', axis: int = 1, window_size='deprecated')[ソース]

ベースクラス: _BaseFIRFilter

Modified Sinc smoothing (MS) for denoising while preserving peak positions based on the paper "Why and How Savitzky–Golay Filters Should Be Replaced."

The Modified Sinc smoother is a linear-phase FIR filter: the signal is convolved with a fixed, symmetric kernel. The kernel is built from:

  1. a sinc core with argument ((n + 4) / 2) * pi * x (Eq. 3, p. 187),

  2. a special Gaussian-like window w(x) whose value and slope vanish at

    the window ends (Eq. 4, p. 187), and

  3. small optional correction terms that flatten the passband so low

    frequencies are almost unattenuated (Eqs. 7–8 and Table 1, pp. 187–188).

パラメータ:
  • window_length (int, default=21) -- Odd number of taps (2*m + 1). Larger values give stronger smoothing.

  • n (int, default=6) -- Even integer >= 2. Controls how many inner zeros the sinc has within the window. The paper discusses n = 2, 4, 6, 8, 10 (Fig. 2).

  • alpha (float, default=4.0) -- Positive window width parameter. Larger alpha reduces side lobes more aggressively (steeper roll-off).

  • use_corrections (bool, default=True) -- If True and n in {6, 8, 10} and the window is large enough, add the small passband-flattening terms from Eqs. 7–8 (coefficients from Table 1).

  • mode ({"mirror", "constant", "nearest", "wrap", "interp"}, default="interp") -- Boundary strategy, passed to the base FIR class. "interp" performs linear extrapolation (recommended in the paper).

  • axis (int, default=1) -- Axis along which to smooth for 2D inputs (rows x features). Use 1 to smooth within each row.

  • window_size (int, optional) -- Deprecated alias for window_length.

fit(X, y=None)[ソース]

Inherited from the base class. Validates input and builds the kernel.

transform(X, y=None)[ソース]

Inherited from the base class. Pads, convolves, and returns the smoothed data.

参照

[1] Schmid, M.; Rath, D.; Diebold, U. "Why and How Savitzky–Golay Filters Should Be Replaced." ACS measurement science Au 2022, 2 (2), 185-196.

サンプル

>>> from chemotools.datasets import load_fermentation_train
>>> from chemotools.smooth import ModifiedSincFilter
>>> # Load sample data
>>> X, _ = load_fermentation_train()
>>> # Initialize ModifiedSincFilter
>>> msf = ModifiedSincFilter()
ModifiedSincFilter()
>>> # Fit and transform the data
>>> X_smoothed = msf.fit_transform(X)
fit(X: ndarray, y: ndarray | None = None) ModifiedSincFilter[ソース]

Fit the Modified Sinc Filter to the data.

パラメータ:
  • X (np.ndarray of shape (n_samples, n_features)) -- The input data to fit the transformer.

  • y (Ignored) -- Not used, present for API consistency by convention.

戻り値:

self -- The fitted transformer.

戻り値の型:

ModifiedSincFilter

transform(X: ndarray, y: ndarray | None = None) ndarray[ソース]

Transform the input data by applying the Modified Sinc Filter.

パラメータ:
  • X (np.ndarray of shape (n_samples, n_features)) -- The input data to transform.

  • y (None) -- Ignored to align with API.

戻り値:

X_transformed -- The transformed data.

戻り値の型:

np.ndarray of shape (n_samples, n_features)