From 475f951457d2f264a67c78f78705a281abbb5b60 Mon Sep 17 00:00:00 2001 From: "David E. Tiller" <3858971+dtiller@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:38:02 -0400 Subject: [PATCH] Put original program back for reference. Added fixed codes. --- src/bch.c | 13 ++++---- src/bch3.c | 92 ++---------------------------------------------------- 2 files changed, 10 insertions(+), 95 deletions(-) diff --git a/src/bch.c b/src/bch.c index 1769183..3293c63 100644 --- a/src/bch.c +++ b/src/bch.c @@ -514,12 +514,13 @@ void dump_bch(bch_t *bch) { int main() { int test[][8] = { - { 0xb2, 0x17, 0xa2, 0xb9, 0x53, 0xdd, 0xc5, 0x52 }, /* perfect random test */ +/* 0 errors */ { 0xb2, 0x17, 0xa2, 0xb9, 0x53, 0xdd, 0xc5, 0x52 }, /* perfect random test */ { 0xf0, 0x5a, 0x6a, 0x6a, 0x01, 0x63, 0x33, 0xd0 }, /* g001-cut-lenthened_457.938M.wav */ { 0xf0, 0x81, 0x52, 0x6b, 0x71, 0xa5, 0x63, 0x08 }, /* 1st in eotd_received_data */ -/* 3 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x6e, 0x84 }, /* 2nd in eotd_received_data */ -/* fixed */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x06, 0x84 }, /* 2nd, but with the bits fixed */ - { 0xf0, 0x85, 0x59, 0x5a, 0x01, 0xe5, 0x6e, 0x84 }, /* 3rd - 3 bad bits */ +/* 3 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x6e, 0x84 }, /* 2nd in eotd_received_data - 3 bad bits */ +/* 0 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x06, 0x84 }, /* 2nd, but with the bits fixed */ +/* 3 errors */ { 0xf0, 0x85, 0x59, 0x5a, 0x01, 0xe5, 0x6e, 0x84 }, /* 3rd - 3 bad bits */ +/* 0 errors */ { 0xb0, 0x85, 0x59, 0x5a, 0x11, 0xe5, 0x6f, 0x84 }, /* 3rd fixed */ { 0xf1, 0x34, 0x50, 0x1a, 0x01, 0xe5, 0x66, 0xfe }, /* 4th */ { 0xf0, 0xeb, 0x10, 0xea, 0x01, 0x6e, 0x54, 0x1c }, /* 5th */ { 0xf0, 0xea, 0x5c, 0xea, 0x01, 0x6e, 0x55, 0x0e }, /* 6th */ @@ -527,8 +528,8 @@ int main() { 0xf0, 0x42, 0x50, 0x5b, 0xcf, 0xd5, 0x64, 0xe4 }, /* Sun Mar 20 12:58:43 2022 */ { 0xf0, 0x8c, 0x10, 0xaa, 0x01, 0x73, 0x7b, 0x1a }, /* Sun Mar 20 13:35:48 2022 */ { 0xf0, 0x8c, 0x10, 0xb1, 0xc0, 0xe0, 0x90, 0x64 }, /* Sun Mar 20 13:37:05 2022 */ - { 0xf0, 0x8c, 0x10, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 - 3 bad bits */ - { 0x50, 0x8c, 0x12, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* above, with bits fixed */ +/* 3 errors */ { 0xf0, 0x8c, 0x10, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 - 3 bad bits */ +/* 0 errors */ { 0x50, 0x8c, 0x12, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 with bits fixed */ }; int bits[63]; diff --git a/src/bch3.c b/src/bch3.c index 87d7da0..2f13e6e 100644 --- a/src/bch3.c +++ b/src/bch3.c @@ -72,7 +72,6 @@ #include #include #include -#include int m, n, length, k, t, d; int p[21]; @@ -81,71 +80,6 @@ int recd[1048576], data[1048576], bb[548576]; int seed; int numerr, errpos[1024], decerror = 0; -int real_data[][45] = { - { 1,1,1,1,0,0,0,0, - 0,1,0,1,1,0,1,0, - 0,1,1,0,1,0,1,0, - 0,1,1,0,1,0,1,0, - 0,0,0,0,0,0,0,1, - 0,1,1,0,0}, - -// 0=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0, 0,1,0 }, // CORRECTED - { 1,0,1, 0,1,1,0, 1,1,1,0, 1,0,0,0, 0,1,0 }, - { 1,0,1, 0,1,1,0, 0,1,1,0, 1,1,1,1, 1,1,1 }, - { 1,1,0, 0,1,0,1, 0,1,0,0, 0,0,0,1, 1,1,0 }, - { 1,1,0, 0,1,0,1, 0,1,0,1, 0,0,0,0, 1,1,1 }, -}; void read_p() @@ -581,16 +515,12 @@ int main() generate_gf(); /* Construct the Galois Field GF(2**m) */ gen_poly(); /* Compute the generator polynomial of BCH code */ -#ifdef TEST -for (int count = 0; count < sizeof(real_data) / sizeof(*real_data); count++) { - memcpy(data, real_data[count], sizeof(*real_data)); -#else /* Randomly generate DATA */ seed = 131073; srandom(seed); for (i = 0; i < k; i++) data[i] = ( random() & 65536 ) >> 16; -#endif + encode_bch(); /* encode data */ /* @@ -623,9 +553,8 @@ for (int count = 0; count < sizeof(real_data) / sizeof(*real_data); count++) { printf("r(x) = "); for (i = 0; i < length; i++) { printf("%1d", recd[i]); -if (i == length - k - 1) printf(" "); - //if (i && ((i % 50) == 0)) - //printf("\n"); + if (i && ((i % 50) == 0)) + printf("\n"); } printf("\n"); @@ -649,18 +578,6 @@ if (i == length - k - 1) printf(" "); } printf("\n"); - int flag = 0; -printf("n=%d, k=%d, length=%d\n", n, k, length); -#ifdef TEST - for (int jj = 0; jj < n - k; jj++) { - if (expected[count][jj] != recd[jj]) { - printf("bit %d: expected %d calc: %d\n", jj, expected[count][jj], recd[jj]); - flag++; - } - } - printf("%d ERRORS.\n", flag); -#endif - /* * DECODING ERRORS? we compare only the data portion */ @@ -671,7 +588,4 @@ printf("n=%d, k=%d, length=%d\n", n, k, length); printf("There were %d decoding errors in message positions\n", decerror); else printf("Succesful decoding\n"); -#ifdef TEST - } -#endif }