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

« back to all changes in this revision

Viewing changes to gnuradio-core/src/lib/general/qa_gr_math.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
/*
 
2
 * Copyright 2008 Free Software Foundation, Inc.
 
3
 * 
 
4
 * This file is part of GNU Radio
 
5
 * 
 
6
 * GNU Radio is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 3, or (at your option)
 
9
 * any later version.
 
10
 * 
 
11
 * GNU Radio is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with GNU Radio; see the file COPYING.  If not, write to
 
18
 * the Free Software Foundation, Inc., 51 Franklin Street,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include <gr_math.h>
 
23
#include <qa_gr_math.h>
 
24
#include <cppunit/TestAssert.h>
 
25
#include <stdio.h>
 
26
 
 
27
void
 
28
qa_gr_math::test_binary_slicer1 ()
 
29
{
 
30
  float x[5] = {-1, -0.5, 0, 0.5, 1.0};
 
31
  unsigned int z[5] = {0, 0, 1, 1, 1};
 
32
  unsigned int y;
 
33
 
 
34
  //printf("\nBinary\n");
 
35
  for (unsigned int i = 0; i < 5; i++) {
 
36
    y = gr_binary_slicer(x[i]);
 
37
    //printf("in: %f   out: %d   desired: %d\n", x[i], y, z[i]);
 
38
 
 
39
    CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9);
 
40
  }
 
41
 
 
42
  //printf("\nBranchless Binary\n");
 
43
  for (unsigned int i = 0; i < 5; i++) {
 
44
    y = gr_branchless_binary_slicer(x[i]);
 
45
    //printf("in: %f   out: %d   desired: %d\n", x[i], y, z[i]);
 
46
 
 
47
    CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9);    
 
48
  }
 
49
}
 
50
 
 
51
void
 
52
qa_gr_math::test_quad_0deg_slicer1 ()
 
53
{
 
54
  gr_complex x[4] = {gr_complex(1, 0),
 
55
                     gr_complex(0, 1), 
 
56
                     gr_complex(-1, 0),
 
57
                     gr_complex(0, -1)};
 
58
 
 
59
  unsigned int z[4] = {0, 1, 2, 3};
 
60
  unsigned int y;
 
61
 
 
62
  //printf("\nQuad0\n");
 
63
  for (unsigned int i = 0; i < 4; i++) {
 
64
    y = gr_quad_0deg_slicer(x[i]);
 
65
    //printf("in: %.4f+j%.4f   out: %d   desired: %d\n", x[i].real(), x[i].imag(), y, z[i]);
 
66
 
 
67
    CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9);
 
68
  }
 
69
 
 
70
  //printf("\nBranchless Quad0\n");
 
71
  for (unsigned int i = 0; i < 4; i++) {
 
72
    y = gr_branchless_quad_0deg_slicer(x[i]);
 
73
    //printf("in: %.4f+j%.4f   out: %d   desired: %d\n", x[i].real(), x[i].imag(), y, z[i]);
 
74
    
 
75
    CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9);
 
76
  }
 
77
}
 
78
 
 
79
void
 
80
qa_gr_math::test_quad_45deg_slicer1 ()
 
81
{
 
82
  gr_complex x[4] = {gr_complex(0.707, 0.707),
 
83
                     gr_complex(-0.707, 0.707), 
 
84
                     gr_complex(-0.707, -0.707),
 
85
                     gr_complex(0.707, -0.707)};
 
86
  
 
87
  unsigned int z[4] = {0, 1, 2, 3};
 
88
  unsigned int y;
 
89
 
 
90
  //printf("\nQuad45\n");
 
91
  for (unsigned int i = 0; i < 4; i++) {
 
92
    y = gr_quad_45deg_slicer(x[i]);
 
93
    //printf("in: %.4f+j%.4f   out: %d   desired: %d\n", x[i].real(), x[i].imag(), y, z[i]);
 
94
 
 
95
    CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9);
 
96
  }
 
97
 
 
98
  //printf("\nBranchless Quad45\n");
 
99
  for (unsigned int i = 0; i < 4; i++) {
 
100
    y = gr_branchless_quad_45deg_slicer(x[i]);
 
101
    //printf("in: %.4f+j%.4f   out: %d   desired: %d\n", x[i].real(), x[i].imag(), y, z[i]);
 
102
 
 
103
    CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9);
 
104
  }
 
105
}