3 #include <boost/numeric/ublas/matrix.hpp>
4 #include <boost/numeric/ublas/operation.hpp>
5 #include <boost/numeric/ublas/triangular.hpp>
6 #include <boost/numeric/ublas/lu.hpp>
7 #include <boost/numeric/ublas/io.hpp>
9 using namespace boost::numeric::ublas;
14 template<
class InMatrix,
class OutMatrix>
17 using namespace boost::numeric::ublas;
18 typedef permutation_matrix<std::size_t> pmatrix;
21 pmatrix pm(input.size1());
24 int res = lu_factorize(input, pm);
29 inverse.assign(boost::numeric::ublas::identity_matrix<double>(
33 lu_substitute(input, pm, inverse);
38 WienerFilter::WienerFilter(
const int inputsize) :
39 AdaptiveFilter(inputsize, inputsize), CorrMatrix(inputsize, inputsize),
40 Weights(inputsize), lambda(0)
50 std::copy(Weights.begin(), Weights.end(),
51 std::ostream_iterator<double>(output,
"\n"));
55 const gplib::rvec &Desired)
57 const int inputsize = Input.size();
58 vector<double> Cross(Input.size());
59 vector<double> Auto(Input.size());
60 Correl(Desired, Desired, Auto);
61 Correl(Input, Desired, Cross);
62 for (
int i = 0; i < inputsize; ++i)
63 for (
int j = i; j < inputsize; ++j)
65 CorrMatrix(i, j) = Auto(j - i);
66 CorrMatrix(j, i) = Auto(j - i);
68 CorrMatrix += lambda * identity_matrix<double> (inputsize);
69 matrix<double> Inverse(inputsize, inputsize);
74 axpy_prod(Inverse, Cross, Weights,
true);
80 vector<double> output(Input.size());
81 Convolve(Input, Weights, Output);
virtual void PrintWeights(std::ostream &output)
Print the current set of weights to the output stream, has to be implemented in derived class...
virtual void AdaptFilter(const gplib::rvec &Input, const gplib::rvec &Desired)
Adapt the filter weights given the Input and Desired vectors.
bool InvertMatrix(InMatrix &input, OutMatrix &inverse)
A generic base class for all types of adaptive filters.
void SetOutput(const gplib::rvec &Out)
Possibility for derived classes to set output.
virtual void CalcOutput(const gplib::rvec &Input, gplib::rvec &Output)
Calculate the filter output given Input.