Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: barak/LDPC-codes
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: piql/LDPC-codes
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 50 files changed
  • 1 contributor

Commits on Jan 30, 2025

  1. Copy the full SHA
    c231b41 View commit details
Showing with 767 additions and 757 deletions.
  1. +2 −1 Makefile
  2. +4 −2 alist-to-pchk.c
  3. +13 −25 channel.c
  4. +2 −9 channel.h
  5. +0 −1 check.c
  6. +48 −48 dec.c
  7. +5 −14 dec.h
  8. +50 −32 decode.c
  9. +31 −33 enc.c
  10. +3 −3 enc.h
  11. +29 −24 encode.c
  12. +28 −28 ex-dep
  13. +28 −28 ex-dep-out
  14. +9 −9 ex-ham7a
  15. +9 −9 ex-ham7a-out
  16. +8 −8 ex-ham7b
  17. +8 −8 ex-ham7b-out
  18. +15 −15 ex-ldpc-encode
  19. +15 −15 ex-ldpc-encode-out
  20. +16 −16 ex-ldpc36-1000a
  21. +16 −16 ex-ldpc36-1000a-out
  22. +19 −19 ex-ldpc36-5000a
  23. +19 −19 ex-ldpc36-5000a-out
  24. +19 −19 ex-ldpcvar-5000a
  25. +19 −19 ex-ldpcvar-5000a-out
  26. +42 −42 ex-wrong-model
  27. +43 −43 ex-wrong-model-out
  28. +8 −7 extract.c
  29. +6 −7 extract_systematic.c
  30. +0 −1 intio.c
  31. +71 −61 make-gen.c
  32. +32 −25 make-ldpc.c
  33. +5 −4 make-pchk.c
  34. +0 −1 mod2convert-test.c
  35. +0 −1 mod2convert.c
  36. +0 −1 mod2dense-test.c
  37. +3 −1 mod2dense.c
  38. +0 −1 mod2sparse-test.c
  39. +5 −1 mod2sparse.c
  40. +18 −17 pchk-to-alist.c
  41. +20 −22 print-gen.c
  42. +7 −8 print-pchk.c
  43. +1 −1 rand-src.c
  44. +2 −1 rand-test.c
  45. +0 −4 rand.c
  46. +34 −54 rcode.c
  47. +31 −11 rcode.h
  48. +1 −1 run-examples
  49. +6 −6 transmit.c
  50. +17 −16 verify.c
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -30,9 +30,10 @@ tests = mod2dense-test mod2sparse-test mod2convert-test rand-test

tests: $(tests)

CFLAGS += -Wall -Wno-maybe-uninitialized
CFLAGS += -Wall -Wextra -Wpedantic -Wmissing-prototypes
CFLAGS += -O2
CFLAGS += -g
CFLAGS += -std=c99
LOADLIBES += -lm

ofiles = alloc.o blockio.o channel.o check.o dec.o distrib.o enc.o \
6 changes: 4 additions & 2 deletions alist-to-pchk.c
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "alloc.h"
#include "intio.h"
#include "open.h"
#include "mod2sparse.h"
#include "mod2dense.h"
#include "mod2convert.h"
#include "rcode.h"


@@ -46,6 +44,10 @@ int main
int tot, trans;
int nxt;

mod2sparse *H;
int M;
int N;

trans = 0;

for (;;)
38 changes: 13 additions & 25 deletions channel.c
Original file line number Diff line number Diff line change
@@ -14,36 +14,24 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "channel.h"


/* GLOBAL VARIABLES. Declared in channel.h. */

channel_type channel; /* Type of channel */

double error_prob; /* Error probability for BSC */
double std_dev; /* Noise standard deviation for AWGN */
double lwidth; /* Width of noise distribution for AWLN */


/* PARSE A COMMAND-LINE SPECIFICATION OF A CHANNEL. Takes a pointer to an
argument list and an argument count; returns the number of arguments that
make up a channel specification at this point in the command line. Returns
zero if the argument list does not start with a channel specification.
Returns -1 if there seems to be a channel specification here, but it's
invalid.
Sets the variables declared in channel.h to the type and parameters of
the channel.
*/

int channel_parse
( char **argv, /* Pointer to argument list */
int argc /* Number of arguments in list */
int argc, /* Number of arguments in list */
channel_type *channel, /* (output parameter) Type of channel */
double *channel_data /* (output parameter) BSC: Error probability, AWGN: Noise standard deviation, AWLN: Width of noise distribution */
)
{
char junk;
@@ -52,9 +40,9 @@ int channel_parse

if (strcmp(argv[0],"bsc")==0 || strcmp(argv[0],"BSC")==0)
{
channel = BSC;
if (argc<2 || sscanf(argv[1],"%lf%c",&error_prob,&junk)!=1
|| error_prob<=0 || error_prob>=1)
*channel = BSC;
if (argc<2 || sscanf(argv[1],"%lf%c",channel_data,&junk)!=1
|| *channel_data<=0 || *channel_data>=1)
{ return -1;
}
else
@@ -63,9 +51,9 @@ int channel_parse
}
else if (strcmp(argv[0],"awgn")==0 || strcmp(argv[0],"AWGN")==0)
{
channel = AWGN;
if (argc<2 || sscanf(argv[1],"%lf%c",&std_dev,&junk)!=1
|| std_dev<=0)
*channel = AWGN;
if (argc<2 || sscanf(argv[1],"%lf%c",channel_data,&junk)!=1
|| *channel_data<=0)
{ return -1;
}
else
@@ -74,9 +62,9 @@ int channel_parse
}
else if (strcmp(argv[0],"awln")==0 || strcmp(argv[0],"AWLN")==0)
{
channel = AWLN;
if (argc<2 || sscanf(argv[1],"%lf%c",&lwidth,&junk)!=1
|| lwidth<=0)
*channel = AWLN;
if (argc<2 || sscanf(argv[1],"%lf%c",channel_data,&junk)!=1
|| *channel_data<=0)
{ return -1;
}
else
@@ -85,7 +73,7 @@ int channel_parse
}
else if (strcmp(argv[0],"misc")==0 || strcmp(argv[0],"MISC")==0)
{
channel = MISC;
*channel = MISC;
return 2;
}
else
11 changes: 2 additions & 9 deletions channel.h
Original file line number Diff line number Diff line change
@@ -14,19 +14,12 @@
*/


/* TYPES OF CHANNEL, AND CHANNEL PARAMETERS. The global variables declared
here are located in channel.c. */
/* TYPES OF CHANNEL */

typedef enum { BSC, AWGN, AWLN , MISC} channel_type;

extern channel_type channel; /* Type of channel */

extern double error_prob; /* Error probability for BSC */
extern double std_dev; /* Noise standard deviation for AWGN */
extern double lwidth; /* Width of noise distributoin for AWLN */


/* PROCEDURES TO DO WITH CHANNELS. */

int channel_parse (char **, int);
int channel_parse (char **, int, channel_type *channel, double *channel_data);
void channel_usage (void);
1 change: 0 additions & 1 deletion check.c
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
* risk.
*/

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

96 changes: 48 additions & 48 deletions dec.c
Original file line number Diff line number Diff line change
@@ -24,25 +24,12 @@
#include "alloc.h"
#include "mod2sparse.h"
#include "mod2dense.h"
#include "mod2convert.h"
#include "rand.h"
#include "rcode.h"
#include "check.h"
#include "dec.h"
#include "enc.h"


/* GLOBAL VARIABLES. Declared in dec.h. */

decoding_method dec_method; /* Decoding method to use */

int table; /* Trace option, 2 for a table of decoding details */
int block_no; /* Number of current block, from zero */

int max_iter; /* Maximum number of iteratons of decoding to do */
char *gen_file; /* Generator file for Enum_block and Enum_bit */


/* DECODE BY EXHAUSTIVE ENUMERATION. Decodes by trying all possible source
messages (and hence all possible codewords, unless the parity check matrix
was redundant). If the last argument is 1, it sets dblk to the most likely
@@ -54,22 +41,23 @@ char *gen_file; /* Generator file for Enum_block and Enum_bit */
will be the same for all blocks). The return valued is "unsigned" because
it might conceivably be as big as 2^31.
The parity check matrix and other data are taken from the global variables
declared in rcode.h.
The number of message bits should not be greater than 31 for this procedure.
The setup procedure immediately below checks this, reads the generator file,
and outputs headers for the detailed trace file, if required.
*/

void enum_decode_setup(void)
void enum_decode_setup(
gen_matrix *gm,
int table, /* Trace option, 2 for a table of decoding details */
char *gen_file /* Generator file for Enum_block and Enum_bit */
)
{
read_gen(gen_file,0,0);
read_gen(gen_file,0,0, gm);

if (N-M>31)
if (gm->dim.N-gm->dim.M>31)
{ fprintf(stderr,
"Trying to decode messages with %d bits by exhaustive enumeration is absurd!\n",
N-M);
gm->dim.N-gm->dim.M);
exit(1);
}

@@ -82,7 +70,11 @@ unsigned enum_decode
( double *lratio, /* Likelihood ratios for bits */
char *dblk, /* Place to stored decoded message */
double *bitpr, /* Place to store marginal bit probabilities */
int max_block /* Maximize probability of whole block being correct? */
int max_block, /* Maximize probability of whole block being correct? */
mod2sparse *H, /* Parity check matrix */
gen_matrix *gm, /* Generator matrix */
int table, /* Trace option, 2 for a table of decoding details */
int block_no /* Number of current block, from zero */
)
{
mod2dense *u, *v;
@@ -93,84 +85,89 @@ unsigned enum_decode
unsigned d;
int i, j;

if (N-M>31) abort();
if (gm->dim.N-gm->dim.M>31) abort();

/* Allocate needed space. */

bpr = bitpr;
if (bpr==0 && max_block==0)
{ bpr = chk_alloc (N, sizeof *bpr);
{ bpr = chk_alloc (gm->dim.N, sizeof *bpr);
}

cblk = chk_alloc (N, sizeof *cblk);
cblk = chk_alloc (gm->dim.N, sizeof *cblk);

if (type=='d')
{ u = mod2dense_allocate(N-M,1);
v = mod2dense_allocate(M,1);
if (gm->type=='d')
{ u = mod2dense_allocate(gm->dim.N-gm->dim.M,1);
v = mod2dense_allocate(gm->dim.M,1);
}

if (type=='m')
{ u = mod2dense_allocate(M,1);
v = mod2dense_allocate(M,1);
else if (gm->type=='m')
{ u = mod2dense_allocate(gm->dim.M,1);
v = mod2dense_allocate(gm->dim.M,1);
}

else
{ u = NULL;
v = NULL;
}

lk0 = chk_alloc (N, sizeof *lk0);
lk1 = chk_alloc (N, sizeof *lk1);
lk0 = chk_alloc (gm->dim.N, sizeof *lk0);
lk1 = chk_alloc (gm->dim.N, sizeof *lk1);

/* Pre-compute likelihoods for bits. */

for (j = 0; j<N; j++)
for (j = 0; j<gm->dim.N; j++)
{ lk0[j] = 1/(1+lratio[j]);
lk1[j] = 1 - lk0[j];
}

/* Initialize marginal bit probabilities. */

if (bpr)
{ for (j = 0; j<N; j++) bpr[j] = 0.0;
{ for (j = 0; j<gm->dim.N; j++) bpr[j] = 0.0;
}

/* Exhaustively try all possible decoded messages. */

tpr = 0.0;

for (d = 0; d<=(1u<<(N-M))-1; d++)
for (d = 0; d<=(1u<<(gm->dim.N-gm->dim.M))-1; d++)
{
/* Unpack message into source block. */

for (i = N-M-1; i>=0; i--)
for (i = gm->dim.N-gm->dim.M-1; i>=0; i--)
{ sblk[i] = (d>>i)&1;
}

/* Find full codeword for this message. */

switch (type)
switch (gm->type)
{ case 's':
{ sparse_encode (sblk, cblk);
{ sparse_encode (sblk, cblk, H, gm);
break;
}
case 'd':
{ dense_encode (sblk, cblk, u, v);
{ dense_encode (sblk, cblk, u, v, gm);
break;
}
case 'm':
{ mixed_encode (sblk, cblk, u, v);
{ mixed_encode (sblk, cblk, u, v, H, gm);
break;
}
}

/* Compute likelihood for this decoding. */

lk = 1;
for (j = 0; j<N; j++)
for (j = 0; j<gm->dim.N; j++)
{ lk *= cblk[j]==0 ? lk0[j] : lk1[j];
}

/* Update maximum likelihood decoding. */

if (max_block)
{ if (d==0 || lk>maxlk)
{ for (j = 0; j<N; j++)
{ for (j = 0; j<gm->dim.N; j++)
{ dblk[j] = cblk[j];
}
maxlk = lk;
@@ -180,7 +177,7 @@ unsigned enum_decode
/* Update bit probabilities. */

if (bpr)
{ for (j = 0; j<N; j++)
{ for (j = 0; j<gm->dim.N; j++)
{ if (cblk[j]==1)
{ bpr[j] += lk;
}
@@ -198,14 +195,14 @@ unsigned enum_decode
/* Normalize bit probabilities. */

if (bpr)
{ for (j = 0; j<N; j++) bpr[j] /= tpr;
{ for (j = 0; j<gm->dim.N; j++) bpr[j] /= tpr;
}

/* Decoding to maximize bit-by-bit success, if that's what's wanted.
In case of a tie, decode to a 1. */

if (!max_block)
{ for (j = 0; j<N; j++)
{ for (j = 0; j<gm->dim.N; j++)
{ dblk[j] = bpr[j]>=0.5;
}
}
@@ -217,7 +214,7 @@ unsigned enum_decode
free(lk0);
free(lk1);

return 1<<(N-M);
return 1<<(gm->dim.N-gm->dim.M);
}


@@ -240,7 +237,7 @@ unsigned enum_decode
file, if required.
*/

void prprp_decode_setup (void)
void prprp_decode_setup (int table)
{
if (table==2)
{ printf(
@@ -253,7 +250,10 @@ unsigned prprp_decode
double *lratio, /* Likelihood ratios for bits */
char *dblk, /* Place to store decoding */
char *pchk, /* Place to store parity checks */
double *bprb /* Place to store bit probabilities */
double *bprb, /* Place to store bit probabilities */
int table, /* Trace option, 2 for a table of decoding details */
int block_no, /* Number of current block, from zero */
int max_iter /* Maximum number of iterations of decoding to do */
)
{
int N, n, c;
Loading