-/* RA encoder program; Bill, March 2016
- Using the elegant back substitution of RA LDPC codes.
- This version does not store the data in bytes! */
+/*
+ FILE...: ldpc_enc.c
+ AUTHOR.: Bill Cowley, David Rowe
+ CREATED: Sep 2016
+ RA LDPC encoder program. Using the elegant back substitution of RA
+ LDPC codes.
+*/
#include <stdio.h>
#include <stdlib.h>
-#define Nibits 2064
-#define Npbits 516
-#define Nwt 12
-
/* generated by ldpc_fsk_lib.m:ldpc_decode() */
#include "ldpc_code.h"
-unsigned char ibits[Nibits]; // info array
-unsigned char pbits[Npbits]; // parity array
-
-void encode() {
- unsigned int p, i, tmp, par, prev=0;
+void encode(unsigned char ibits[], unsigned char pbits[]) {
+ unsigned int p, i, tmp, par, prev=0;
int ind;
- for (p=0; p<Npbits; p++) {
+ for (p=0; p<NUMBERPARITYBITS; p++) {
par = 0;
- for (i=0; i<Nwt; i++) {
- ind = (int)H_rows[p + i*Npbits];
+ for (i=0; i<MAX_ROW_WEIGHT; i++) {
+ ind = (int)H_rows[p + i*NUMBERPARITYBITS];
par = par + ibits[ind-1];
}
int main(void)
{
- short k;
- unsigned int x;
+ unsigned char ibits[NUMBERROWSHCOLS];
+ unsigned char pbits[NUMBERPARITYBITS];
+ short k;
+ unsigned int x;
- printf("Test C Encoder\n");
+ printf("Test C Encoder\n");
- FILE *infp, *opfp;
- infp = fopen("dat_in2064.txt", "r"); // read info bits from file
- if (infp == NULL) {printf("Unable to open file.\n"); exit(1);}
+ FILE *infp, *opfp;
+ infp = fopen("dat_in2064.txt", "r"); // read info bits from file
+ if (infp == NULL) {printf("Unable to open file.\n"); exit(1);}
- for (k=0; k<Nibits; k++) {
- fscanf(infp, "%u\n", &x);
- ibits[k] = x;
+ for (k=0; k<NUMBERROWSHCOLS; k++) {
+ fscanf(infp, "%u\n", &x);
+ ibits[k] = x;
}
- fclose(infp);
+ fclose(infp);
- encode();
+ encode(ibits, pbits);
- opfp = fopen("dat_op2064.bin", "wb"); // write par bits to file
- if (opfp == NULL) {printf("Unable to output file.\n"); exit(1);}
- for (k=0; k<Nibits; k++)
- fwrite(&ibits[k], sizeof(char), 1, opfp);
- for (k=0; k<Npbits; k++)
- fwrite(&pbits[k], sizeof(char), 1, opfp);
- fclose(opfp);
+ opfp = fopen("dat_op2064.bin", "wb"); // write par bits to file
+ if (opfp == NULL) {printf("Unable to output file.\n"); exit(1);}
+ for (k=0; k<NUMBERROWSHCOLS; k++)
+ fwrite(&ibits[k], sizeof(char), 1, opfp);
+ for (k=0; k<NUMBERPARITYBITS; k++)
+ fwrite(&pbits[k], sizeof(char), 1, opfp);
+ fclose(opfp);
- return 1;
+ return 1;
}