Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
b8e582a4
Commit
b8e582a4
authored
Feb 12, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update convolution code test: use command line arg to choose block type.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
ed535d1f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
14 deletions
+40
-14
testconvcode.cc
src/testconvcode.cc
+40
-14
No files found.
src/testconvcode.cc
View file @
b8e582a4
...
...
@@ -34,10 +34,36 @@ generate_error_vector (size_t n, int errors)
}
return
ev
;
}
static
bool
no_case_equal
(
const
string
&
s1
,
const
string
&
s2
)
{
if
(
s1
.
size
()
!=
s2
.
size
())
return
false
;
return
std
::
equal
(
s1
.
begin
(),
s1
.
end
(),
s2
.
begin
(),
[]
(
char
c1
,
char
c2
)
->
bool
{
return
tolower
(
c1
)
==
tolower
(
c2
);});
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
==
1
)
string
btype
=
(
argc
>
1
)
?
argv
[
1
]
:
""
;
ConvBlockType
block_type
;
if
(
no_case_equal
(
btype
,
"A"
))
block_type
=
ConvBlockType
::
a
;
else
if
(
no_case_equal
(
btype
,
"B"
))
block_type
=
ConvBlockType
::
b
;
else
if
(
no_case_equal
(
btype
,
"AB"
))
block_type
=
ConvBlockType
::
ab
;
else
{
printf
(
"first argument must be A, B, or AB
\n
"
);
return
1
;
}
if
(
argc
==
2
)
{
vector
<
int
>
in_bits
=
bit_str_to_vec
(
"80f12381"
);
...
...
@@ -46,16 +72,16 @@ main (int argc, char **argv)
printf
(
"%d"
,
b
);
printf
(
"
\n
"
);
vector
<
int
>
coded_bits
=
conv_encode
(
ConvBlockType
::
a
,
in_bits
);
vector
<
int
>
coded_bits
=
conv_encode
(
block_type
,
in_bits
);
printf
(
"coded vector (n=%zd): "
,
coded_bits
.
size
());
for
(
auto
b
:
coded_bits
)
printf
(
"%d"
,
b
);
printf
(
"
\n
"
);
printf
(
"coded hex: %s
\n
"
,
bit_vec_to_str
(
coded_bits
).
c_str
());
assert
(
coded_bits
.
size
()
==
conv_code_size
(
ConvBlockType
::
a
,
in_bits
.
size
()));
assert
(
coded_bits
.
size
()
==
conv_code_size
(
block_type
,
in_bits
.
size
()));
vector
<
int
>
decoded_bits
=
conv_decode_hard
(
ConvBlockType
::
a
,
coded_bits
);
vector
<
int
>
decoded_bits
=
conv_decode_hard
(
block_type
,
coded_bits
);
printf
(
"output vector (k=%zd): "
,
decoded_bits
.
size
());
for
(
auto
b
:
decoded_bits
)
printf
(
"%d"
,
b
);
...
...
@@ -68,9 +94,9 @@ main (int argc, char **argv)
errors
++
;
printf
(
"decoding errors: %d
\n
"
,
errors
);
}
if
(
argc
==
2
&&
string
(
argv
[
1
])
==
"error"
)
if
(
argc
==
3
&&
string
(
argv
[
2
])
==
"error"
)
{
size_t
max_bit_errors
=
conv_code_size
(
ConvBlockType
::
a
,
128
)
*
0.5
;
size_t
max_bit_errors
=
conv_code_size
(
block_type
,
128
)
*
0.5
;
for
(
size_t
bit_errors
=
0
;
bit_errors
<
max_bit_errors
;
bit_errors
++
)
{
...
...
@@ -84,14 +110,14 @@ main (int argc, char **argv)
while
(
in_bits
.
size
()
!=
128
)
in_bits
.
push_back
(
rand
()
&
1
);
vector
<
int
>
coded_bits
=
conv_encode
(
ConvBlockType
::
a
,
in_bits
);
vector
<
int
>
coded_bits
=
conv_encode
(
block_type
,
in_bits
);
coded_bit_count
=
coded_bits
.
size
();
vector
<
int
>
error_bits
=
generate_error_vector
(
coded_bits
.
size
(),
bit_errors
);
for
(
size_t
pos
=
0
;
pos
<
coded_bits
.
size
();
pos
++
)
coded_bits
[
pos
]
^=
error_bits
[
pos
];
vector
<
int
>
decoded_bits
=
conv_decode_hard
(
ConvBlockType
::
a
,
coded_bits
);
vector
<
int
>
decoded_bits
=
conv_decode_hard
(
block_type
,
coded_bits
);
assert
(
decoded_bits
.
size
()
==
128
);
...
...
@@ -105,7 +131,7 @@ main (int argc, char **argv)
printf
(
"%f %f
\n
"
,
(
100.0
*
bit_errors
)
/
coded_bit_count
,
(
100.0
*
bad_decode
)
/
test_size
);
}
}
if
(
argc
==
2
&&
string
(
argv
[
1
])
==
"soft-error"
)
if
(
argc
==
3
&&
string
(
argv
[
2
])
==
"soft-error"
)
{
for
(
double
stddev
=
0
;
stddev
<
1.5
;
stddev
+=
0.01
)
{
...
...
@@ -120,7 +146,7 @@ main (int argc, char **argv)
while
(
in_bits
.
size
()
!=
128
)
in_bits
.
push_back
(
rand
()
&
1
);
vector
<
int
>
coded_bits
=
conv_encode
(
ConvBlockType
::
a
,
in_bits
);
vector
<
int
>
coded_bits
=
conv_encode
(
block_type
,
in_bits
);
coded_bit_count
=
coded_bits
.
size
();
std
::
default_random_engine
generator
;
...
...
@@ -130,7 +156,7 @@ main (int argc, char **argv)
for
(
auto
b
:
coded_bits
)
recv_bits
.
push_back
(
b
+
dist
(
generator
));
vector
<
int
>
decoded_bits1
=
conv_decode_soft
(
ConvBlockType
::
a
,
recv_bits
);
vector
<
int
>
decoded_bits1
=
conv_decode_soft
(
block_type
,
recv_bits
);
vector
<
int
>
recv_hard_bits
;
for
(
auto
b
:
recv_bits
)
...
...
@@ -139,7 +165,7 @@ main (int argc, char **argv)
for
(
size_t
x
=
0
;
x
<
recv_hard_bits
.
size
();
x
++
)
local_be
+=
coded_bits
[
x
]
^
recv_hard_bits
[
x
];
vector
<
int
>
decoded_bits2
=
conv_decode_hard
(
ConvBlockType
::
a
,
recv_hard_bits
);
vector
<
int
>
decoded_bits2
=
conv_decode_hard
(
block_type
,
recv_hard_bits
);
assert
(
decoded_bits1
.
size
()
==
128
);
assert
(
decoded_bits2
.
size
()
==
128
);
...
...
@@ -161,7 +187,7 @@ main (int argc, char **argv)
printf
(
"%f %f %f
\n
"
,
double
(
100
*
local_be
)
/
test_size
/
coded_bit_count
,
(
100.0
*
bad_decode1
)
/
test_size
,
(
100.0
*
bad_decode2
)
/
test_size
);
}
}
if
(
argc
==
2
&&
string
(
argv
[
1
])
==
"perf"
)
if
(
argc
==
3
&&
string
(
argv
[
2
])
==
"perf"
)
{
vector
<
int
>
in_bits
;
while
(
in_bits
.
size
()
!=
128
)
...
...
@@ -171,7 +197,7 @@ main (int argc, char **argv)
const
size_t
runs
=
20
;
for
(
size_t
i
=
0
;
i
<
runs
;
i
++
)
{
vector
<
int
>
out_bits
=
conv_decode_hard
(
ConvBlockType
::
a
,
conv_encode
(
ConvBlockType
::
a
,
in_bits
));
vector
<
int
>
out_bits
=
conv_decode_hard
(
block_type
,
conv_encode
(
block_type
,
in_bits
));
assert
(
out_bits
==
in_bits
);
}
printf
(
"%.1f ms/block
\n
"
,
(
gettime
()
-
start_t
)
/
runs
*
1000.0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment