mirror of https://github.com/PentHertz/srsLTE.git
131 lines
3.2 KiB
C
131 lines
3.2 KiB
C
|
/*
|
||
|
* Copyright (c) 2012, Ismael Gomez-Miguelez <ismael.gomez@tsc.upc.edu>.
|
||
|
* This file is part of ALOE++ (http://flexnets.upc.edu/)
|
||
|
*
|
||
|
* ALOE++ is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* ALOE++ 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 Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public License
|
||
|
* along with ALOE++. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include <string.h>
|
||
|
#include "liblte/phy/phy.h"
|
||
|
#include "liblte/mex/mexutils.h"
|
||
|
|
||
|
/** MEX function to be called from MATLAB to test the channel estimator
|
||
|
*/
|
||
|
|
||
|
#define ENBCFG prhs[0]
|
||
|
#define INPUT prhs[1]
|
||
|
#define NOF_INPUTS 2
|
||
|
|
||
|
|
||
|
void help()
|
||
|
{
|
||
|
mexErrMsgTxt
|
||
|
("[decoded_ok, symbols, bits] = liblte_pbch(enbConfig, inputSignal)\n\n");
|
||
|
}
|
||
|
|
||
|
/* the gateway function */
|
||
|
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||
|
{
|
||
|
|
||
|
int i;
|
||
|
lte_cell_t cell;
|
||
|
pbch_t pbch;
|
||
|
chest_dl_t chest;
|
||
|
lte_fft_t fft;
|
||
|
cf_t *input_symbols, *input_fft;
|
||
|
int nof_re;
|
||
|
cf_t *ce[MAX_PORTS], *ce_slot[MAX_PORTS];
|
||
|
|
||
|
if (nrhs != NOF_INPUTS) {
|
||
|
help();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (mexutils_read_cell(ENBCFG, &cell)) {
|
||
|
help();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Read input symbols
|
||
|
mexutils_read_cf(INPUT, &input_symbols);
|
||
|
|
||
|
nof_re = SF_LEN_RE(cell.nof_prb, cell.cp);
|
||
|
|
||
|
// Allocate memory
|
||
|
input_fft = vec_malloc(nof_re * sizeof(cf_t));
|
||
|
for (i=0;i<MAX_PORTS;i++) {
|
||
|
ce[i] = vec_malloc(nof_re * sizeof(cf_t));
|
||
|
}
|
||
|
|
||
|
if (chest_dl_init(&chest, cell)) {
|
||
|
fprintf(stderr, "Error initializing equalizer\n");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) {
|
||
|
fprintf(stderr, "Error initializing FFT\n");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (pbch_init(&pbch, cell)) {
|
||
|
fprintf(stderr, "Error initiating PBCH\n");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
lte_fft_run_sf(&fft, input_symbols, input_fft);
|
||
|
chest_dl_estimate(&chest, input_fft, ce, 0);
|
||
|
|
||
|
for (int i=0;i<MAX_PORTS;i++) {
|
||
|
ce_slot[i] = &ce[i][SLOT_LEN_RE(cell.nof_prb, cell.cp)];
|
||
|
}
|
||
|
|
||
|
uint32_t nof_ports;
|
||
|
int n = pbch_decode(&pbch, &input_fft[SLOT_LEN_RE(cell.nof_prb, cell.cp)],
|
||
|
ce_slot, chest_dl_get_noise_estimate(&chest),
|
||
|
NULL, &nof_ports, NULL);
|
||
|
|
||
|
if (nlhs >= 1) {
|
||
|
if (n == 1) {
|
||
|
plhs[0] = mxCreateDoubleScalar(nof_ports);
|
||
|
} else {
|
||
|
plhs[0] = mxCreateDoubleScalar(0);
|
||
|
}
|
||
|
}
|
||
|
if (nlhs >= 2) {
|
||
|
mexutils_write_cf(pbch.pbch_d, &plhs[1], pbch.nof_symbols, 1);
|
||
|
}
|
||
|
if (nlhs >= 3) {
|
||
|
mexutils_write_f(pbch.pbch_llr, &plhs[2], 2*pbch.nof_symbols, 1);
|
||
|
}
|
||
|
if (nlhs >= 4) {
|
||
|
mexutils_write_cf(ce[0], &plhs[3], SF_LEN_RE(cell.nof_prb,cell.cp)/14, 14);
|
||
|
}
|
||
|
if (nlhs >= 5) {
|
||
|
mexutils_write_cf(ce[1], &plhs[4], SF_LEN_RE(cell.nof_prb,cell.cp)/14, 14);
|
||
|
}
|
||
|
|
||
|
chest_dl_free(&chest);
|
||
|
lte_fft_free(&fft);
|
||
|
pbch_free(&pbch);
|
||
|
|
||
|
for (i=0;i<cell.nof_ports;i++) {
|
||
|
free(ce[i]);
|
||
|
}
|
||
|
free(input_symbols);
|
||
|
free(input_fft);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|