3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
27 #include <cppunit/TestAssert.h>
29 #include <atsci_fake_single_viterbi.h>
30 #include <qa_atsci_fake_single_viterbi.h>
34 static const int NTRIALS = 50;
35 static const int MAXERRORS = 10;
36 static const int NN = 200;
38 static const int MAXDIBIT = 3;
41 qa_atsci_fake_single_viterbi::encode_block (unsigned char *out, unsigned char *in,
44 for (unsigned int i = 0; i < n; i++) {
45 out[i] = encoder.encode(in[i]);
51 qa_atsci_fake_single_viterbi::decode_block (unsigned char *out, unsigned char *in,
54 for (unsigned int i = 0; i < n; i++) {
55 out[i] = decoder.decode ((2*in[i]-7) + noise ());
60 qa_atsci_fake_single_viterbi::noise ()
63 return 2.0 * ((float) random () / RANDOM_MAX - 0.5);;
70 qa_atsci_fake_single_viterbi::t0 ()
73 unsigned char in[blocklen];
74 unsigned char enc[blocklen];
75 unsigned char out[blocklen];
76 int decoder_errors = 0;
77 int delay = decoder.delay ();
80 // printf (" Delay is %d.\n", delay);
82 srandom (27); // reproducable sequence of "random" values
84 for (int nt = 0; nt < NTRIALS; nt++){
86 // load block with random data and encode
88 for (i = 0; i < (blocklen-delay); i++)
89 in[i] = random () & MAXDIBIT;
90 for ( ; i < blocklen; i++)
91 in[i] = 0; /* To empty the delay buffers */
94 encode_block (enc, in, blocklen);
99 decode_block (out, enc, blocklen);
101 // int offset = delay/4;
103 bool differs = (memcmp (in+offset,
104 out+delay+offset, blocklen-(delay+offset)));
106 // initial values after reset are 0
107 for (i = 0; i < delay; i++){
109 printf (" initial output at %i is %X, not 0\n",
114 printf (" incorrect data, trial #%d\n", nt);
116 printf ("\n Erroneous result dibits:");
117 for (int erri = 0; erri < (NN-delay); erri++) {
118 if (in[erri] != out[erri+delay])
119 printf (" %d", erri);
122 for (int erri = 0; erri < (NN-delay); erri++) {
123 printf (" %d", in[erri]);
126 for (int erri = 0; erri < (NN-delay); erri++) {
127 printf (" %d", out[erri+delay]);
130 for (int erri = 0; erri < (NN-delay); erri++) {
131 printf (" %c", (in[erri] != out[erri+delay])? '*': ' ');
133 printf ("\n THIS IS A REAL PROBLEM.\n");
138 printf (" Summary: %d decoder errors out of %d trials.\n",
139 decoder_errors, NTRIALS);
141 CPPUNIT_ASSERT (decoder_errors == 0);