Put original program back for reference. Added fixed codes.

This commit is contained in:
David E. Tiller 2022-03-21 19:38:02 -04:00
parent be0f9c4d2f
commit 475f951457
2 changed files with 10 additions and 95 deletions

View File

@ -514,12 +514,13 @@ void dump_bch(bch_t *bch) {
int main() int main()
{ {
int test[][8] = { 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, 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 */ { 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 */ /* 3 errors */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x6e, 0x84 }, /* 2nd in eotd_received_data - 3 bad bits */
/* fixed */ { 0xf0, 0x85, 0x50, 0x6a, 0x01, 0xe5, 0x06, 0x84 }, /* 2nd, but with the bits fixed */ /* 0 errors */ { 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, 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 */ { 0xf1, 0x34, 0x50, 0x1a, 0x01, 0xe5, 0x66, 0xfe }, /* 4th */
{ 0xf0, 0xeb, 0x10, 0xea, 0x01, 0x6e, 0x54, 0x1c }, /* 5th */ { 0xf0, 0xeb, 0x10, 0xea, 0x01, 0x6e, 0x54, 0x1c }, /* 5th */
{ 0xf0, 0xea, 0x5c, 0xea, 0x01, 0x6e, 0x55, 0x0e }, /* 6th */ { 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, 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, 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, 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 */ /* 3 errors */ { 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 */ /* 0 errors */ { 0x50, 0x8c, 0x12, 0x6a, 0x01, 0x64, 0x7a, 0xe8 }, /* Sun Mar 20 13:37:48 2022 with bits fixed */
}; };
int bits[63]; int bits[63];

View File

@ -72,7 +72,6 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
int m, n, length, k, t, d; int m, n, length, k, t, d;
int p[21]; int p[21];
@ -81,71 +80,6 @@ int recd[1048576], data[1048576], bb[548576];
int seed; int seed;
int numerr, errpos[1024], decerror = 0; 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=f0 1=81 2=52 3=6b 4=71 5=a5 6=63 7=08
{ 1,1,1,1,0,0,0,0,
1,0,0,0,0,0,0,1,
0,1,0,1,0,0,1,0,
0,1,1,0,1,0,1,1,
0,1,1,1,0,0,0,1,
1,0,1,0,0},
// 0=f0 1=85 2=50 3=6a 4=01 5=e5 6=6e 7=84
{ 1,1,1,1,0,0,0,0,
1,0,0,0,0,1,0,1,
0,1,0,1,0,0,0,0,
0,1,1,0,1,0,1,0,
0,0,0,0,0,0,0,1,
1,1,1,0,0},
// 0=f0 1=85 2=59 3=5a 4=01 5=e5 6=6e 7=84
{ 1,1,1,1,0,0,0,0,
1,0,0,0,0,1,0,1,
0,1,0,1,1,0,1,0,
0,0,0,0,0,0,0,1,
1,1,1,0,0},
// 0=f1 1=34 2=50 3=1a 4=01 5=e5 6=66 7=fe
{ 1,1,1,1,0,0,0,1,
0,0,1,1,0,1,0,0,
0,1,0,1,0,0,0,0,
0,0,0,1,1,0,1,0,
0,0,0,0,0,0,0,1,
1,1,1,0,0},
// 0=f0 1=eb 2=10 3=ea 4=01 5=6e 6=54 7=1c
{ 1,1,1,1,0,0,0,0,
1,1,1,0,1,0,1,1,
0,0,0,1,0,0,0,0,
1,1,1,0,1,0,1,0,
0,0,0,0,0,0,0,1,
0,1,1,0,1},
// 0=f0 1=ea 2=5c 3=ea 4=01 5=6e 6=55 7=0e
{ 1,1,1,1,0,0,0,0,
1,1,1,0,1,0,1,0,
0,1,0,1,1,1,0,0,
1,1,1,0,1,0,1,0,
0,0,0,0,0,0,0,1,
0,1,1,0,1},
};
int expected[][18] = {
{ 0,1,1, 0,0,1,1, 0,0,1,1, 1,1,0,1, 0,0,0 },
{ 1,0,1, 0,1,1,0, 0,0,1,1, 0,0,0,0, 1,0,0 },
//orig { 1,0,1, 0,1,1,0, 1,1,1,0, 1,0,0,0, 0,1,0 },
{ 1,0,1, 0,0,0,0, 0,1,1,0, 1,0,0,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 void
read_p() read_p()
@ -581,16 +515,12 @@ int main()
generate_gf(); /* Construct the Galois Field GF(2**m) */ generate_gf(); /* Construct the Galois Field GF(2**m) */
gen_poly(); /* Compute the generator polynomial of BCH code */ 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 */ /* Randomly generate DATA */
seed = 131073; seed = 131073;
srandom(seed); srandom(seed);
for (i = 0; i < k; i++) for (i = 0; i < k; i++)
data[i] = ( random() & 65536 ) >> 16; data[i] = ( random() & 65536 ) >> 16;
#endif
encode_bch(); /* encode data */ encode_bch(); /* encode data */
/* /*
@ -623,9 +553,8 @@ for (int count = 0; count < sizeof(real_data) / sizeof(*real_data); count++) {
printf("r(x) = "); printf("r(x) = ");
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
printf("%1d", recd[i]); printf("%1d", recd[i]);
if (i == length - k - 1) printf(" "); if (i && ((i % 50) == 0))
//if (i && ((i % 50) == 0)) printf("\n");
//printf("\n");
} }
printf("\n"); printf("\n");
@ -649,18 +578,6 @@ if (i == length - k - 1) printf(" ");
} }
printf("\n"); 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 * 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); printf("There were %d decoding errors in message positions\n", decerror);
else else
printf("Succesful decoding\n"); printf("Succesful decoding\n");
#ifdef TEST
}
#endif
} }