2014-12-17 12:52:58 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* Copyright 2013-2015 The srsLTE Developers. See the
|
2014-12-17 12:52:58 -08:00
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* This file is part of the srsLTE library.
|
2014-12-17 12:52:58 -08:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2014-12-17 12:52:58 -08:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2014-12-16 09:30:37 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 08:05:40 -07:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-12-17 12:52:58 -08:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2014-12-17 12:52:58 -08:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
2014-12-16 09:30:37 -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-16 09:30:37 -08:00
|
|
|
|
|
|
|
/** MEX function to be called from MATLAB to test the channel estimator
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define INPUT prhs[0]
|
|
|
|
#define NOF_INPUTS 1
|
|
|
|
|
|
|
|
|
|
|
|
void help()
|
|
|
|
{
|
|
|
|
mexErrMsgTxt
|
2015-03-18 05:16:28 -07:00
|
|
|
("[decoded_bits] = srslte_viterbi(input_llr, type)\n\n");
|
2014-12-16 09:30:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the gateway function */
|
|
|
|
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|
|
|
{
|
|
|
|
|
2015-03-18 08:05:38 -07:00
|
|
|
srslte_viterbi_t viterbi;
|
2014-12-16 09:30:37 -08:00
|
|
|
float *input_llr;
|
|
|
|
uint8_t *output_data;
|
|
|
|
int nof_bits;
|
|
|
|
|
|
|
|
if (nrhs < NOF_INPUTS) {
|
|
|
|
help();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read input symbols
|
|
|
|
nof_bits = mexutils_read_f(INPUT, &input_llr);
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
output_data = srslte_vec_malloc(nof_bits * sizeof(uint8_t));
|
2014-12-16 09:30:37 -08:00
|
|
|
|
|
|
|
uint32_t poly[3] = { 0x6D, 0x4F, 0x57 };
|
2015-03-18 08:05:38 -07:00
|
|
|
if (srslte_viterbi_init(&viterbi, SRSLTE_VITERBI_37, poly, nof_bits/3, true)) {
|
2014-12-16 09:30:37 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nrhs >= 2) {
|
|
|
|
float gain_quant = mxGetScalar(prhs[1]);
|
2015-03-18 08:05:38 -07:00
|
|
|
srslte_viterbi_set_gain_quant(&viterbi, gain_quant);
|
2014-12-16 09:30:37 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 08:05:38 -07:00
|
|
|
srslte_viterbi_decode_f(&viterbi, input_llr, output_data, nof_bits/3);
|
2014-12-16 09:30:37 -08:00
|
|
|
|
|
|
|
if (nlhs >= 1) {
|
|
|
|
mexutils_write_uint8(output_data, &plhs[0], nof_bits/3, 1);
|
|
|
|
}
|
|
|
|
if (nlhs >= 2) {
|
|
|
|
mexutils_write_uint8(viterbi.symbols_uc, &plhs[1], nof_bits/3, 1);
|
|
|
|
}
|
|
|
|
|
2015-03-18 08:05:38 -07:00
|
|
|
srslte_viterbi_free(&viterbi);
|
2014-12-16 09:30:37 -08:00
|
|
|
|
|
|
|
free(input_llr);
|
|
|
|
free(output_data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|