OpenMS
Loading...
Searching...
No Matches
ModifiedSincSmoother.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Sarah Najar $
7// --------------------------------------------------------------------------
8
9#pragma once
10
17
18#include <vector>
19#include <cmath>
20
21namespace OpenMS
22{
62 class OPENMS_DLLAPI ModifiedSincSmoother :
63 public ProgressLogger,
65 {
66 public:
69
81 ModifiedSincSmoother(bool isMS1, int degree, int m);
82
96 std::vector<double> smooth(const std::vector<double>& data);
97
111 std::vector<double> smoothExceptBoundaries(const std::vector<double>& data);
112
126 static int bandwidthToM(bool isMS1, int degree, double bandwidth);
127
142 static int noiseGainToM(bool isMS1, int degree, double noiseGain);
143
158 static double savitzkyGolayBandwidth(int degree, int m);
159
173 void filter(MSSpectrum& spectrum);
174
186 void filter(MSChromatogram& chromatogram);
187
199 void filter(Mobilogram& mobilogram);
200
215
216 protected:
218 void updateMembers_() override;
219
220 private:
223
225 bool isMS1_;
229 int m_;
231 std::vector<double> kernel_;
233 std::vector<double> fit_weights_;
234
247 std::vector<double> makeKernel(bool isMS1, int degree, int m, const std::vector<double>& coeffs);
248
259 std::vector<double> getCoefficients(bool isMS1, int degree, int m);
260
275 std::vector<double> makeFitWeights(bool isMS1, int degree, int m);
276
291 std::vector<double> extendData(const std::vector<double>& data, int m);
292
300 {
301 double sum_weights = 0;
302 double sum_x = 0;
303 double sum_y = 0;
304 double sum_xy = 0;
305 double sum_x2 = 0;
306 double offset = NAN;
307 double slope = NAN;
308 bool calculated = false;
309
313 void clear();
314
322 void addPointW(double x, double y, double weight);
323
333 void calculate();
334
341 double getOffset();
342
349 double getSlope();
350 };
351
353 static double sqr(double x) { return x * x; }
354 };
355} // namespace OpenMS
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
The representation of a chromatogram.
Definition MSChromatogram.h:30
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
The representation of a 1D ion mobilogram.
Definition Mobilogram.h:32
Computes a modified sinc smoothing filter for profile data.
Definition ModifiedSincSmoother.h:65
std::vector< double > fit_weights_
Weights for boundary linear regression fitting.
Definition ModifiedSincSmoother.h:233
void filter(MSChromatogram &chromatogram)
Apply modified sinc smoothing to an MSChromatogram.
void filter(MSSpectrum &spectrum)
Apply modified sinc smoothing to an MSSpectrum.
std::vector< double > extendData(const std::vector< double > &data, int m)
Extend data boundaries using weighted linear regression.
static double sqr(double x)
Helper: square function.
Definition ModifiedSincSmoother.h:353
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.
int degree_
Polynomial degree for sinc modification (even, 2-10)
Definition ModifiedSincSmoother.h:227
std::vector< double > makeFitWeights(bool isMS1, int degree, int m)
Construct weights for boundary linear regression.
std::vector< double > makeKernel(bool isMS1, int degree, int m, const std::vector< double > &coeffs)
Construct the modified sinc convolution kernel.
std::vector< double > kernel_
Symmetric convolution kernel coefficients [k_0, k_1, ..., k_m].
Definition ModifiedSincSmoother.h:231
std::vector< double > smooth(const std::vector< double > &data)
Smooth a vector of data values with boundary extrapolation.
int m_
Kernel half-width parameter (spatial domain)
Definition ModifiedSincSmoother.h:229
bool isMS1_
MS1 vs MS filter variant selection.
Definition ModifiedSincSmoother.h:225
void updateMembers_() override
Sync internal state from parameters.
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.
std::vector< double > smoothExceptBoundaries(const std::vector< double > &data)
Smooth data without boundary extension (interior points only).
static int bandwidthToM(bool isMS1, int degree, double bandwidth)
Convert frequency domain bandwidth to spatial domain parameter m.
std::vector< double > getCoefficients(bool isMS1, int degree, int m)
Get correction coefficients for kernel modification.
ModifiedSincSmoother()
Default constructor with parameter registration.
ModifiedSincSmoother(bool isMS1, int degree, int m)
Constructor initializing the modified sinc smoother.
void registerDefaults_()
Register default parameters (shared by both constructors)
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:27
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Helper class for weighted linear regression.
Definition ModifiedSincSmoother.h:300
double getSlope()
Get regression slope (dy/dx).
double getOffset()
Get regression intercept (y-value at x=0).
void clear()
Reset accumulator for new regression.
void addPointW(double x, double y, double weight)
Add a weighted data point to the regression.
void calculate()
Compute least-squares line parameters.