2014-12-17 12:52:58 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
|
|
|
* Copyright 2013-2014 The libLTE Developers. See the
|
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
|
|
|
* This file is part of the libLTE library.
|
|
|
|
*
|
|
|
|
* libLTE 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.
|
|
|
|
*
|
|
|
|
* libLTE is distributed in the hope that it will be useful,
|
2014-12-01 13:15:32 -08:00
|
|
|
* 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.
|
2014-12-17 12:52:58 -08:00
|
|
|
*
|
|
|
|
* A copy of the GNU Lesser General Public License can be found in
|
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
2014-12-01 13:15:32 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/srslte.h"
|
2015-03-18 05:16:28 -07:00
|
|
|
#include "srslte/mex/mexutils.h"
|
2014-12-01 13:15:32 -08:00
|
|
|
|
|
|
|
/** MEX function to be called from MATLAB to test the channel estimator
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ENBCFG prhs[0]
|
|
|
|
#define RNTI prhs[1]
|
|
|
|
#define INPUT prhs[2]
|
|
|
|
#define NOF_INPUTS 3
|
|
|
|
|
|
|
|
#define MAX_CANDIDATES 64
|
|
|
|
|
|
|
|
|
|
|
|
dci_format_t ue_formats[] = {Format1A,Format1}; // Format1B should go here also
|
|
|
|
const uint32_t nof_ue_formats = 2;
|
|
|
|
|
|
|
|
dci_format_t common_formats[] = {Format1A,Format1C};
|
|
|
|
const uint32_t nof_common_formats = 2;
|
|
|
|
|
|
|
|
|
|
|
|
void help()
|
|
|
|
{
|
|
|
|
mexErrMsgTxt
|
2015-03-18 05:16:28 -07:00
|
|
|
("[decoded_ok, llr, rm, bits, symbols] = srslte_pdcch(enbConfig, RNTI, rxWaveform)\n\n");
|
2014-12-01 13:15:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the gateway function */
|
|
|
|
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|
|
|
{
|
2014-12-17 12:52:58 -08:00
|
|
|
int i;
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_cell_t cell;
|
2014-12-01 13:15:32 -08:00
|
|
|
pdcch_t pdcch;
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_chest_dl_t chest;
|
|
|
|
srslte_fft_t fft;
|
2014-12-01 13:15:32 -08:00
|
|
|
regs_t regs;
|
|
|
|
dci_location_t locations[MAX_CANDIDATES];
|
|
|
|
uint32_t cfi, sf_idx;
|
|
|
|
uint16_t rnti;
|
2014-12-17 12:52:58 -08:00
|
|
|
cf_t *input_fft, *input_signal;
|
2014-12-01 13:15:32 -08:00
|
|
|
int nof_re;
|
|
|
|
uint32_t nof_formats;
|
|
|
|
dci_format_t *formats = NULL;
|
|
|
|
|
|
|
|
if (nrhs != NOF_INPUTS) {
|
|
|
|
help();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mexutils_read_cell(ENBCFG, &cell)) {
|
|
|
|
help();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mexutils_read_uint32_struct(ENBCFG, "CFI", &cfi)) {
|
|
|
|
help();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mexutils_read_uint32_struct(ENBCFG, "NSubframe", &sf_idx)) {
|
|
|
|
help();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-17 12:52:58 -08:00
|
|
|
|
2015-03-18 05:41:50 -07:00
|
|
|
if (srslte_chest_dl_init(&chest, cell)) {
|
2014-12-17 12:52:58 -08:00
|
|
|
fprintf(stderr, "Error initializing equalizer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-18 05:41:50 -07:00
|
|
|
if (srslte_fft_init(&fft, cell.cp, cell.nof_prb)) {
|
2014-12-17 12:52:58 -08:00
|
|
|
fprintf(stderr, "Error initializing FFT\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-12-01 13:15:32 -08:00
|
|
|
|
|
|
|
rnti = (uint16_t) mxGetScalar(RNTI);
|
|
|
|
|
|
|
|
if (regs_init(®s, cell)) {
|
|
|
|
mexErrMsgTxt("Error initiating regs\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (regs_set_cfi(®s, cfi)) {
|
|
|
|
fprintf(stderr, "Error setting CFI\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdcch_init(&pdcch, ®s, cell)) {
|
|
|
|
mexErrMsgTxt("Error initiating channel estimator\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Allocate input buffers */
|
2014-12-17 12:52:58 -08:00
|
|
|
if (mexutils_read_cf(INPUT, &input_signal) < 0) {
|
|
|
|
mexErrMsgTxt("Error reading input signal\n");
|
|
|
|
return;
|
2014-12-01 13:15:32 -08:00
|
|
|
}
|
2015-03-18 05:59:29 -07:00
|
|
|
input_fft = vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
|
2014-12-01 13:15:32 -08:00
|
|
|
|
|
|
|
// Set Channel estimates to 1.0 (ignore fading)
|
2015-03-18 05:41:50 -07:00
|
|
|
cf_t *ce[SRSLTE_MAX_PORTS];
|
2014-12-01 13:15:32 -08:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
2015-03-18 05:59:29 -07:00
|
|
|
ce[i] = vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
|
2014-12-01 13:15:32 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_fft_run_sf(&fft, input_signal, input_fft);
|
2014-12-17 12:52:58 -08:00
|
|
|
|
|
|
|
if (nrhs > NOF_INPUTS) {
|
|
|
|
cf_t *cearray;
|
2014-12-18 12:24:19 -08:00
|
|
|
nof_re = mexutils_read_cf(prhs[NOF_INPUTS], &cearray);
|
2014-12-17 12:52:58 -08:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
|
|
|
for (int j=0;j<nof_re;j++) {
|
|
|
|
ce[i][j] = *cearray;
|
|
|
|
cearray++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_chest_dl_estimate(&chest, input_fft, ce, sf_idx);
|
2014-12-17 12:52:58 -08:00
|
|
|
}
|
|
|
|
float noise_power;
|
|
|
|
if (nrhs > NOF_INPUTS + 1) {
|
|
|
|
noise_power = mxGetScalar(prhs[NOF_INPUTS+1]);
|
|
|
|
} else {
|
2015-03-18 05:41:50 -07:00
|
|
|
noise_power = srslte_chest_dl_get_noise_estimate(&chest);
|
2014-12-17 12:52:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pdcch_extract_llr(&pdcch, input_fft, ce, noise_power, sf_idx, cfi);
|
2014-12-01 13:15:32 -08:00
|
|
|
|
|
|
|
uint32_t nof_locations;
|
2015-03-18 05:59:29 -07:00
|
|
|
if (rnti == SRSLTE_SIRNTI) {
|
2014-12-01 13:15:32 -08:00
|
|
|
nof_locations = pdcch_common_locations(&pdcch, locations, MAX_CANDIDATES, cfi);
|
|
|
|
formats = common_formats;
|
|
|
|
nof_formats = nof_common_formats;
|
|
|
|
} else {
|
|
|
|
nof_locations = pdcch_ue_locations(&pdcch, locations, MAX_CANDIDATES, sf_idx, cfi, rnti);
|
|
|
|
formats = ue_formats;
|
|
|
|
nof_formats = nof_ue_formats;
|
|
|
|
}
|
2015-03-18 08:05:38 -07:00
|
|
|
uint16_t srslte_crc_rem=0;
|
2014-12-01 13:15:32 -08:00
|
|
|
dci_msg_t dci_msg;
|
2014-12-17 12:52:58 -08:00
|
|
|
bzero(&dci_msg, sizeof(dci_msg_t));
|
2014-12-01 13:15:32 -08:00
|
|
|
|
|
|
|
for (int f=0;f<nof_formats;f++) {
|
2015-03-18 08:05:38 -07:00
|
|
|
for (i=0;i<nof_locations && srslte_crc_rem != rnti;i++) {
|
|
|
|
if (pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], formats[f], &srslte_crc_rem)) {
|
2014-12-01 13:15:32 -08:00
|
|
|
fprintf(stderr, "Error decoding DCI msg\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nlhs >= 1) {
|
2015-03-18 08:05:38 -07:00
|
|
|
plhs[0] = mxCreateLogicalScalar(srslte_crc_rem == rnti);
|
2014-12-01 13:15:32 -08:00
|
|
|
}
|
|
|
|
int nof_bits = (regs_pdcch_nregs(®s, cfi) / 9) * 72;
|
|
|
|
if (nlhs >= 2) {
|
|
|
|
mexutils_write_f(pdcch.pdcch_llr, &plhs[1], nof_bits, 1);
|
|
|
|
}
|
|
|
|
if (nlhs >= 3) {
|
2014-12-17 12:52:58 -08:00
|
|
|
mexutils_write_cf(pdcch.pdcch_symbols[0], &plhs[2], 36*pdcch.nof_cce, 1);
|
2014-12-01 13:15:32 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_chest_dl_free(&chest);
|
|
|
|
srslte_fft_free(&fft);
|
2014-12-01 13:15:32 -08:00
|
|
|
pdcch_free(&pdcch);
|
|
|
|
regs_free(®s);
|
2014-12-17 12:52:58 -08:00
|
|
|
|
2014-12-01 13:15:32 -08:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
|
|
|
free(ce[i]);
|
|
|
|
}
|
2014-12-17 12:52:58 -08:00
|
|
|
free(input_signal);
|
|
|
|
free(input_fft);
|
|
|
|
|
2014-12-01 13:15:32 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|