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); //calculate the correlation between desired and input
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)); //find minimum and maximum
00036         int MaxIndex = MinMaxPos.second - Corr.begin(); //index of maximum
00037         int MinIndex = MinMaxPos.first - Corr.begin(); //index of minimum
00038 
00039         if (std::abs(*MinMaxPos.second) > std::abs(*MinMaxPos.first)) //if max has higher absolute value than min
00040           Weights(MaxIndex) += *MinMaxPos.second / power; //update weight for max
00041         else
00042           Weights(MinIndex) += *MinMaxPos.first / power; //update weight for min
00043       }
00044 
00045     void IterDecon::CalcOutput(const gplib::rvec &Input, gplib::rvec &Output)
00046       {
00047         Convolve(Input, Weights, Output, Spectrum);//multiplication with a toeplitz matrix is the same as cyclic convolution
00048         SetOutput(Output);
00049       }
00050   }

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8