/*---------------------------------------------------------------------------*\
FILE........: interldpc.c
AUTHOR......: David Rowe
DATE CREATED: April 2018
Helper functions for interleaved LDPC waveforms.
\*---------------------------------------------------------------------------*/
/*
Copyright (C) 2018 David Rowe
All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 2.1, as
published by the Free Software Foundation. This program is
distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
#include
#include
#include
#include
#include
//#include
#include "interldpc.h"
#include "codec2_ofdm.h"
#include "mpdecode_core.h"
#include "gp_interleaver.h"
#include "HRA_112_112.h"
#include "test_bits_ofdm.h"
/* CRC type function, used to compare QPSK vectors when debugging */
COMP test_acc(COMP v[], int n) {
COMP acc = {0.0,0.0};
int i;
for(i=0; imax_iter = HRA_112_112_MAX_ITER;
ldpc->dec_type = 0;
ldpc->q_scale_factor = 1;
ldpc->r_scale_factor = 1;
ldpc->CodeLength = HRA_112_112_CODELENGTH;
ldpc->NumberParityBits = HRA_112_112_NUMBERPARITYBITS;
ldpc->NumberRowsHcols = HRA_112_112_NUMBERROWSHCOLS;
ldpc->max_row_weight = HRA_112_112_MAX_ROW_WEIGHT;
ldpc->max_col_weight = HRA_112_112_MAX_COL_WEIGHT;
ldpc->H_rows = HRA_112_112_H_rows;
ldpc->H_cols = HRA_112_112_H_cols;
/* provided for convenience and to match Octave vaiable names */
ldpc->data_bits_per_frame = HRA_112_112_CODELENGTH - HRA_112_112_NUMBERPARITYBITS;
ldpc->coded_bits_per_frame = HRA_112_112_CODELENGTH;
ldpc->coded_syms_per_frame = ldpc->coded_bits_per_frame/OFDM_BPS;
}
void ldpc_encode_frame(struct LDPC *ldpc, int codeword[], unsigned char tx_bits_char[]) {
unsigned char pbits[ldpc->NumberParityBits];
int i,j;
encode(ldpc, tx_bits_char, pbits);
for(i=0; idata_bits_per_frame; i++) {
codeword[i] = tx_bits_char[i];
}
for(j=0; icoded_bits_per_frame; i++,j++) {
codeword[i] = pbits[j];
}
}
void qpsk_modulate_frame(COMP tx_symbols[], int codeword[], int n) {
int s,i;
int dibit[2];
complex float qpsk_symb;
for(s=0,i=0; icoded_syms_per_frame;
int coded_bits_per_frame = ldpc->coded_bits_per_frame;
int data_bits_per_frame = ldpc->data_bits_per_frame;
double llr[coded_bits_per_frame];
char out_char[coded_bits_per_frame];
char next_sync_state_interleaver[OFDM_STATE_STR];
strcpy(next_sync_state_interleaver, ofdm->sync_state_interleaver);
if ((strcmp(ofdm->sync_state_interleaver,"search") == 0) && (ofdm->frame_count >= (interleave_frames-1))) {
symbols_to_llrs(llr, codeword_symbols_de, codeword_amps_de, EsNo, ofdm->mean_amp, coded_syms_per_frame);
iter[0] = run_ldpc_decoder(ldpc, out_char, llr, parityCheckCount);
Nerrs_coded[0] = data_bits_per_frame - parityCheckCount[0];
//for(i=0; i<20; i++)
// fprintf(stderr,"%d ", out_char[i]);
//fprintf(stderr,"\n");
//fprintf(stderr, " iter: %d pcc: %d Nerrs: %d\n", iter[0], parityCheckCount[0], Nerrs_coded[0]);
if ((Nerrs_coded[0] == 0) || (interleave_frames == 1)) {
/* sucessful decode! */
strcpy(next_sync_state_interleaver, "synced");
ofdm->frame_count_interleaver = interleave_frames;
}
}
strcpy(ofdm->sync_state_interleaver, next_sync_state_interleaver);
}
/* measure uncoded (raw) bit errors over interleaver frame */
int count_uncoded_errors(struct LDPC *ldpc, int Nerrs_raw[], int interleave_frames, COMP codeword_symbols_de[])
{
int i,j,Nerrs,Terrs;
int coded_syms_per_frame = ldpc->coded_syms_per_frame;
int coded_bits_per_frame = ldpc->coded_bits_per_frame;
int rx_bits_raw[coded_bits_per_frame];
assert(sizeof(test_codeword)/sizeof(int) == coded_bits_per_frame);
Terrs = 0;
for (j=0; jtx_uw[i];
}
/* clear txt bits for now, they can be added in later */
for(j=0; jcoded_syms_per_frame;
int coded_bits_per_frame = ldpc->coded_bits_per_frame;
int data_bits_per_frame = ldpc->data_bits_per_frame;
int codeword[coded_bits_per_frame];
COMP coded_symbols[interleave_frames*coded_syms_per_frame];
COMP coded_symbols_inter[interleave_frames*coded_syms_per_frame];
int Nsamperframe = ofdm_get_samples_per_frame();
complex float tx_symbols[OFDM_BITSPERFRAME/OFDM_BPS];
int j;
for (j=0; j