ProteoWizard
gaussfilter.hpp
Go to the documentation of this file.
1 //
2 // $Id: gaussfilter.hpp 5313 2013-12-17 18:06:54Z chambm $
3 //
4 //
5 // Original author: Witold Wolski <wewolski@gmail.com>
6 //
7 // Copyright : ETH Zurich
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 #ifndef GAUSSFILTERTYPES_H
23 #define GAUSSFILTERTYPES_H
24 
25 #include <boost/math/distributions/normal.hpp>
27 
28 
29 namespace ralab{
30  namespace base{
31  namespace filter{
32 
33  /*! \brief generate the gauss filter function for filtering of peaks with fwhm (full width at half max)
34 
35  \post accumulate(gauss) == 1.
36  \return accumulate(gauss) == 1.
37  */
38  template <typename TReal>
39  TReal getGaussianFilter
40  (
41  std::vector<TReal> & gauss, //!<[out] Gaussian for filtering
42  TReal fwhm = 20 //!<[in] full width at half max in points
43  )
44  {
45  std::vector<TReal> x;
46  ralab::base::base::seq<TReal>( -ceil(TReal(2*fwhm)), ceil(TReal(2*fwhm)) , x);
47  TReal sigma = fwhm/2.35;
48  //generate response
49  return utilities::getGaussWorker(sigma, gauss, x);
50  }
51 
52  /*! \brief generate the gauss filter function for filtering of peaks with fwhm (full width at half max)
53 
54  \post accumulate(gauss) == 1.
55  \return accumulate(gauss) == 1.
56  */
57  template <typename TReal>
59  (
60  std::vector<TReal> & gauss, //!<[out] Gaussian for filtering
61  TReal fwhm = 20, //!<[in] full width at half max in points
62  TReal quantile = 0.01 //!< would mean that the generated distribution covers at least 99.8 of mass
63  )
64  {
65  if( quantile >= 0.5)
66  {
67  throw std::logic_error("quantile >= 0.5");
68  }
69  std::vector<TReal> x;
70 
71  TReal sigma = fwhm/2.35;
72  boost::math::normal_distribution<TReal> nd_(0,sigma);
73  TReal quant = floor(boost::math::quantile(nd_,quantile));
74  ralab::base::base::seq( quant , -quant , x);
75  return utilities::getGaussWorker(sigma, gauss, x);
76 
77  }
78 
79 
80  /*! \brief generate first derivative Gauss
81 
82  \post accumulate(gauss1d) == 0.
83  \post accumulate(fabs(gauss1d)) == 1.
84  */
85 
86  template <typename TReal>
88  std::vector<TReal> & gauss1d, //!<[out] Gaussian for filtering
89  TReal fwhm = 20 //!<[in] full width at half max in points
90  )
91  {
92  std::vector<TReal> x;
93  ralab::base::base::seq( - ceil(TReal(2*fwhm)), ceil(TReal(2*fwhm)) , x);
94  TReal sigma = fwhm/2.35;
95  //generate response
96  return utilities::getGaussian1DerWorker(sigma, gauss1d, x);
97  }
98 
99 
100 
101  template <typename TReal>
103  std::vector<TReal> & gauss1d, //!<[out] Gaussian for filtering
104  TReal fwhm = 20, //!<[in] full width at half max in points
105  TReal quantile = 0.1
106  )
107  {
108  if( quantile >= 0.5)
109  {
110  throw std::logic_error("quantile >= 0.5");
111  }
112  std::vector<TReal> x;
113  TReal sigma = fwhm/2.35;
114  boost::math::normal_distribution<TReal> nd_(0,sigma);
115  TReal quant = floor(boost::math::quantile(nd_,quantile));
116  ralab::base::base::seq( quant , -quant , x);
117  //generate response
118  return utilities::getGaussian1DerWorker(sigma, gauss1d, x);
119  }
120  }//filter
121  }//base
122 }//ralab
123 
124 #endif
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
Definition: base.hpp:49
TReal getGaussianFilterQuantile(std::vector< TReal > &gauss, TReal fwhm=20, TReal quantile=0.01)
generate the gauss filter function for filtering of peaks with fwhm (full width at half max) ...
Definition: gaussfilter.hpp:59
TReal getGaussian1DerWorker(TReal sigma, std::vector< TReal > &gauss1d, std::vector< TReal > &x)
Definition: gauss.hpp:130
TReal getGaussianFilter(std::vector< TReal > &gauss, TReal fwhm=20)
generate the gauss filter function for filtering of peaks with fwhm (full width at half max) ...
Definition: gaussfilter.hpp:40
TReal getGaussWorker(TReal sigma, std::vector< TReal > &gauss, std::vector< TReal > &x)
Definition: gauss.hpp:94
EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
Definition: base.hpp:39
TReal getGaussian1DerFilterQuantile(std::vector< TReal > &gauss1d, TReal fwhm=20, TReal quantile=0.1)
KernelTraitsBase< Kernel >::space_type::abscissa_type x
TReal getGaussian1DerFilter(std::vector< TReal > &gauss1d, TReal fwhm=20)
generate first derivative Gauss
Definition: gaussfilter.hpp:87
void filter(const TContainer &data, const TContainer &filter, TContainer &result, bool circular=false, uint32_t sides=2)
Applies linear convolution (filtering) to a univariate time series.
Definition: filter.hpp:112