void pbch_free(pbch_t *q) { if (q->pbch_d) { free(q->pbch_d); } int i; for (i = 0; i < q->cell.nof_ports; i++) { if (q->ce[i]) { free(q->ce[i]); } if (q->pbch_x[i]) { free(q->pbch_x[i]); } if (q->pbch_symbols[i]) { free(q->pbch_symbols[i]); } } if (q->pbch_llr) { free(q->pbch_llr); } if (q->temp) { free(q->temp); } if (q->pbch_rm_f) { free(q->pbch_rm_f); } if (q->pbch_rm_b) { free(q->pbch_rm_b); } if (q->data_enc) { free(q->data_enc); } if (q->data) { free(q->data); } sequence_free(&q->seq_pbch); modem_table_free(&q->mod); viterbi_free(&q->decoder); }
int demod_soft_stop(demod_soft_hl* hl) { modem_table_free(&hl->table); return 0; }
int main(int argc, char **argv) { int i; modem_table_t mod; demod_soft_t demod_soft; char *input, *output; cf_t *symbols; float *llr_exact, *llr_approx; parse_args(argc, argv); /* initialize objects */ if (modem_table_lte(&mod, modulation, true)) { fprintf(stderr, "Error initializing modem table\n"); exit(-1); } /* check that num_bits is multiple of num_bits x symbol */ num_bits = mod.nbits_x_symbol * (num_bits / mod.nbits_x_symbol); demod_soft_init(&demod_soft); demod_soft_table_set(&demod_soft, &mod); demod_soft_sigma_set(&demod_soft, 2.0 / mod.nbits_x_symbol); /* allocate buffers */ input = malloc(sizeof(char) * num_bits); if (!input) { perror("malloc"); exit(-1); } output = malloc(sizeof(char) * num_bits); if (!output) { perror("malloc"); exit(-1); } symbols = malloc(sizeof(cf_t) * num_bits / mod.nbits_x_symbol); if (!symbols) { perror("malloc"); exit(-1); } llr_exact = malloc(sizeof(float) * num_bits); if (!llr_exact) { perror("malloc"); exit(-1); } llr_approx = malloc(sizeof(float) * num_bits); if (!llr_approx) { perror("malloc"); exit(-1); } /* generate random data */ srand(0); int ret = -1; double mse; struct timeval t[3]; float mean_texec = 0.0; for (int n=0;n<nof_frames;n++) { for (i=0;i<num_bits;i++) { input[i] = rand()%2; } /* modulate */ mod_modulate(&mod, input, symbols, num_bits); /* add noise */ ch_awgn_c(symbols, symbols, ch_awgn_get_variance(5.0, mod.nbits_x_symbol), num_bits / mod.nbits_x_symbol); /* Compare exact with approximation algorithms */ demod_soft_alg_set(&demod_soft, EXACT); demod_soft_demodulate(&demod_soft, symbols, llr_exact, num_bits / mod.nbits_x_symbol); demod_soft_alg_set(&demod_soft, APPROX); gettimeofday(&t[1], NULL); demod_soft_demodulate(&demod_soft, symbols, llr_approx, num_bits / mod.nbits_x_symbol); gettimeofday(&t[2], NULL); get_time_interval(t); /* compute exponentially averaged execution time */ if (n > 0) { mean_texec = EXPAVERAGE((float) t[0].tv_usec, mean_texec, n-1); } /* check MSE */ mse = 0.0; for (i=0;i<num_bits;i++) { float e = llr_exact[i] - llr_approx[i]; mse += e*e; } mse/=num_bits; if (VERBOSE_ISDEBUG()) { printf("exact="); vec_fprint_f(stdout, llr_exact, num_bits); printf("approx="); vec_fprint_f(stdout, llr_approx, num_bits); } if (mse > mse_threshold()) { goto clean_exit; } } ret = 0; clean_exit: free(llr_exact); free(llr_approx); free(symbols); free(output); free(input); modem_table_free(&mod); if (ret == 0) { printf("Ok Mean Throughput: %.2f. Mbps ExTime: %.2f us\n", num_bits/mean_texec, mean_texec); } else { printf("Error: MSE too large (%f > %f)\n", mse, mse_threshold()); } exit(ret); }
void modem_table_reset(modem_table_t* q) { modem_table_free(q); modem_table_init(q); }
int mod_stop(mod_hl* hl) { modem_table_free(&hl->obj); return 0; }