GPLIB++
WienerInterpolator.cpp
Go to the documentation of this file.
1 #include "WienerInterpolator.h"
2 #include <iostream>
3 #include <iterator>
4 #include <algorithm>
5 
6 namespace gplib
7  {
8 
9  WienerInterpolator::WienerInterpolator(const int filterlength) :
10  LSSOFilter(filterlength), xms(0.0)
11  {
12  }
13 
15  {
16  }
17 
18  void WienerInterpolator::AdaptFilter(const gplib::rvec &Input,
19  const gplib::rvec &Desired)
20  {
21  const int size = Input.size();
22  const int filterlength = GetWeights().size();
23  gplib::rvec wk1(size);
24  gplib::rvec wk2(size);
25  gplib::rvec wkm(filterlength);
26  double power = inner_prod(Input, Input);
27  xms = power / size;
28  std::fill_n(wkm.begin(), filterlength, 0.0);
29 
30  wk1(0) = Input(0);
31  wk2(size - 2) = Input(size - 1);
32  for (int i = 1; i < size - 1; ++i)
33  {
34  wk1(i) = Input(i);
35  wk2(i - 1) = Input(i);
36  }
37  for (int j = 0; j < filterlength; ++j)
38  {
39  double num = 0.0;
40  double denom = 0.0;
41  for (int k = 0; k < (size - j - 1); ++k)
42  {
43  num += wk1(k) * wk2(k);
44  denom += wk1(k) * wk1(k) + wk2(k) * wk2(k);
45  }
46  SetWeights()(j) = 2.0 * num / denom;
47  xms *= (1.0 - GetWeights()(j) * GetWeights()(j));
48  for (int k = 0; k < j; ++k)
49  {
50  SetWeights()(k) = wkm(k) - GetWeights()(j) * wkm(j - k - 1);
51  }
52  if (j == filterlength - 1)
53  {
54  reverse(SetWeights().begin(), SetWeights().end());
55  return;
56  }
57  for (int k = 0; k <= j; ++k)
58  wkm(k) = GetWeights()(k);
59  for (int k = 0; k < size - j - 2; ++k)
60  {
61  wk1(k) -= wkm(j) * wk2(k);
62  wk2(k) = wk2(k + 1) - wkm(j) * wk1(k + 1);
63  }
64  }
65  }
66  }
const gplib::rvec & GetWeights()
Return the current set of weights.
Definition: LSSOFilter.h:41
WienerInterpolator(const int filterlength)
The constructor needs to know the filterlength.
gplib::rvec & SetWeights()
Definition: LSSOFilter.h:26
Base class for least squares filter with a single output value.
Definition: LSSOFilter.h:20
const int size
Definition: perftest.cpp:14
virtual void AdaptFilter(const gplib::rvec &Input, const gplib::rvec &Desired)
Calculate the prediction coefficients, the contents of Desired are ignored, this function has to be i...