3 #include <boost/algorithm/minmax_element.hpp>
11 AdaptiveFilter(inputsize, inputsize), Weights(inputsize), Spectrum(Spec)
13 for (
int i = 0; i < inputsize; ++i)
23 std::copy(Weights.begin(), Weights.end(),
24 std::ostream_iterator<double>(output,
"\n"));
28 const gplib::rvec &Desired)
30 typedef gplib::rvec::const_iterator iterator;
31 gplib::rvec Corr(Desired.size());
32 Correl(Desired, Input, Corr, Spectrum);
33 const double power = ublas::prec_inner_prod(Input, Input);
34 std::pair<iterator, iterator> MinMaxPos(boost::minmax_element(
35 Corr.begin(), Corr.begin() + Corr.size() / 2));
36 int MaxIndex = MinMaxPos.second - Corr.begin();
37 int MinIndex = MinMaxPos.first - Corr.begin();
39 if (std::abs(*MinMaxPos.second) > std::abs(*MinMaxPos.first))
40 Weights(MaxIndex) += *MinMaxPos.second / power;
42 Weights(MinIndex) += *MinMaxPos.first / power;
47 Convolve(Input, Weights, Output, Spectrum);
IterDecon(const int inputsize, TsSpectrum &Spec)
Input and output length have to be the same, so only one parameter for the constructor.
virtual void AdaptFilter(const gplib::rvec &Input, const gplib::rvec &Desired)
Adapt the filter weights given the Input and Desired vectors.
A generic base class for all types of adaptive filters.
virtual void PrintWeights(std::ostream &output)
print weights to a file
virtual void CalcOutput(const gplib::rvec &Input, gplib::rvec &Output)
Calculate the filter output given Input.
The class CTsSpectrum is used to calculate spectra from (real) time series data.
void SetOutput(const gplib::rvec &Out)
Possibility for derived classes to set output.