Skip to content

Commit 475f951

Browse files
committed
Put original program back for reference. Added fixed codes.
1 parent be0f9c4 commit 475f951

File tree

2 files changed

+10
-95
lines changed

2 files changed

+10
-95
lines changed

Diff for: src/bch.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -514,21 +514,22 @@ void dump_bch(bch_t *bch) {
514514
int main()
515515
{
516516
int test[][8] = {
517-
{ 0xb2, 0x17, 0xa2, 0xb9, 0x53, 0xdd, 0xc5, 0x52 }, /* perfect random test */
517+
/* 0 errors */ { 0xb2, 0x17, 0xa2, 0xb9, 0x53, 0xdd, 0xc5, 0x52 }, /* perfect random test */
518518
{ 0xf0, 0x5a, 0x6a, 0x6a, 0x01, 0x63, 0x33, 0xd0 }, /* g001-cut-lenthened_457.938M.wav */
519519
{ 0xf0, 0x81, 0x52, 0x6b, 0x71, 0xa5, 0x63, 0x08 }, /* 1st in eotd_received_data */
520-
/* 3 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x6e, 0x84 }, /* 2nd in eotd_received_data */
521-
/* fixed */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x06, 0x84 }, /* 2nd, but with the bits fixed */
522-
{ 0xf0, 0x85, 0x59, 0x5a, 0x01, 0xe5, 0x6e, 0x84 }, /* 3rd - 3 bad bits */
520+
/* 3 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x6e, 0x84 }, /* 2nd in eotd_received_data - 3 bad bits */
521+
/* 0 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x06, 0x84 }, /* 2nd, but with the bits fixed */
522+
/* 3 errors */ { 0xf0, 0x85, 0x59, 0x5a, 0x01, 0xe5, 0x6e, 0x84 }, /* 3rd - 3 bad bits */
523+
/* 0 errors */ { 0xb0, 0x85, 0x59, 0x5a, 0x11, 0xe5, 0x6f, 0x84 }, /* 3rd fixed */
523524
{ 0xf1, 0x34, 0x50, 0x1a, 0x01, 0xe5, 0x66, 0xfe }, /* 4th */
524525
{ 0xf0, 0xeb, 0x10, 0xea, 0x01, 0x6e, 0x54, 0x1c }, /* 5th */
525526
{ 0xf0, 0xea, 0x5c, 0xea, 0x01, 0x6e, 0x55, 0x0e }, /* 6th */
526527
{ 0xe0, 0x21, 0x10, 0x1a, 0x01, 0x32, 0xbc, 0xe4 }, /* Sun Mar 20 05:41:00 2022 */
527528
{ 0xf0, 0x42, 0x50, 0x5b, 0xcf, 0xd5, 0x64, 0xe4 }, /* Sun Mar 20 12:58:43 2022 */
528529
{ 0xf0, 0x8c, 0x10, 0xaa, 0x01, 0x73, 0x7b, 0x1a }, /* Sun Mar 20 13:35:48 2022 */
529530
{ 0xf0, 0x8c, 0x10, 0xb1, 0xc0, 0xe0, 0x90, 0x64 }, /* Sun Mar 20 13:37:05 2022 */
530-
{ 0xf0, 0x8c, 0x10, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 - 3 bad bits */
531-
{ 0x50, 0x8c, 0x12, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* above, with bits fixed */
531+
/* 3 errors */ { 0xf0, 0x8c, 0x10, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 - 3 bad bits */
532+
/* 0 errors */ { 0x50, 0x8c, 0x12, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 with bits fixed */
532533
};
533534

534535
int bits[63];

Diff for: src/bch3.c

+3-89
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
#include <math.h>
7373
#include <stdio.h>
7474
#include <stdlib.h>
75-
#include <string.h>
7675

7776
int m, n, length, k, t, d;
7877
int p[21];
@@ -81,71 +80,6 @@ int recd[1048576], data[1048576], bb[548576];
8180
int seed;
8281
int numerr, errpos[1024], decerror = 0;
8382

84-
int real_data[][45] = {
85-
{ 1,1,1,1,0,0,0,0,
86-
0,1,0,1,1,0,1,0,
87-
0,1,1,0,1,0,1,0,
88-
0,1,1,0,1,0,1,0,
89-
0,0,0,0,0,0,0,1,
90-
0,1,1,0,0},
91-
92-
// 0=f0 1=81 2=52 3=6b 4=71 5=a5 6=63 7=08
93-
{ 1,1,1,1,0,0,0,0,
94-
1,0,0,0,0,0,0,1,
95-
0,1,0,1,0,0,1,0,
96-
0,1,1,0,1,0,1,1,
97-
0,1,1,1,0,0,0,1,
98-
1,0,1,0,0},
99-
100-
// 0=f0 1=85 2=50 3=6a 4=01 5=e5 6=6e 7=84
101-
{ 1,1,1,1,0,0,0,0,
102-
1,0,0,0,0,1,0,1,
103-
0,1,0,1,0,0,0,0,
104-
0,1,1,0,1,0,1,0,
105-
0,0,0,0,0,0,0,1,
106-
1,1,1,0,0},
107-
108-
// 0=f0 1=85 2=59 3=5a 4=01 5=e5 6=6e 7=84
109-
{ 1,1,1,1,0,0,0,0,
110-
1,0,0,0,0,1,0,1,
111-
0,1,0,1,1,0,1,0,
112-
0,0,0,0,0,0,0,1,
113-
1,1,1,0,0},
114-
115-
// 0=f1 1=34 2=50 3=1a 4=01 5=e5 6=66 7=fe
116-
{ 1,1,1,1,0,0,0,1,
117-
0,0,1,1,0,1,0,0,
118-
0,1,0,1,0,0,0,0,
119-
0,0,0,1,1,0,1,0,
120-
0,0,0,0,0,0,0,1,
121-
1,1,1,0,0},
122-
// 0=f0 1=eb 2=10 3=ea 4=01 5=6e 6=54 7=1c
123-
{ 1,1,1,1,0,0,0,0,
124-
1,1,1,0,1,0,1,1,
125-
0,0,0,1,0,0,0,0,
126-
1,1,1,0,1,0,1,0,
127-
0,0,0,0,0,0,0,1,
128-
0,1,1,0,1},
129-
130-
// 0=f0 1=ea 2=5c 3=ea 4=01 5=6e 6=55 7=0e
131-
{ 1,1,1,1,0,0,0,0,
132-
1,1,1,0,1,0,1,0,
133-
0,1,0,1,1,1,0,0,
134-
1,1,1,0,1,0,1,0,
135-
0,0,0,0,0,0,0,1,
136-
0,1,1,0,1},
137-
};
138-
139-
int expected[][18] = {
140-
{ 0,1,1, 0,0,1,1, 0,0,1,1, 1,1,0,1, 0,0,0 },
141-
{ 1,0,1, 0,1,1,0, 0,0,1,1, 0,0,0,0, 1,0,0 },
142-
//orig { 1,0,1, 0,1,1,0, 1,1,1,0, 1,0,0,0, 0,1,0 },
143-
{ 1,0,1, 0,0,0,0, 0,1,1,0, 1,0,0,0, 0,1,0 }, // CORRECTED
144-
{ 1,0,1, 0,1,1,0, 1,1,1,0, 1,0,0,0, 0,1,0 },
145-
{ 1,0,1, 0,1,1,0, 0,1,1,0, 1,1,1,1, 1,1,1 },
146-
{ 1,1,0, 0,1,0,1, 0,1,0,0, 0,0,0,1, 1,1,0 },
147-
{ 1,1,0, 0,1,0,1, 0,1,0,1, 0,0,0,0, 1,1,1 },
148-
};
14983

15084
void
15185
read_p()
@@ -581,16 +515,12 @@ int main()
581515
generate_gf(); /* Construct the Galois Field GF(2**m) */
582516
gen_poly(); /* Compute the generator polynomial of BCH code */
583517

584-
#ifdef TEST
585-
for (int count = 0; count < sizeof(real_data) / sizeof(*real_data); count++) {
586-
memcpy(data, real_data[count], sizeof(*real_data));
587-
#else
588518
/* Randomly generate DATA */
589519
seed = 131073;
590520
srandom(seed);
591521
for (i = 0; i < k; i++)
592522
data[i] = ( random() & 65536 ) >> 16;
593-
#endif
523+
594524
encode_bch(); /* encode data */
595525

596526
/*
@@ -623,9 +553,8 @@ for (int count = 0; count < sizeof(real_data) / sizeof(*real_data); count++) {
623553
printf("r(x) = ");
624554
for (i = 0; i < length; i++) {
625555
printf("%1d", recd[i]);
626-
if (i == length - k - 1) printf(" ");
627-
//if (i && ((i % 50) == 0))
628-
//printf("\n");
556+
if (i && ((i % 50) == 0))
557+
printf("\n");
629558
}
630559
printf("\n");
631560

@@ -649,18 +578,6 @@ if (i == length - k - 1) printf(" ");
649578
}
650579
printf("\n");
651580

652-
int flag = 0;
653-
printf("n=%d, k=%d, length=%d\n", n, k, length);
654-
#ifdef TEST
655-
for (int jj = 0; jj < n - k; jj++) {
656-
if (expected[count][jj] != recd[jj]) {
657-
printf("bit %d: expected %d calc: %d\n", jj, expected[count][jj], recd[jj]);
658-
flag++;
659-
}
660-
}
661-
printf("%d ERRORS.\n", flag);
662-
#endif
663-
664581
/*
665582
* DECODING ERRORS? we compare only the data portion
666583
*/
@@ -671,7 +588,4 @@ printf("n=%d, k=%d, length=%d\n", n, k, length);
671588
printf("There were %d decoding errors in message positions\n", decerror);
672589
else
673590
printf("Succesful decoding\n");
674-
#ifdef TEST
675-
}
676-
#endif
677591
}

0 commit comments

Comments
 (0)