From d56fc6d26d5fe939172936b6c06a7c7bca3c9baa Mon Sep 17 00:00:00 2001 From: ismagom Date: Tue, 16 Dec 2014 17:30:37 +0000 Subject: [PATCH] Patch to install rrc ASN headers --- lte/phy/lib/fec/test/viterbi_test_mex.c | 81 +++++++++++++++ lte/phy/lib/phch/test/pbch_test_mex.c | 130 ++++++++++++++++++++++++ lte/rrc/CMakeLists.txt | 30 ++++++ lte/rrc/asn/CMakeLists.txt | 3 +- matlab/tests/test_pbch.m | 104 +++++++++++++++++++ matlab/tests/test_viterbi.m | 49 +++++++++ 6 files changed, 395 insertions(+), 2 deletions(-) create mode 100644 lte/phy/lib/fec/test/viterbi_test_mex.c create mode 100644 lte/phy/lib/phch/test/pbch_test_mex.c create mode 100644 matlab/tests/test_pbch.m create mode 100644 matlab/tests/test_viterbi.m diff --git a/lte/phy/lib/fec/test/viterbi_test_mex.c b/lte/phy/lib/fec/test/viterbi_test_mex.c new file mode 100644 index 000000000..6d4b2d82c --- /dev/null +++ b/lte/phy/lib/fec/test/viterbi_test_mex.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012, Ismael Gomez-Miguelez . + * 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 . + */ + +#include +#include "liblte/phy/phy.h" +#include "liblte/mex/mexutils.h" + +/** MEX function to be called from MATLAB to test the channel estimator + */ + +#define INPUT prhs[0] +#define NOF_INPUTS 1 + + +void help() +{ + mexErrMsgTxt + ("[decoded_bits] = liblte_viterbi(input_llr, type)\n\n"); +} + +/* the gateway function */ +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) +{ + + viterbi_t viterbi; + 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); + + output_data = vec_malloc(nof_bits * sizeof(uint8_t)); + + uint32_t poly[3] = { 0x6D, 0x4F, 0x57 }; + if (viterbi_init(&viterbi, viterbi_37, poly, nof_bits/3, true)) { + return; + } + + if (nrhs >= 2) { + float gain_quant = mxGetScalar(prhs[1]); + viterbi_set_gain_quant(&viterbi, gain_quant); + } + + viterbi_decode_f(&viterbi, input_llr, output_data, nof_bits/3); + + 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); + } + + viterbi_free(&viterbi); + + free(input_llr); + free(output_data); + + return; +} + diff --git a/lte/phy/lib/phch/test/pbch_test_mex.c b/lte/phy/lib/phch/test/pbch_test_mex.c new file mode 100644 index 000000000..0679ea69d --- /dev/null +++ b/lte/phy/lib/phch/test/pbch_test_mex.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, Ismael Gomez-Miguelez . + * 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 . + */ + +#include +#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= 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 1) + plot(SNR_values_db, 1-error/Nrealizations) + grid on + xlabel('SNR (dB)'); + ylabel('Pdet') + legend('Matlab','libLTE') +else + disp(error) +end + diff --git a/matlab/tests/test_viterbi.m b/matlab/tests/test_viterbi.m new file mode 100644 index 000000000..06b49c82f --- /dev/null +++ b/matlab/tests/test_viterbi.m @@ -0,0 +1,49 @@ + +clear +blen=40; +SNR_values_db=linspace(-6,4,8); +Nrealizations=5000; + +addpath('../../debug/lte/phy/lib/fec/test') + +errors1=zeros(1,length(SNR_values_db)); +errors2=zeros(1,length(SNR_values_db)); +for snr_idx=1:length(SNR_values_db) + SNRdB = SNR_values_db(snr_idx); % Desired SNR in dB + SNR = 10^(SNRdB/20); % Linear SNR + + for i=1:Nrealizations + Data = randi(2,blen,1)==1; + codedData = lteConvolutionalEncode(Data); + + codedsymbols = 2*double(codedData)-1; + + %% Additive Noise + N0 = 1/SNR; + + % Create additive white Gaussian noise + noise = N0*randn(size(codedsymbols)); + + noisysymbols = noise + codedsymbols; + + decodedData = lteConvolutionalDecode(noisysymbols); + interleavedSymbols = reshape(reshape(noisysymbols,[],3)',1,[]); + [decodedData2, quant] = liblte_viterbi(interleavedSymbols); + + errors1(snr_idx) = errors1(snr_idx) + any(decodedData ~= Data); + errors2(snr_idx) = errors2(snr_idx) + any(decodedData2 ~= Data); + end +end + +if (length(SNR_values_db) > 1) + semilogy(SNR_values_db, errors1/Nrealizations, ... + SNR_values_db, errors2/Nrealizations) + grid on + xlabel('SNR (dB)') + ylabel('BLER') + legend('Matlab','libLTE'); +else + disp(errors1); + disp(errors2); + disp(errors3); +end \ No newline at end of file