ProteoWizard
Namespaces | Typedefs | Functions
ralab::base::filter Namespace Reference

Namespaces

namespace  utilities
 

Typedefs

typedef boost::uint32_t uint32_t
 

Functions

template<typename TIterator , typename TFilterIterator , typename TOutputIterator >
void filter_sequence (TIterator dataBeg, TIterator dataEnd, TFilterIterator filterBeg, size_t fsize, TOutputIterator resBeg, bool circular=false, uint32_t sides=2)
 
template<typename TContainer >
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.
 
template<typename TReal >
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)
 
template<typename TReal >
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)
 
template<typename TReal >
TReal getGaussian1DerFilter (std::vector< TReal > &gauss1d, TReal fwhm=20)
 generate first derivative Gauss
 
template<typename TReal >
TReal getGaussian1DerFilterQuantile (std::vector< TReal > &gauss1d, TReal fwhm=20, TReal quantile=0.1)
 

Typedef Documentation

◆ uint32_t

typedef boost::uint32_t ralab::base::filter::uint32_t

Definition at line 47 of file filter.hpp.

Function Documentation

◆ filter_sequence()

template<typename TIterator , typename TFilterIterator , typename TOutputIterator >
void ralab::base::filter::filter_sequence ( TIterator  dataBeg,
TIterator  dataEnd,
TFilterIterator  filterBeg,
size_t  fsize,
TOutputIterator  resBeg,
bool  circular = false,
uint32_t  sides = 2 
)
Parameters
[in]dataBega univariate time series.
[in]filterBega vector of filter coefficients in reverse time order (as for AR or MA coefficients). Lenght of filter must be odd.
[out]resBegresult
[in]circularIf TRUE, wrap the filter around the ends of the series, otherwise assume external values are missing (NA).
[in]sidescurrently only sides 2 supported....

Definition at line 49 of file filter.hpp.

58 {
59 typedef typename std::iterator_traits<TOutputIterator>::value_type TReal;
60 if((fsize-1) % 2)
61 {
62 throw std::logic_error("filter size must be odd");
63 }
64 if(!circular)
65 {
66 //result.assign(data.size(), std::numeric_limits<TReal>::quiet_NaN() );
67
68 size_t offset = static_cast<size_t>(fsize/2);
69 for(std::size_t i = 0 ; i< offset; ++i, ++resBeg)
70 {
71 *resBeg = std::numeric_limits<TReal>::quiet_NaN();
72 }
73
74 for( ; dataBeg != dataEnd - (fsize -1) ; ++dataBeg, ++resBeg )
75 {
76 *resBeg = (std::inner_product(dataBeg , dataBeg + fsize, filterBeg ,0. ));
77 }
78 }
79 else
80 {
81
82 std::vector<typename std::iterator_traits<TIterator>::value_type> tmp;
83 typename std::vector<typename std::iterator_traits<TIterator>::value_type>::iterator it;
84 it = utilities::prepareData( dataBeg, dataEnd, fsize , tmp );
85
86 TIterator tbegin = tmp.begin();
87 TIterator tend = it;
88
89 for( ; tbegin != tend - (fsize-1 ) ; ++tbegin, ++resBeg )
90 {
91 *resBeg = std::inner_product(tbegin , tbegin + fsize, filterBeg ,0. );
92 }
93 }
94 }// filter end

References ralab::base::filter::utilities::prepareData().

Referenced by filter().

◆ filter()

template<typename TContainer >
void ralab::base::filter::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.

The convolution filter is $ y[i] = f[1]*x[i+o] + ... + f[p]*x[i+o-(p-1)] $ where o is the offset: see sides for how it is determined.

Parameters
sidesfor convolution filters only. If sides=1 the filter coefficients are for past values only; if sides=2 they are centred around lag 0. In this case the length of the filter should be odd, but if it is even, more of the filter is forward in time than backward
Parameters
[in]dataa univariate time series.
[in]filtera vector of filter coefficients in reverse time order (as for AR or MA coefficients). Lenght of filter must be odd.
[out]resultresult
[in]circularIf TRUE, wrap the filter around the ends of the series, otherwise assume external values are missing (NA).
[in]sidescurrently only sides 2 supported....

Definition at line 112 of file filter.hpp.

119 {
120 result.resize(data.size());
122 (
123 data.begin(),
124 data.end(),
125 filter.begin(),
126 filter.size(),
127 result.begin(),
128 circular,
129 sides
130 );
131 }// filter end
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
void filter_sequence(TIterator dataBeg, TIterator dataEnd, TFilterIterator filterBeg, size_t fsize, TOutputIterator resBeg, bool circular=false, uint32_t sides=2)
Definition filter.hpp:49

References filter(), and filter_sequence().

Referenced by filter(), and ralab::base::ms::PeakPicker< TReal, TIntegrator >::operator()().

◆ getGaussianFilter()

template<typename TReal >
TReal ralab::base::filter::getGaussianFilter ( std::vector< TReal > &  gauss,
TReal  fwhm = 20 
)

generate the gauss filter function for filtering of peaks with fwhm (full width at half max)

          \post accumulate(gauss) == 1.
          \return accumulate(gauss) == 1.
Parameters
[out]gaussGaussian for filtering
[in]fwhmfull width at half max in points

Definition at line 39 of file gaussfilter.hpp.

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 }
KernelTraitsBase< Kernel >::space_type::abscissa_type x

References ralab::base::filter::utilities::getGaussWorker(), and x.

◆ getGaussianFilterQuantile()

template<typename TReal >
TReal ralab::base::filter::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)

          \post accumulate(gauss) == 1.
          \return accumulate(gauss) == 1.
Parameters
[out]gaussGaussian for filtering
[in]fwhmfull width at half max in points
quantilewould mean that the generated distribution covers at least 99.8 of mass

Definition at line 58 of file gaussfilter.hpp.

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 }
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

References ralab::base::filter::utilities::getGaussWorker(), ralab::base::base::seq(), and x.

Referenced by ralab::base::ms::PeakPicker< TReal, TIntegrator >::PeakPicker().

◆ getGaussian1DerFilter()

template<typename TReal >
TReal ralab::base::filter::getGaussian1DerFilter ( std::vector< TReal > &  gauss1d,
TReal  fwhm = 20 
)

generate first derivative Gauss

          \post accumulate(gauss1d) == 0.
          \post accumulate(fabs(gauss1d)) == 1.
Parameters
[out]gauss1dGaussian for filtering
[in]fwhmfull width at half max in points

Definition at line 87 of file gaussfilter.hpp.

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 }

References ralab::base::filter::utilities::getGaussian1DerWorker(), ralab::base::base::seq(), and x.

◆ getGaussian1DerFilterQuantile()

template<typename TReal >
TReal ralab::base::filter::getGaussian1DerFilterQuantile ( std::vector< TReal > &  gauss1d,
TReal  fwhm = 20,
TReal  quantile = 0.1 
)
Parameters
[out]gauss1dGaussian for filtering
[in]fwhmfull width at half max in points

Definition at line 102 of file gaussfilter.hpp.

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 }

References ralab::base::filter::utilities::getGaussian1DerWorker(), ralab::base::base::seq(), and x.