OpenMS
Loading...
Searching...
No Matches
ModifiedSincSmoother Class Reference

Computes a modified sinc smoothing filter for profile data. More...

#include <OpenMS/PROCESSING/SMOOTHING/ModifiedSincSmoother.h>

Inheritance diagram for ModifiedSincSmoother:
[legend]
Collaboration diagram for ModifiedSincSmoother:
[legend]

Classes

struct  LinearRegression
 Helper class for weighted linear regression. More...
 

Public Member Functions

 ModifiedSincSmoother ()
 Default constructor with parameter registration.
 
 ModifiedSincSmoother (bool isMS1, int degree, int m)
 Constructor initializing the modified sinc smoother.
 
std::vector< double > smooth (const std::vector< double > &data)
 Smooth a vector of data values with boundary extrapolation.
 
std::vector< double > smoothExceptBoundaries (const std::vector< double > &data)
 Smooth data without boundary extension (interior points only).
 
void filter (MSSpectrum &spectrum)
 Apply modified sinc smoothing to an MSSpectrum.
 
void filter (MSChromatogram &chromatogram)
 Apply modified sinc smoothing to an MSChromatogram.
 
void filter (Mobilogram &mobilogram)
 Apply modified sinc smoothing to a Mobilogram.
 
void filterExperiment (PeakMap &map)
 Apply modified sinc smoothing to all spectra and chromatograms in an experiment.
 
- Public Member Functions inherited from ProgressLogger
 ProgressLogger ()
 Constructor.
 
virtual ~ProgressLogger ()
 Destructor.
 
 ProgressLogger (const ProgressLogger &other)
 Copy constructor.
 
ProgressLoggeroperator= (const ProgressLogger &other)
 Assignment Operator.
 
void setLogType (LogType type) const
 Sets the progress log that should be used. The default type is NONE!
 
LogType getLogType () const
 Returns the type of progress log being used.
 
void setLogger (ProgressLoggerImpl *logger)
 Sets the logger to be used for progress logging.
 
void startProgress (SignedSize begin, SignedSize end, const String &label) const
 Initializes the progress display.
 
void setProgress (SignedSize value) const
 Sets the current progress.
 
void endProgress (UInt64 bytes_processed=0) const
 
void nextProgress () const
 increment progress by 1 (according to range begin-end)
 
- Public Member Functions inherited from DefaultParamHandler
 DefaultParamHandler (const String &name)
 Constructor with name that is displayed in error messages.
 
 DefaultParamHandler (const DefaultParamHandler &rhs)
 Copy constructor.
 
virtual ~DefaultParamHandler ()
 Destructor.
 
DefaultParamHandleroperator= (const DefaultParamHandler &rhs)
 Assignment operator.
 
virtual bool operator== (const DefaultParamHandler &rhs) const
 Equality operator.
 
void setParameters (const Param &param)
 Sets the parameters.
 
const ParamgetParameters () const
 Non-mutable access to the parameters.
 
const ParamgetDefaults () const
 Non-mutable access to the default parameters.
 
const StringgetName () const
 Non-mutable access to the name.
 
void setName (const String &name)
 Mutable access to the name.
 
const std::vector< String > & getSubsections () const
 Non-mutable access to the registered subsections.
 

Static Public Member Functions

static int bandwidthToM (bool isMS1, int degree, double bandwidth)
 Convert frequency domain bandwidth to spatial domain parameter m.
 
static int noiseGainToM (bool isMS1, int degree, double noiseGain)
 Convert desired noise gain to optimal parameter m.
 
static double savitzkyGolayBandwidth (int degree, int m)
 Compute equivalent Savitzky-Golay bandwidth for comparison.
 
- Static Public Member Functions inherited from DefaultParamHandler
static void writeParametersToMetaValues (const Param &write_this, MetaInfoInterface &write_here, const String &key_prefix="")
 Writes all parameters to meta values.
 

Protected Member Functions

void updateMembers_ () override
 Sync internal state from parameters.
 
- Protected Member Functions inherited from DefaultParamHandler
void defaultsToParam_ ()
 Updates the parameters after the defaults have been set in the constructor.
 

Private Member Functions

void registerDefaults_ ()
 Register default parameters (shared by both constructors)
 
std::vector< double > makeKernel (bool isMS1, int degree, int m, const std::vector< double > &coeffs)
 Construct the modified sinc convolution kernel.
 
std::vector< double > getCoefficients (bool isMS1, int degree, int m)
 Get correction coefficients for kernel modification.
 
std::vector< double > makeFitWeights (bool isMS1, int degree, int m)
 Construct weights for boundary linear regression.
 
std::vector< double > extendData (const std::vector< double > &data, int m)
 Extend data boundaries using weighted linear regression.
 

Static Private Member Functions

static double sqr (double x)
 Helper: square function.
 

Private Attributes

bool isMS1_
 MS1 vs MS filter variant selection.
 
int degree_
 Polynomial degree for sinc modification (even, 2-10)
 
int m_
 Kernel half-width parameter (spatial domain)
 
std::vector< double > kernel_
 Symmetric convolution kernel coefficients [k_0, k_1, ..., k_m].
 
std::vector< double > fit_weights_
 Weights for boundary linear regression fitting.
 

Additional Inherited Members

- Public Types inherited from ProgressLogger
enum  LogType { CMD , GUI , NONE }
 Possible log types. More...
 
- Protected Attributes inherited from ProgressLogger
LogType type_
 
time_t last_invoke_
 
ProgressLoggerImplcurrent_logger_
 
- Protected Attributes inherited from DefaultParamHandler
Param param_
 Container for current parameters.
 
Param defaults_
 Container for default parameters. This member should be filled in the constructor of derived classes!
 
std::vector< Stringsubsections_
 Container for registered subsections. This member should be filled in the constructor of derived classes!
 
String error_name_
 Name that is displayed in error messages during the parameter checking.
 
bool check_defaults_
 If this member is set to false no checking if parameters in done;.
 
bool warn_empty_defaults_
 If this member is set to false no warning is emitted when defaults are empty;.
 
- Static Protected Attributes inherited from ProgressLogger
static int recursion_depth_
 

Detailed Description

Computes a modified sinc smoothing filter for profile data.

This class implements the modified sinc (MS) filter from Schmid, Rath & Diebold, "Why and How Savitzky-Golay Filters Should Be Replaced", ACS Measurement Science Au, 2022, 2(2), 185-196.

The filter supports two variants from the paper:

  • MS variant (isMS1 = false): wider kernel with decay alpha=4, providing excellent stopband suppression (~-70 dB). Requires m >= degree/2 + 2.
  • MS1 variant (isMS1 = true): narrower kernel with decay alpha=2, trading some stopband suppression for a smaller kernel size. Requires m >= degree/2 + 1.
Note
These are two filter design variants, NOT mass spectrometry scan level designations. The naming follows the original paper's convention.

The algorithm constructs a symmetric convolution kernel based on a sinc function multiplied by a modified Gaussian window, with optional passband correction terms for polynomial degrees >= 6 (MS) or >= 4 (MS1).

Parameters:

  • degree: polynomial degree (must be even, 2-10). Higher degree gives sharper cutoff.
  • m: kernel half-width (determines smoothing strength). Use bandwidthToM() or noiseGainToM() to compute from desired filter characteristics.
  • isMS1: selects MS1 (smaller) vs MS (wider) kernel variant.

Boundary Handling: For finite data, the filter extends boundaries using weighted linear regression on the nearest available data points to minimize edge artifacts.

Container Support: The filter can process individual data vectors or OpenMS container types (MSSpectrum, MSChromatogram, Mobilogram, PeakMap).

Note
This filter works optimally with uniform profile data.
Data should be sorted by position (m/z, RT, or IM) before filtering.

Constructor & Destructor Documentation

◆ ModifiedSincSmoother() [1/2]

Default constructor with parameter registration.

◆ ModifiedSincSmoother() [2/2]

ModifiedSincSmoother ( bool  isMS1,
int  degree,
int  m 
)

Constructor initializing the modified sinc smoother.

Parameters
isMS1true for MS1 variant (smaller kernel), false for MS variant (wider kernel)
degreepolynomial degree for sinc modification (must be even, 2-10)
mkernel half-width parameter (spatial domain)
Exceptions
std::invalid_argumentif degree is not even or outside [2,10]
std::invalid_argumentif m is too small for the given degree (minimum: m >= degree/2 + 1 for MS1 variant, m >= degree/2 + 2 for MS variant)

Member Function Documentation

◆ bandwidthToM()

static int bandwidthToM ( bool  isMS1,
int  degree,
double  bandwidth 
)
static

Convert frequency domain bandwidth to spatial domain parameter m.

Parameters
isMS1true for MS1 variant (smaller kernel), false for MS variant (wider kernel)
degreepolynomial degree used in the filter
bandwidthnormalized frequency bandwidth in (0, 0.5)
Returns
corresponding kernel half-width parameter m
Exceptions
std::invalid_argumentif bandwidth ∉ (0, 0.5)
Note
Bandwidth interpretation: fraction of Nyquist frequency
Smaller bandwidth → larger m → more smoothing

◆ extendData()

std::vector< double > extendData ( const std::vector< double > &  data,
int  m 
)
private

Extend data boundaries using weighted linear regression.

Fits linear models to boundary regions using cosine-squared weights, then extrapolates to extend the data symmetrically by m points on each side.

Parameters
dataoriginal data vector
mextension half-width (points to add on each side)
Returns
extended data: [left_ext..., original_data..., right_ext...]
Note
Left extension: fit forward from start, extrapolate backward
Right extension: fit backward from end, extrapolate forward
Uses fit_weights_ for regression weighting

◆ filter() [1/3]

void filter ( Mobilogram mobilogram)

Apply modified sinc smoothing to a Mobilogram.

Smooths the intensity values of an ion mobility spectrum while preserving all mobility positions and metadata.

Parameters
mobilograminput/output mobilogram to be smoothed in-place
Note
IM positions are preserved exactly; only intensities modified
Negative intensities are clipped to zero after smoothing

◆ filter() [2/3]

void filter ( MSChromatogram chromatogram)

Apply modified sinc smoothing to an MSChromatogram.

Smooths the intensity values of a chromatogram while preserving all retention time positions and metadata.

Parameters
chromatograminput/output chromatogram to be smoothed in-place
Note
RT positions are preserved exactly; only intensities modified
Negative intensities are clipped to zero after smoothing

◆ filter() [3/3]

void filter ( MSSpectrum spectrum)

Apply modified sinc smoothing to an MSSpectrum.

Smooths the intensity values of a mass spectrum while preserving all m/z positions and metadata. Uses copy-filter-swap pattern for exception safety.

Parameters
spectruminput/output spectrum to be smoothed in-place
Note
Requires uniform profile data for optimal results
m/z positions are preserved exactly; only intensities modified
Negative intensities are clipped to zero after smoothing

◆ filterExperiment()

void filterExperiment ( PeakMap map)

Apply modified sinc smoothing to all spectra and chromatograms in an experiment.

Batch processes all MSSpectra and MSChromatograms in the peak map, applying the filter to each container. Progress is reported via the ProgressLogger interface.

Parameters
mapinput/output experiment to be smoothed in-place
Note
Processes both spectra and chromatograms
Progress is reported as "smoothing data" with step counts
All metadata and positions are preserved across containers

◆ getCoefficients()

std::vector< double > getCoefficients ( bool  isMS1,
int  degree,
int  m 
)
private

Get correction coefficients for kernel modification.

Parameters
isMS1MS1 vs MS filter variant selection
degreepolynomial degree
mkernel half-width
Returns
correction coefficients (currently empty placeholder)
Note
Currently returns empty vector; reserved for future enhancements

◆ makeFitWeights()

std::vector< double > makeFitWeights ( bool  isMS1,
int  degree,
int  m 
)
private

Construct weights for boundary linear regression.

Derives fitting window size and cosine-squared weights based on kernel first zero location and empirical beta parameter.

Parameters
isMS1MS1 vs MS filter variant selection
degreepolynomial degree
mkernel half-width
Returns
weight vector for boundary fitting
Note
Weight derivation: first_zero → beta → fit_length → cos²(·) weights
Optimized separately for MS1 and MS filter variant boundary characteristics

◆ makeKernel()

std::vector< double > makeKernel ( bool  isMS1,
int  degree,
int  m,
const std::vector< double > &  coeffs 
)
private

Construct the modified sinc convolution kernel.

Parameters
isMS1MS1 vs MS filter variant selection
degreepolynomial degree for modifications
mkernel half-width
coeffsoptional correction coefficients (currently unused)
Returns
normalized symmetric kernel [k_0, k_1, ..., k_m]
Note
Kernel is normalized to unity gain at DC (frequency 0)
Incorporates exponential decay terms for improved characteristics

◆ noiseGainToM()

static int noiseGainToM ( bool  isMS1,
int  degree,
double  noiseGain 
)
static

Convert desired noise gain to optimal parameter m.

Computes the kernel half-width m that achieves the specified noise gain factor for the given filter configuration.

Parameters
isMS1true for MS1 variant (smaller kernel), false for MS variant (wider kernel)
degreepolynomial degree used in the filter
noiseGaindesired noise amplification factor (typically < 1)
Returns
corresponding kernel half-width parameter m
Note
noiseGain = 1 means noise unchanged, < 1 means noise reduction
Formula based on empirical characterization of filter response

◆ registerDefaults_()

void registerDefaults_ ( )
private

Register default parameters (shared by both constructors)

◆ savitzkyGolayBandwidth()

static double savitzkyGolayBandwidth ( int  degree,
int  m 
)
static

Compute equivalent Savitzky-Golay bandwidth for comparison.

Given modified sinc parameters, computes the frequency bandwidth that a Savitzky-Golay filter of the same degree would need to achieve similar smoothing characteristics.

Parameters
degreepolynomial degree
mkernel half-width parameter
Returns
equivalent Savitzky-Golay bandwidth
Note
Useful for comparing filter characteristics across algorithms
Based on empirical matching of filter frequency responses

◆ smooth()

std::vector< double > smooth ( const std::vector< double > &  data)

Smooth a vector of data values with boundary extrapolation.

Applies the modified sinc filter to the input data. Boundaries are extended using weighted linear regression before filtering, then the result is trimmed to match the original input size.

Parameters
datainput intensity values to be smoothed
Returns
smoothed data vector of same size as input
Note
Returns empty vector if input is empty
All values in returned vector correspond to positions in original data

◆ smoothExceptBoundaries()

std::vector< double > smoothExceptBoundaries ( const std::vector< double > &  data)

Smooth data without boundary extension (interior points only).

Applies the modified sinc filter only where a full symmetric neighborhood exists. Boundary points are left as zeros. This method is typically used with pre-extended data.

Parameters
datainput data (potentially pre-extended)
Returns
smoothed data vector of same size, with boundary zeros
Note
Use this method when you have already extended the data externally
Boundary points (within kernel radius) will be zero in output

◆ sqr()

static double sqr ( double  x)
inlinestaticprivate

Helper: square function.

◆ updateMembers_()

void updateMembers_ ( )
overrideprotectedvirtual

Sync internal state from parameters.

Reimplemented from DefaultParamHandler.

Member Data Documentation

◆ degree_

int degree_
private

Polynomial degree for sinc modification (even, 2-10)

◆ fit_weights_

std::vector<double> fit_weights_
private

Weights for boundary linear regression fitting.

◆ isMS1_

bool isMS1_
private

MS1 vs MS filter variant selection.

◆ kernel_

std::vector<double> kernel_
private

Symmetric convolution kernel coefficients [k_0, k_1, ..., k_m].

◆ m_

int m_
private

Kernel half-width parameter (spatial domain)