Skip to contents

Applies a Savitzky-Golay filter to a continuous glucose monitoring (CGM) trace prior to baseline correction and peak detection. This mirrors the smoothing step of the first post-wake glucose peak detection pipeline described in Pugliane et al. (2026, preprint).

Usage

sg_smooth(glucose, window = 5, order = 2)

Arguments

glucose

Numeric vector of interstitial glucose values (mg/dL), assumed to be evenly spaced in time (e.g. 15-min CGM sampling).

window

Integer, window length in points. Default 5, matching the manuscript's pipeline.

order

Integer, polynomial order. Default 2.

Value

Numeric vector of smoothed glucose values, same length as glucose.

Details

NOTE (parity flag): this is currently a clean-room reimplementation and has not yet been validated against the Python reference (scipy.signal.savgol_filter) used in the manuscript pipeline. Edge handling (boundary mode) in particular needs to be checked for parity before this function is treated as validated. See package NEWS.md / inst/COPYRIGHTS once that comparison has been done.