/** * * \section COPYRIGHT * * Copyright 2013-2015 Software Radio Systems Limited * * \section LICENSE * * This file is part of the srsLTE library. * * srsLTE is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * srsLTE 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 Affero General Public License for more details. * * A copy of the GNU Affero 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/. * */ #include #include #include "srslte/mex/mexutils.h" #include "srslte/utils/vector.h" #include "srslte/common/phy_common.h" bool mexutils_isScalar(const mxArray *ptr) { return mxGetM(ptr) == 1 && mxGetN(ptr) == 1; } bool mexutils_isCell(const mxArray *ptr) { return mxIsCell(ptr); } int mexutils_getLength(const mxArray *ptr) { const mwSize *dims; dims = mxGetDimensions(ptr); return dims[0]; } mxArray* mexutils_getCellArray(const mxArray *ptr, int idx) { return mxGetCell(ptr, idx); } char *mexutils_get_char_struct(const mxArray *ptr, const char *field_name) { mxArray *p; p = mxGetField(ptr, 0, field_name); if (!p) { return ""; } if (mxIsCell(p)) { return mxArrayToString(mxGetCell(p,0)); } else { return mxArrayToString(p); } } int mexutils_read_uint32_struct(const mxArray *ptr, const char *field_name, uint32_t *value) { mxArray *p; p = mxGetField(ptr, 0, field_name); if (!p) { return -1; } *value = (uint32_t) mxGetScalar(p); return 0; } int mexutils_read_float_struct(const mxArray *ptr, const char *field_name, float *value) { mxArray *p; p = mxGetField(ptr, 0, field_name); if (!p) { return -1; } *value = (float) mxGetScalar(p); return 0; } int mexutils_read_cell(const mxArray *ptr, srslte_cell_t *cell) { if (mexutils_read_uint32_struct(ptr, "NCellID", &cell->id)) { return -1; } if (mexutils_read_uint32_struct(ptr, "CellRefP", &cell->nof_ports)) { return -1; } if (mexutils_read_uint32_struct(ptr, "NDLRB", &cell->nof_prb)) { return -1; } if (!strcmp(mexutils_get_char_struct(ptr, "CyclicPrefix"), "Extended")) { cell->cp = SRSLTE_CP_EXT; } else { cell->cp = SRSLTE_CP_NORM; } if (!strcmp(mexutils_get_char_struct(ptr, "PHICHDuration"), "Extended")) { cell->phich_length = SRSLTE_PHICH_EXT; } else { cell->phich_length = SRSLTE_PHICH_NORM; } if (!strcmp(mexutils_get_char_struct(ptr, "Ng"), "Sixth")) { cell->phich_resources = SRSLTE_PHICH_R_1_6; } else if (!strcmp(mexutils_get_char_struct(ptr, "Ng"), "Half")) { cell->phich_resources = SRSLTE_PHICH_R_1_2; } else if (!strcmp(mexutils_get_char_struct(ptr, "Ng"), "Two")) { cell->phich_resources = SRSLTE_PHICH_R_2; } else { cell->phich_resources = SRSLTE_PHICH_R_1; } return 0; } int mexutils_read_cf(const mxArray *ptr, cf_t **buffer) { int numelems = mxGetNumberOfElements(ptr); cf_t *tmp = srslte_vec_malloc(numelems * sizeof(cf_t)); if (tmp) { double *inr=mxGetPr(ptr); double *ini=mxGetPi(ptr); for (int i=0;i