return Terrs;
}
+
+int count_errors(int tx_bits[], char rx_bits[], int n) {
+ int i;
+ int Nerrs = 0;
+
+ Nerrs = 0;
+ for(i=0; i<n; i++) {
+ if (tx_bits[i] != rx_bits[i]) {
+ Nerrs++;
+ }
+ }
+ return Nerrs;
+}
+
+
+void ofdm_ldpc_interleave_tx(struct OFDM *ofdm, struct LDPC *ldpc, complex float tx_sams[], uint8_t tx_bits_char[], complex float tx_symbols[], int interleave_frames)
+{
+ int coded_syms_per_frame = ldpc->coded_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();
+
+ int i,j;
+
+ for (j=0; j<interleave_frames; j++) {
+ ldpc_encode_frame(ldpc, codeword, &tx_bits_char[j*data_bits_per_frame]);
+ qpsk_modulate_frame(&coded_symbols[j*coded_syms_per_frame], codeword, coded_syms_per_frame);
+ }
+ gp_interleave_comp(coded_symbols_inter, coded_symbols, interleave_frames*coded_syms_per_frame);
+ for (j=0; j<interleave_frames; j++) {
+ for(i=0; i<coded_syms_per_frame; i++) {
+ tx_symbols[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS+i] = coded_symbols_inter[j*coded_syms_per_frame+i].real
+ + I * coded_symbols_inter[j*coded_syms_per_frame+i].imag;
+ }
+ ofdm_txframe(ofdm, &tx_sams[j*Nsamperframe], tx_symbols);
+ }
+}
+
+/* UW never changes so we can pre-load tx_symbols with modulated UW */
+
+void build_modulated_uw(struct OFDM *ofdm, complex float tx_symbols[])
+{
+ int uw_txt_bits[OFDM_NUWBITS+OFDM_NTXTBITS];
+ COMP uw_txt_syms[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS];
+ int i,j;
+
+ for(i=0; i<OFDM_NUWBITS; i++) {
+ uw_txt_bits[i] = ofdm->tx_uw[i];
+ }
+ /* clear txt bits for now, they can be added in later */
+ for(j=0; j<OFDM_NTXTBITS; j++,i++) {
+ uw_txt_bits[i] = 0;
+ }
+ qpsk_modulate_frame(uw_txt_syms, uw_txt_bits, (OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS);
+ for(i=0; i<(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS; i++) {
+ tx_symbols[i] = uw_txt_syms[i].real + I * uw_txt_syms[i].imag;
+ }
+}
#ifndef __INTERLDPC__
#define __INTERLDPC__
+#include <stdint.h>
#include "comp.h"
#include "mpdecode_core.h"
#include "ofdm_internal.h"
float EsNo, int interleave_frames,
int *inter, int *parityCheckCount, int *Nerrs_coded);
int count_uncoded_errors(struct LDPC *ldpc, int Nerrs_raw[], int interleave_frames, COMP codeword_symbols_de[]);
+int count_errors(int tx_bits[], char rx_bits[], int n);
+void ofdm_ldpc_interleave_tx(struct OFDM *ofdm, struct LDPC *ldpc, complex float tx_sams[], uint8_t tx_bits_char[], complex float tx_symbols[], int interleave_frames);
+void build_modulated_uw(struct OFDM *ofdm, complex float tx_symbols[]);
#endif
iter[j] = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount[j]);
//fprintf(stderr,"j: %d iter: %d pcc: %d\n", j, iter[j], parityCheckCount[j]);
if (testframes) {
- Nerrs = 0;
- for(i=0; i<data_bits_per_frame; i++) {
- if (payload_data_bits[i] != out_char[i]) {
- Nerrs++;
- }
- }
- Nerrs_coded[j] = Nerrs;
- Terrs_coded += Nerrs;
+ Nerrs_coded[j] = count_errors(payload_data_bits, out_char, data_bits_per_frame);
+ Terrs_coded += Nerrs_coded[j];
Tbits_coded += data_bits_per_frame;
}
fwrite(out_char, sizeof(char), data_bits_per_frame, fout);
#include "ofdm_internal.h"
#include "interldpc.h"
#include "gp_interleaver.h"
-#include "test_bits_ofdm.h"
#define ASCALE (2E5*1.1491)
+extern int payload_data_bits[];
+extern int test_bits_ofdm[];
+
int opt_exists(char *argv[], int argc, char opt[]) {
int i;
for (i=0; i<argc; i++) {
/* build modulated UW and txt bits */
- int uw_txt_bits[OFDM_NUWBITS+OFDM_NTXTBITS];
- COMP uw_txt_syms[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS];
complex float tx_symbols[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS + coded_syms_per_frame];
- for(i=0; i<OFDM_NUWBITS; i++) {
- uw_txt_bits[i] = ofdm->tx_uw[i];
- }
- for(j=0; j<OFDM_NTXTBITS; j++,i++) {
- uw_txt_bits[i] = 0;
- }
- qpsk_modulate_frame(uw_txt_syms, uw_txt_bits, (OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS);
- for(i=0; i<(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS; i++) {
- tx_symbols[i] = uw_txt_syms[i].real + I * uw_txt_syms[i].imag;
- }
-
+ build_modulated_uw(ofdm, tx_symbols);
+
testframes = 0;
int Nframes = 0;
if ((arg = (opt_exists(argv, argc, "-t")))) {
if (ldpc_en) {
/* fancy interleaved LDPC encoded frames ----------------------------------------*/
- /* optionally overwrite input data with test frame nown to demodulator */
+ /* optionally overwrite input data with test frame of
+ payload data bits known to demodulator */
if (testframes) {
for (j=0; j<interleave_frames; j++) {
}
}
}
-
- 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];
- complex float tx_sams[Nsamperframe];
-
- for (j=0; j<interleave_frames; j++) {
- ldpc_encode_frame(&ldpc, codeword, &tx_bits_char[j*data_bits_per_frame]);
- qpsk_modulate_frame(&coded_symbols[j*coded_syms_per_frame], codeword, coded_syms_per_frame);
- }
- gp_interleave_comp(coded_symbols_inter, coded_symbols, interleave_frames*coded_syms_per_frame);
+
+ complex float tx_sams[interleave_frames*Nsamperframe];
+ ofdm_ldpc_interleave_tx(ofdm, &ldpc, tx_sams, tx_bits_char, tx_symbols, interleave_frames);
+
for (j=0; j<interleave_frames; j++) {
- for(i=0; i<coded_syms_per_frame; i++) {
- tx_symbols[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS+i] = coded_symbols_inter[j*coded_syms_per_frame+i].real
- + I * coded_symbols_inter[j*coded_syms_per_frame+i].imag;
- }
- ofdm_txframe(ofdm, tx_sams, tx_symbols);
for(i=0; i<Nsamperframe; i++) {
- tx_scaled[i] = ASCALE * crealf(tx_sams[i]);
+ tx_scaled[i] = ASCALE * crealf(tx_sams[j*Nsamperframe+i]);
}
fwrite(tx_scaled, sizeof(short), Nsamperframe, fout);
frames++;
}
+
} else {
/* just modulate uncoded raw bits ----------------------------------------------*/
tx_bits_char[i] = test_bits_ofdm[i];
}
}
+
for(i=0; i<Nbitsperframe; i++)
tx_bits[i] = tx_bits_char[i];
COMP tx_sams[Nsamperframe];