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>
35 static const int NTRIALS = 50;
36 static const int MAXERRORS = 10;
37 static const int NN = 200;
39 static const int MAXDIBIT = 3;
42 qa_atsci_fake_single_viterbi::encode_block (unsigned char *out, unsigned char *in,
45 for (unsigned int i = 0; i < n; i++) {
46 out[i] = encoder.encode(in[i]);
52 qa_atsci_fake_single_viterbi::decode_block (unsigned char *out, unsigned char *in,
55 for (unsigned int i = 0; i < n; i++) {
56 out[i] = decoder.decode ((2*in[i]-7) + noise ());
61 qa_atsci_fake_single_viterbi::noise ()
64 return 2.0 * ((float) random () / RANDOM_MAX - 0.5);;
71 qa_atsci_fake_single_viterbi::t0 ()
74 unsigned char in[blocklen];
75 unsigned char enc[blocklen];
76 unsigned char out[blocklen];
77 int decoder_errors = 0;
78 int delay = decoder.delay ();
81 // printf (" Delay is %d.\n", delay);
83 srandom (27); // reproducable sequence of "random" values
85 for (int nt = 0; nt < NTRIALS; nt++){
87 // load block with random data and encode
89 for (i = 0; i < (blocklen-delay); i++)
90 in[i] = random () & MAXDIBIT;
91 for ( ; i < blocklen; i++)
92 in[i] = 0; /* To empty the delay buffers */
95 encode_block (enc, in, blocklen);
100 decode_block (out, enc, blocklen);
102 // int offset = delay/4;
104 bool differs = (memcmp (in+offset,
105 out+delay+offset, blocklen-(delay+offset)));
107 // initial values after reset are 0
108 for (i = 0; i < delay; i++){
110 printf (" initial output at %i is %X, not 0\n",
115 printf (" incorrect data, trial #%d\n", nt);
117 printf ("\n Erroneous result dibits:");
118 for (int erri = 0; erri < (NN-delay); erri++) {
119 if (in[erri] != out[erri+delay])
120 printf (" %d", erri);
123 for (int erri = 0; erri < (NN-delay); erri++) {
124 printf (" %d", in[erri]);
127 for (int erri = 0; erri < (NN-delay); erri++) {
128 printf (" %d", out[erri+delay]);
131 for (int erri = 0; erri < (NN-delay); erri++) {
132 printf (" %c", (in[erri] != out[erri+delay])? '*': ' ');
134 printf ("\n THIS IS A REAL PROBLEM.\n");
139 printf (" Summary: %d decoder errors out of %d trials.\n",
140 decoder_errors, NTRIALS);
142 CPPUNIT_ASSERT (decoder_errors == 0);