IterDecon.cpp
Go to the documentation of this file.00001 #include "IterDecon.h"
00002 #include "miscfunc.h"
00003 #include <boost/algorithm/minmax_element.hpp>
00004 #include <iostream>
00005 #include <cmath>
00006
00007 namespace gplib
00008 {
00009
00010 IterDecon::IterDecon(const int inputsize, TsSpectrum &Spec) :
00011 AdaptiveFilter(inputsize, inputsize), Weights(inputsize), Spectrum(Spec)
00012 {
00013 for (int i = 0; i < inputsize; ++i)
00014 Weights(i) = 0;
00015 }
00016
00017 IterDecon::~IterDecon()
00018 {
00019 }
00020
00021 void IterDecon::PrintWeights(std::ostream &output)
00022 {
00023 std::copy(Weights.begin(), Weights.end(),
00024 std::ostream_iterator<double>(output, "\n"));
00025 }
00026
00027 void IterDecon::AdaptFilter(const gplib::rvec &Input,
00028 const gplib::rvec &Desired)
00029 {
00030 typedef gplib::rvec::const_iterator iterator;
00031 gplib::rvec Corr(Desired.size());
00032 Correl(Desired, Input, Corr, Spectrum);
00033 const double power = ublas::prec_inner_prod(Input, Input);
00034 std::pair<iterator, iterator> MinMaxPos(boost::minmax_element(
00035 Corr.begin(), Corr.begin() + Corr.size() / 2));
00036 int MaxIndex = MinMaxPos.second - Corr.begin();
00037 int MinIndex = MinMaxPos.first - Corr.begin();
00038
00039 if (std::abs(*MinMaxPos.second) > std::abs(*MinMaxPos.first))
00040 Weights(MaxIndex) += *MinMaxPos.second / power;
00041 else
00042 Weights(MinIndex) += *MinMaxPos.first / power;
00043 }
00044
00045 void IterDecon::CalcOutput(const gplib::rvec &Input, gplib::rvec &Output)
00046 {
00047 Convolve(Input, Weights, Output, Spectrum);
00048 SetOutput(Output);
00049 }
00050 }