/* High-Level API */ int mod_initialize(mod_hl* hl) { modem_table_init(&hl->obj); if (modem_table_std(&hl->obj,hl->init.std,false)) { return -1; } return 0; }
/* High-Level API */ int demod_soft_initialize(demod_soft_hl* hl) { modem_table_init(&hl->table); if (modem_table_std(&hl->table,hl->init.std,true)) { return -1; } demod_soft_init(&hl->obj); hl->obj.table = &hl->table; return 0; }
int main(int argc, char **argv) { viterbi_t dec; convcoder_t cod; modem_table_t modem; demod_soft_t demod; int frame_cnt; float *llr; char *data_tx, *data_rx, *symbols; cf_t *iq; int i; parse_args(argc,argv); if (!seed) { seed = time(NULL); } srand(seed); int coded_length = 3 * (frame_length + ((tail_biting)?0:6)); printf("Convolutional Code 1/3 K=7 Test\n"); printf(" Frame length: %d\n", frame_length); printf(" Codeword length: %d\n", coded_length); printf(" Tail bitting: %s\n", tail_biting?"yes":"no"); printf(" EbNo: %.2f\n", ebno_db); data_tx = malloc(frame_length * sizeof(char)); if (!data_tx) { perror("malloc"); exit(-1); } data_rx = malloc(frame_length * sizeof(char)); if (!data_rx) { perror("malloc"); exit(-1); } symbols = malloc(coded_length * sizeof(char)); if (!symbols) { perror("malloc"); exit(-1); } llr = malloc(coded_length * sizeof(float)); if (!llr) { perror("malloc"); exit(-1); } iq = malloc(coded_length * sizeof(cf_t)); if (!iq) { perror("malloc"); exit(-1); } cod.K = 7; cod.R = 3; cod.tail_biting = tail_biting; cod.framelength = frame_length; cod.poly[0] = 0x6D; cod.poly[1] = 0x4F; cod.poly[2] = 0x57; float var = sqrt(pow(10,-ebno_db/10)); modem_table_init(&modem); modem_table_std(&modem, LTE_QPSK, true); demod_soft_init(&demod); demod_soft_table_set(&demod, &modem); demod_soft_alg_set(&demod, APPROX); demod_soft_sigma_set(&demod, var); viterbi_init(&dec, viterbi_37, cod.poly, frame_length, tail_biting); /* read all file or nof_frames */ frame_cnt = 0; unsigned int errors=0; while (frame_cnt < nof_slots) { /* generate data_tx */ for (i=0;i<frame_length;i++) { data_tx[i] = message[i]; } convcoder_encode(&cod, data_tx, symbols); bit_fprint(stdout, symbols, 120); mod_modulate(&modem, symbols, iq, coded_length); if (ebno_db < 100.0) { ch_awgn(iq, iq, var, coded_length/2); } demod_soft_demodulate(&demod, iq, llr, coded_length/2); viterbi_decode(&dec, llr, data_rx); errors += bit_diff(data_tx, data_rx, frame_length); frame_cnt++; } printf("BER:\t%g\t%u errors\n", (float) errors/(frame_cnt*frame_length), errors); viterbi_free(&dec); free(data_tx); free(symbols); free(iq); free(llr); free(data_rx); printf("Done\n"); exit(0); }
/** Initializes the PBCH transmitter and receiver */ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) { int ret = -1; if (cell_id < 0) { return -1; } bzero(q, sizeof(pbch_t)); q->cell_id = cell_id; q->cp = cp; q->nof_prb = nof_prb; if (modem_table_std(&q->mod, LTE_QPSK, true)) { goto clean; } demod_soft_init(&q->demod); demod_soft_table_set(&q->demod, &q->mod); demod_soft_alg_set(&q->demod, APPROX); if (sequence_pbch(&q->seq_pbch, q->cp, q->cell_id)) { goto clean; } int poly[3] = { 0x6D, 0x4F, 0x57 }; if (viterbi_init(&q->decoder, viterbi_37, poly, 40, true)) { goto clean; } if (crc_init(&q->crc, LTE_CRC16, 16)) { goto clean; } q->encoder.K = 7; q->encoder.R = 3; q->encoder.tail_biting = true; memcpy(q->encoder.poly, poly, 3 * sizeof(int)); q->nof_symbols = (CP_ISNORM(q->cp)) ? PBCH_RE_CPNORM : PBCH_RE_CPEXT; q->pbch_d = malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_d) { goto clean; } int i; for (i = 0; i < MAX_PORTS_CTRL; i++) { q->ce[i] = malloc(sizeof(cf_t) * q->nof_symbols); if (!q->ce[i]) { goto clean; } q->pbch_x[i] = malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_x[i]) { goto clean; } q->pbch_symbols[i] = malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_symbols[i]) { goto clean; } } q->pbch_llr = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_llr) { goto clean; } q->temp = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->temp) { goto clean; } q->pbch_rm_f = malloc(sizeof(float) * 120); if (!q->pbch_rm_f) { goto clean; } q->pbch_rm_b = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_rm_b) { goto clean; } q->data = malloc(sizeof(char) * 40); if (!q->data) { goto clean; } q->data_enc = malloc(sizeof(char) * 120); if (!q->data_enc) { goto clean; } ret = 0; clean: if (ret == -1) { pbch_free(q); } return ret; }