Exemplo n.º 1
0
int
main (int argc, char** argv)
{

  vsip::vsipl v(argc, argv);
  vsip::Rand<cscalar_f> R(1);

  scalar_f w_background = 0.01f;

  length_type const NB = 3;
  length_type const NK = 1024;

  // scalar_f scale = 1.f*NK;

  Matrix<cscalar_f> data(NK, NB);
  Matrix<cscalar_f> copy(NK, NB);
  Matrix<cscalar_f> covar(NB, NB);
  Matrix<cscalar_f> B(NB, 1);
  Matrix<cscalar_f> X(NB, 1);
  Matrix<cscalar_f> X2(NB, 1);
  Matrix<cscalar_f> chk(NB, 1);

  // Put some data into a matrix with some covariance properties.
  if (true)
  {
    for (index_type b=0; b<NB; ++b)
      for (index_type k=0; k<NK; ++k)
	data.put(k, b, w_background * R.randn());
  }

  coherent(data, R, 0, 1, 0, NK, 0.20f, 1.00f, 0.001f);
  coherent(data, R, 2, 1, 0, NK, 0.10f, 1.00f, 0.001f);
  coherent(data, R, 0, 2, 0, NK, 0.50f, 0.25f, 0.001f);

  // Build covariance matrix.
  covar = prod(herm(data), data); // / scale;
  Matrix<cscalar_f> covar2 = prod(herm(data), data);

  assert(maxdiff(covar, covar2) < 1e-6);

  B = 0.f; B.put(1, 0, 1.f);
  // B /= scale;

  // Solve covariance system (copy data since covsol may overwrite it)
  copy = data; covsol(copy, B, X);
  copy = data; X2 = covsol(copy, B);

  assert(maxdiff(X, X2) < 1e-6);

  // Check solution.
  chk = prod(covar, X);

  vsip::scalar_f epsilon = 1e-3;
  vsip::scalar_f error = maxdiff(chk, B);

  assert(error < epsilon);
  
  return EXIT_SUCCESS;
}
Exemplo n.º 2
0
// Simple filter example: Uses static allocation
void
simple_filter(length_type const N)
{
  // Create an object given a fixed input signal length, known
  // at initialization time.  May be allocated as a static or
  // global and persist throughout the lifetime of the program.
  Filter filter(N);

  Vector<cscalar_f> in(N, cscalar_f(1.f));
  Vector<cscalar_f> k(N, cscalar_f(1.f));
  Vector<cscalar_f> out(N);

  filter(in, k, out);
}  
Exemplo n.º 3
0
// Resizable filter example: Uses dynamic allocation
void
resizable_filter(length_type const N)
{
  // Create an object and defer allocation of the wrapped object
  // until reconfigure() is called, usually at a time after the system
  // is up and running and the size information has been obtained
  // via some sort of I/O (a file is read, or a message is received).
  Dynamic_filter filter;
  filter.reconfigure(N);

  Vector<cscalar_f> in(N, cscalar_f(1.f));
  Vector<cscalar_f> k(N, cscalar_f(1.f));
  Vector<cscalar_f> out(N);

  filter(in, k, out);

  // Change the input signal length and only operate on the first
  // half of the data, just to demonstrate how this is done.
  filter.reconfigure(N/2);

  Domain<1> n2(N/2);
  filter(in(n2), k(n2), out(n2));
}  
void
test_meansqval()
{
  using vsip::Vector;
  using vsip::cscalar_f;
  using vsip::scalar_f;
  using vsip::meansqval;

  // Specification appears to be incorrect.
  Vector<cscalar_f>
		vec (2, cscalar_f (1.0, 0.0));

  vec.put(0, cscalar_f(1.f, 0.f));
  vec.put(1, cscalar_f(1.f, 0.f));
  insist(equal(meansqval(vec), scalar_f(1.0)));

  vec.put(0, cscalar_f(0.f, 1.f));
  vec.put(1, cscalar_f(0.f, 1.f));
  insist(equal(meansqval(vec), scalar_f(1.0)));

  vec.put(0, cscalar_f(1.f, 0.f));
  vec.put(1, cscalar_f(0.f, 2.f));
  insist(equal(meansqval(vec), scalar_f(2.5)));
}