1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/* -*- c++ -*- */
/*
* Copyright 2002 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <qa_atsci_equalizer_nop.h>
#include <atsci_equalizer.h>
#include <atsci_equalizer_nop.h>
#include <atsci_pnXXX.h>
#include <atsc_types.h>
#include <cppunit/TestAssert.h>
#include <assert.h>
#include <iostream>
#include <string.h>
using std::cerr;
using std::endl;
static const int SYMBOLS_PER_FIELD = (ATSC_DSEGS_PER_FIELD + 1) * ATSC_DATA_SEGMENT_LENGTH;
static const int PAD = 500;
static const int NFIELDS = 2;
static const int INPUT_SIZE = PAD + (NFIELDS * SYMBOLS_PER_FIELD);
static float
bin_map (int bit)
{
return bit ? +5 : -5;
}
static void
init_tags (atsc::syminfo *tags, int segnum, int fieldnum)
{
int i;
for (i = 0; i < ATSC_DATA_SEGMENT_LENGTH; i++){
tags[i].symbol_num = i;
tags[i].segment_num = segnum;
tags[i].field_num = fieldnum;
tags[i].valid = 1;
}
}
static void
init_data_seg (float *p, atsc::syminfo *tags, int v, int segnum, int fieldnum)
{
init_tags (tags, segnum, fieldnum);
int i = 0;
p[i++] = bin_map (1); // data segment sync pulse
p[i++] = bin_map (0);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
for (; i < ATSC_DATA_SEGMENT_LENGTH; i++)
p[i] = (float) (i + v);
}
static void
init_field_sync_tags (atsc::syminfo *tags, int fieldnum)
{
init_tags (tags, atsc::SI_FIELD_SYNC_SEGMENT_NUM, fieldnum);
}
static void
init_field_sync_common (float *p, int mask)
{
int i = 0;
p[i++] = bin_map (1); // data segment sync pulse
p[i++] = bin_map (0);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
for (int j = 0; j < 511; j++) // PN511
p[i++] = bin_map (atsc_pn511[j]);
for (int j = 0; j < 63; j++) // PN63
p[i++] = bin_map (atsc_pn63[j]);
for (int j = 0; j < 63; j++) // PN63, toggled on field 2
p[i++] = bin_map (atsc_pn63[j] ^ mask);
for (int j = 0; j < 63; j++) // PN63
p[i++] = bin_map (atsc_pn63[j]);
p[i++] = bin_map (0); // 24 bits of VSB8 mode identifiera
p[i++] = bin_map (0);
p[i++] = bin_map (0);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (1);
p[i++] = bin_map (1);
p[i++] = bin_map (1);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
p[i++] = bin_map (1);
p[i++] = bin_map (0);
for (int j = 0; j < 92; j++) // 92 more bits
p[i++] = bin_map (atsc_pn63[j % 63]);
// now copy the last 12 symbols of the previous segment
// bogus fill
for (int j = 0; j < 12; j++)
p[i++] = bin_map (j & 1);
assert (i == ATSC_DATA_SEGMENT_LENGTH);
}
void
qa_atsci_equalizer_nop::setUp ()
{
eq = new atsci_equalizer_nop ();
}
void
qa_atsci_equalizer_nop::tearDown ()
{
delete eq;
eq = 0;
}
static void
setup_test_data (float *data, atsc::syminfo *tags)
{
int mask = 0;
int i = 0;
for (i = 0; i < PAD; i++){
data[i] = (float) i;
tags[i].symbol_num = 13 + i;
tags[i].segment_num = 17;
tags[i].field_num = 0;
tags[i].valid = 1;
}
for (int nfields = 0; nfields < NFIELDS; nfields++){
init_field_sync_common (&data[i], mask);
init_field_sync_tags (&tags[i], mask);
i += ATSC_DATA_SEGMENT_LENGTH;
for (int segnum = 0; segnum < 312; segnum++){
init_data_seg (&data[i], &tags[i], i, segnum, mask);
i += ATSC_DATA_SEGMENT_LENGTH;
}
mask ^= 1;
}
assert (i == INPUT_SIZE);
}
void
qa_atsci_equalizer_nop::t0 ()
{
// these are dynamically allocated because they are bigger
// than the default stack limit.
float *input_data = new float[INPUT_SIZE];
atsc::syminfo *input_tags = new atsc::syminfo[INPUT_SIZE];
float *output_data = new float[INPUT_SIZE];
try {
memset (input_data, 0, sizeof (input_data));
memset (input_tags, 0, sizeof (input_tags));
memset (output_data, 0, sizeof (output_data));
setup_test_data (input_data, input_tags);
eq->filter (input_data, input_tags,
output_data, INPUT_SIZE);
// now check that data values got copied correctly
for (int i = 0; i < INPUT_SIZE; i++){
if (input_tags[i].segment_num == atsc::SI_FIELD_SYNC_SEGMENT_NUM){
// ignore entire field sync data segment
}
else if (input_tags[i].symbol_num <= 3){
// ignore 4 symbols of data segment sync (+5, -5, -5, +5)
}
else {
if (output_data[i] != (float) i){
cerr << "output_data[" << i << "] == " << output_data[i] << endl;
CPPUNIT_ASSERT_DOUBLES_EQUAL ((float) i, output_data[i], 1e-6);
}
}
}
delete [] input_data;
delete [] input_tags;
delete [] output_data;
}
catch ( ... ){
delete [] input_data;
delete [] input_tags;
delete [] output_data;
}
}
void
qa_atsci_equalizer_nop::t1 ()
{
// think of another test...
}
|