~ubuntu-branches/ubuntu/trusty/gnuradio/trusty

« back to all changes in this revision

Viewing changes to gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- c++ -*- */
 
2
/*
 
3
 * Copyright 2002,2007 Free Software Foundation, Inc.
 
4
 * 
 
5
 * This file is part of GNU Radio
 
6
 * 
 
7
 * GNU Radio is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 3, or (at your option)
 
10
 * any later version.
 
11
 * 
 
12
 * GNU Radio is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with GNU Radio; see the file COPYING.  If not, write to
 
19
 * the Free Software Foundation, Inc., 51 Franklin Street,
 
20
 * Boston, MA 02110-1301, USA.
 
21
 */
 
22
 
 
23
#include <cppunit/TestAssert.h>
 
24
#include <qa_gri_mmse_fir_interpolator_cc.h>
 
25
#include <gri_mmse_fir_interpolator_cc.h>
 
26
#include <stdio.h>
 
27
#include <cmath>
 
28
#include <stdexcept>
 
29
 
 
30
#define NELEM(x) (sizeof (x) / sizeof (x[0]))
 
31
 
 
32
 
 
33
static float
 
34
test_fcn_sin(double index)
 
35
{
 
36
  return (2 * sin (index * 0.25 * 2 * M_PI + 0.125 * M_PI)
 
37
          + 3 * sin (index * 0.077 * 2 * M_PI + 0.3 * M_PI));
 
38
}
 
39
 
 
40
static float
 
41
test_fcn_cos(double index)
 
42
{
 
43
  return (2 * cos (index * 0.25 * 2 * M_PI + 0.125 * M_PI)
 
44
          + 3 * cos (index * 0.077 * 2 * M_PI + 0.3 * M_PI));
 
45
}
 
46
 
 
47
static gr_complex
 
48
test_fcn(double index)
 
49
{
 
50
  return gr_complex(test_fcn_cos(index), test_fcn_sin(index));
 
51
}
 
52
 
 
53
 
 
54
void
 
55
qa_gri_mmse_fir_interpolator_cc::t1()
 
56
{
 
57
  static const unsigned N = 100;
 
58
  gr_complex input[N + 10] __attribute__ ((aligned (8)));
 
59
 
 
60
  for (unsigned i = 0; i < NELEM(input); i++)
 
61
    input[i] = test_fcn ((double) i);
 
62
 
 
63
  gri_mmse_fir_interpolator_cc  intr;
 
64
  float inv_nsteps = 1.0 / intr.nsteps ();
 
65
 
 
66
  for (unsigned i = 0; i < N; i++){
 
67
    for (unsigned imu = 0; imu <= intr.nsteps (); imu += 1){
 
68
      gr_complex expected = test_fcn ((i + 3) + imu * inv_nsteps);
 
69
      gr_complex actual = intr.interpolate (&input[i], imu * inv_nsteps);
 
70
 
 
71
      CPPUNIT_ASSERT_COMPLEXES_EQUAL (expected, actual, 0.004);
 
72
      // printf ("%9.6f  %9.6f  %9.6f\n", expected, actual, expected - actual);
 
73
    }
 
74
  }
 
75
}
 
76
 
 
77
 
 
78
/*
 
79
 * Force bad alignment and confirm that it raises an exception
 
80
 */
 
81
void
 
82
qa_gri_mmse_fir_interpolator_cc::t2_body()
 
83
{
 
84
  static const unsigned N = 100;
 
85
  float float_input[2*(N+10) + 1];
 
86
  gr_complex *input;
 
87
 
 
88
  // We require that gr_complex be aligned on an 8-byte boundary.
 
89
  // Ensure that we ARE NOT ;)
 
90
 
 
91
  if (((intptr_t) float_input & 0x7) == 0)
 
92
    input = reinterpret_cast<gr_complex *>(&float_input[1]);
 
93
  else
 
94
    input = reinterpret_cast<gr_complex *>(&float_input[0]);
 
95
 
 
96
 
 
97
  for (unsigned i = 0; i < (N+10); i++)
 
98
    input[i] = test_fcn ((double) i);
 
99
 
 
100
  gri_mmse_fir_interpolator_cc  intr;
 
101
  float inv_nsteps = 1.0 / intr.nsteps ();
 
102
 
 
103
  for (unsigned i = 0; i < N; i++){
 
104
    for (unsigned imu = 0; imu <= intr.nsteps (); imu += 1){
 
105
      gr_complex expected = test_fcn ((i + 3) + imu * inv_nsteps);
 
106
      gr_complex actual = intr.interpolate (&input[i], imu * inv_nsteps);
 
107
 
 
108
      CPPUNIT_ASSERT_COMPLEXES_EQUAL (expected, actual, 0.004);
 
109
      // printf ("%9.6f  %9.6f  %9.6f\n", expected, actual, expected - actual);
 
110
    }
 
111
  }
 
112
}
 
113
 
 
114
void
 
115
qa_gri_mmse_fir_interpolator_cc::t2()
 
116
{
 
117
  CPPUNIT_ASSERT_THROW(t2_body(), std::invalid_argument);
 
118
}