Scanner version working correctly

master
ismagom 10 years ago
parent 92e0db231c
commit d6797964a5

@ -127,7 +127,7 @@ int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples) {
extern float mean_exec_time;
enum receiver_state { DECODE_MIB, DECODE_SIB, DECODE_SIB4, MEASURE} state;
enum receiver_state { DECODE_MIB, DECODE_SIB, MEASURE} state;
#define MAX_SINFO 10
#define MAX_NEIGHBOUR_CELLS 128
@ -151,10 +151,6 @@ int main(int argc, char **argv) {
uint8_t bch_payload[BCH_PAYLOAD_LEN], bch_payload_unpacked[BCH_PAYLOAD_LEN];
uint32_t sfn_offset;
float rssi_utra=0,rssi=0, rsrp=0, rsrq=0, snr=0;
uint32_t si_window_length;
scheduling_info_t sinfo[MAX_SINFO];
scheduling_info_t *sinfo_sib4 = NULL;
uint32_t neighbour_cell_ids[MAX_NEIGHBOUR_CELLS];
cf_t *ce[MAX_PORTS];
if (parse_args(&prog_args, argc, argv)) {
@ -234,10 +230,6 @@ int main(int argc, char **argv) {
cuhd_start_rx_stream(uhd);
bool sib4_window_start = false;
uint32_t sib4_window_cnt = 0;
/* Main loop */
while (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1) {
@ -289,66 +281,12 @@ int main(int argc, char **argv) {
bcch_dlsch_sib1_get_cell_access_info(dlsch_msg, &cell_info);
printf("Decoded SIB1. Cell ID: 0x%x\n", cell_info.cell_id);
bcch_dlsch_fprint(dlsch_msg, stdout);
/* Get SIB4 scheduling */
int nsinfo = bcch_dlsch_sib1_get_scheduling_info(dlsch_msg, &si_window_length, sinfo, MAX_SINFO);
/* find SIB4 */
for (int i=0;i<nsinfo && !sinfo_sib4;i++) {
if (sinfo[i].type == SIB4) {
sinfo_sib4 = &sinfo[i];
}
}
ue_dl.nof_pdcch_detected = nof_trials = 0;
sib4_window_start = false;
bzero(data, sizeof(data));
ue_dl_reset(&ue_dl);
}
if (sinfo_sib4) {
state = DECODE_SIB4;
} else {
state = MEASURE;
}
}
}
break;
case DECODE_SIB4:
if (!sib4_window_start &&
((sfn%sinfo_sib4->period) == sinfo_sib4->n*si_window_length/10) &&
ue_sync_get_sfidx(&ue_sync) == (sinfo_sib4->n*si_window_length%10)) {
sib4_window_start = true;
sib4_window_cnt = 0;
}
/* We are looking for SI Blocks, search only in appropiate places */
if (sib4_window_start && !(ue_sync_get_sfidx(&ue_sync) == 5 && (sfn%2)==0))
{
n = ue_dl_decode_sib(&ue_dl, sf_buffer, data, ue_sync_get_sfidx(&ue_sync),
((int) ceilf((float)3*sib4_window_cnt/2))%4);
if (n < 0) {
fprintf(stderr, "Error decoding UE DL\n");fflush(stdout);
return -1;
} else if (n == 0) {
nof_trials++;
} else {
bit_unpack_vector(data, data_unpacked, n);
void *dlsch_msg = bcch_dlsch_unpack(data_unpacked, n);
int nof_cell = bcch_dlsch_sib4_get_neighbour_cells(dlsch_msg, neighbour_cell_ids, MAX_NEIGHBOUR_CELLS);
printf("Decoded SIB4. Neighbour cell list (PhyIDs): ");
for (int i=0;i<nof_cell;i++) {
printf("%d, ", neighbour_cell_ids[i]);
}
printf("\n");
state = MEASURE;
}
sib4_window_cnt++;
if (sib4_window_cnt == si_window_length) {
sib4_window_start = false;
return -1;
}
}
break;
case MEASURE:
if (ue_sync_get_sfidx(&ue_sync) == 5) {
@ -359,9 +297,9 @@ int main(int argc, char **argv) {
rssi = VEC_CMA(vec_avg_power_cf(sf_buffer,SF_LEN(lte_symbol_sz(cell.nof_prb))),rssi,nframes);
rssi_utra = VEC_CMA(chest_dl_get_rssi(&chest),rssi_utra,nframes);
rsrq = VEC_EMA(chest_dl_get_rsrq(&chest),rsrq,0.001);
rsrp = VEC_EMA(chest_dl_get_rsrp(&chest),rsrp,0.001);
snr = VEC_EMA(chest_dl_get_snr(&chest),snr,0.001);
rsrq = VEC_EMA(chest_dl_get_rsrq(&chest),rsrq,0.05);
rsrp = VEC_EMA(chest_dl_get_rsrp(&chest),rsrp,0.05);
snr = VEC_EMA(chest_dl_get_snr(&chest),snr,0.05);
nframes++;
}

@ -276,7 +276,6 @@ int main(int argc, char **argv) {
}
break;
case DECODE_SIB:
sfn=0;
/* We are looking for SI Blocks, search only in appropiate places */
if ((ue_sync_get_sfidx(&ue_sync) == 5 && (sfn%2)==0)) {
n = ue_dl_decode_sib(&ue_dl, sf_buffer, data, ue_sync_get_sfidx(&ue_sync),
@ -287,9 +286,9 @@ int main(int argc, char **argv) {
}
nof_trials++;
rsrq = VEC_EMA(chest_dl_get_rsrq(&ue_dl.chest),rsrq,0.001);
rsrp = VEC_EMA(chest_dl_get_rsrp(&ue_dl.chest),rsrp,0.001);
snr = VEC_EMA(chest_dl_get_snr(&ue_dl.chest),snr,0.001);
rsrq = VEC_EMA(chest_dl_get_rsrq(&ue_dl.chest), rsrq, 0.05);
rsrp = VEC_EMA(chest_dl_get_rsrp(&ue_dl.chest), rsrp, 0.05);
snr = VEC_EMA(chest_dl_get_snr(&ue_dl.chest), snr, 0.05);
nframes++;
if (isnan(rsrq)) {
rsrq = 0;
@ -303,9 +302,9 @@ int main(int argc, char **argv) {
"PDCCH-Miss: %5.2f%%, PDSCH-BLER: %5.2f%% (%d blocks)\r",
ue_sync_get_cfo(&ue_sync)/1000, ue_sync_get_sfo(&ue_sync)/1000,
10*log10(rsrp*1000)-gain_offset,
10*log10(rsrq), 10*log10(snr),
100*(1-(float) ue_dl.nof_pdcch_detected/nof_trials),
(float) 100*ue_dl.pkt_errors/ue_dl.pkts_total,nof_trials, ue_dl.pkts_total);
10*log10(rsrq), 10*log10(snr),
100*(1-(float) ue_dl.nof_pdcch_detected/nof_trials),
(float) 100*ue_dl.pkt_errors/ue_dl.pkts_total,nof_trials, ue_dl.pkts_total);
}
break;
}

@ -116,8 +116,10 @@ int chest_dl_init(chest_dl_t *q, lte_cell_t cell)
/* Set default time/freq filters */
//float f[3]={0.15, 0.7, 0.15};
float f[3]={0.2, 0.6, 0.2};
chest_dl_set_filter_freq(q, f, 3);
//chest_dl_set_filter_freq(q, f, 3);
float f[5]={0.05, 0.15, 0.6, 0.15, 0.05};
chest_dl_set_filter_freq(q, f, 5);
float t[2]={0.1, 0.9};
chest_dl_set_filter_time(q, t, 2);
@ -196,13 +198,9 @@ static float estimate_noise_port(chest_dl_t *q, uint32_t port_id, cf_t *avg_pilo
vec_sub_ccc(avg_pilots, q->pilot_estimates[port_id],
q->tmp_noise, REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id));
float noise_var = vec_avg_power_cf(q->tmp_noise, REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id));
/* compute noise power. Correction factor obtained through simulations */
return 0.75 * sqrtf((float) q->filter_freq_len) * noise_var / sqrt(q->cell.nof_prb);
return vec_avg_power_cf(q->tmp_noise, REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id));
}
#define pilot_est(idx) q->pilot_estimates[port_id][REFSIGNAL_PILOT_IDX(idx,l,q->cell)]
#define pilot_avg(idx) q->pilot_estimates_average[port_id][REFSIGNAL_PILOT_IDX(idx,l,q->cell)]
#define pilot_tmp(idx) q->tmp_freqavg[REFSIGNAL_PILOT_IDX(idx,l,q->cell)]
@ -310,8 +308,13 @@ float chest_dl_rssi(chest_dl_t *q, cf_t *input, uint32_t port_id) {
}
float chest_dl_rsrp(chest_dl_t *q, uint32_t port_id) {
return vec_avg_power_cf(q->pilot_recv_signal[port_id],
#ifdef RSRP_FROM_ESTIMATES
return vec_avg_power_cf(q->pilot_estimates[port_id],
REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id));
#else
return vec_avg_power_cf(q->pilot_estimates_average[port_id],
REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id));
#endif
}
int chest_dl_estimate_port(chest_dl_t *q, cf_t *input, cf_t *ce, uint32_t sf_idx, uint32_t port_id)
@ -356,14 +359,8 @@ float chest_dl_get_noise_estimate(chest_dl_t *q) {
}
float chest_dl_get_snr(chest_dl_t *q) {
float snr = 0.0;
for (int i=0;i<q->cell.nof_ports;i++) {
if (q->noise_estimate[i]) {
float snr_i = q->rsrp[i]/(q->noise_estimate[i]*sqrtf(2*q->cell.nof_ports*lte_symbol_sz(q->cell.nof_prb)));
snr += snr_i;
}
}
return snr/q->cell.nof_ports;
// Uses RSRP as an estimation of the useful signal power
return chest_dl_get_rsrp(q)/chest_dl_get_noise_estimate(q);
}
float chest_dl_get_rssi(chest_dl_t *q) {
@ -380,9 +377,9 @@ float chest_dl_get_rsrq(chest_dl_t *q) {
float chest_dl_get_rsrp(chest_dl_t *q) {
// return linear average from port 0 only
return q->rsrp[0];
//return q->rsrp[0];
// return linear average from all ports
//return vec_acc_ff(q->rsrp, q->cell.nof_ports)/q->cell.nof_ports;
return vec_acc_ff(q->rsrp, q->cell.nof_ports)/q->cell.nof_ports;
}

@ -1,19 +1,28 @@
/*
* 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,
/**
*
* \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,
* 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/>.
*
* 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/.
*
*/
#include <string.h>

@ -1,19 +1,28 @@
/*
* 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,
/**
*
* \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,
* 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/>.
*
* 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/.
*
*/
#include <string.h>

@ -33,7 +33,7 @@ ADD_TEST(pbch_test_50 pbch_test -p 1 -n 50 -c 50)
ADD_TEST(pbch_test_502 pbch_test -p 2 -n 50 -c 50)
ADD_TEST(pbch_test_504 pbch_test -p 4 -n 50 -c 50)
BuildMex(MEXNAME pbch SOURCES pbch_test_mex.c LIBRARIES lte_phy liblte_mex)
BuildMex(MEXNAME pbch SOURCES pbch_test_mex.c LIBRARIES lte_phy liblte_mex)
########################################################################
@ -49,7 +49,9 @@ ADD_TEST(pcfich_test_64 pcfich_test -p 4 -n 6)
ADD_TEST(pcfich_test_10 pcfich_test -p 1 -n 10)
ADD_TEST(pcfich_test_102 pcfich_test -p 2 -n 10)
ADD_TEST(pcfich_test_104 pcfich_test -p 4 -n 10)
BuildMex(MEXNAME pcfich SOURCES pcfich_test_mex.c LIBRARIES lte_phy liblte_mex)
########################################################################
# PHICH TEST
########################################################################

@ -1,19 +1,28 @@
/*
* 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,
/**
*
* \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,
* 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/>.
*
* 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/.
*
*/
#include <string.h>
@ -32,7 +41,7 @@ extern int indices[2048];
void help()
{
mexErrMsgTxt
("[decoded_ok, symbols, bits] = liblte_pbch(enbConfig, inputSignal)\n\n");
("[decoded_ok, symbols, bits] = liblte_pbch(enbConfig, rxWaveform)\n\n");
}
/* the gateway function */

@ -1,19 +1,28 @@
/*
* 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,
/**
*
* \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,
* 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/>.
*
* 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/.
*
*/
#include <string.h>
@ -41,21 +50,22 @@ const uint32_t nof_common_formats = 2;
void help()
{
mexErrMsgTxt
("[decoded_ok, llr, rm, bits] = liblte_pdcch(enbConfig, RNTI, inputSignal)\n\n");
("[decoded_ok, llr, rm, bits, symbols] = liblte_pdcch(enbConfig, RNTI, rxWaveform)\n\n");
}
/* the gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int i;
int i;
lte_cell_t cell;
pdcch_t pdcch;
chest_dl_t chest;
lte_fft_t fft;
regs_t regs;
dci_location_t locations[MAX_CANDIDATES];
uint32_t cfi, sf_idx;
uint16_t rnti;
cf_t *input_symbols;
cf_t *input_fft, *input_signal;
int nof_re;
uint32_t nof_formats;
dci_format_t *formats = NULL;
@ -78,6 +88,16 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
help();
return;
}
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;
}
rnti = (uint16_t) mxGetScalar(RNTI);
@ -97,23 +117,40 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
/** Allocate input buffers */
nof_re = mexutils_read_cf(INPUT, &input_symbols);
if (nof_re < 0) {
mexErrMsgTxt("Error reading input symbols\n");
return;
if (mexutils_read_cf(INPUT, &input_signal) < 0) {
mexErrMsgTxt("Error reading input signal\n");
return;
}
input_fft = vec_malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
// Set Channel estimates to 1.0 (ignore fading)
cf_t *ce[MAX_PORTS];
for (i=0;i<cell.nof_ports;i++) {
ce[i] = vec_malloc(nof_re * sizeof(cf_t));
for (int j=0;j<nof_re;j++) {
ce[i][j] = 1.0;
}
ce[i] = vec_malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
}
pdcch_extract_llr(&pdcch, input_symbols, ce, 0, sf_idx, cfi);
lte_fft_run_sf(&fft, input_signal, input_fft);
if (nrhs > NOF_INPUTS) {
cf_t *cearray;
mexutils_read_cf(prhs[NOF_INPUTS], &cearray);
for (i=0;i<cell.nof_ports;i++) {
for (int j=0;j<nof_re;j++) {
ce[i][j] = *cearray;
cearray++;
}
}
} else {
chest_dl_estimate(&chest, input_fft, ce, sf_idx);
}
float noise_power;
if (nrhs > NOF_INPUTS + 1) {
noise_power = mxGetScalar(prhs[NOF_INPUTS+1]);
} else {
noise_power = chest_dl_get_noise_estimate(&chest);
}
pdcch_extract_llr(&pdcch, input_fft, ce, noise_power, sf_idx, cfi);
uint32_t nof_locations;
if (rnti == SIRNTI) {
@ -125,8 +162,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
formats = ue_formats;
nof_formats = nof_ue_formats;
}
uint16_t crc_rem;
uint16_t crc_rem=0;
dci_msg_t dci_msg;
bzero(&dci_msg, sizeof(dci_msg_t));
for (int f=0;f<nof_formats;f++) {
for (i=0;i<nof_locations && crc_rem != rnti;i++) {
@ -134,9 +172,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
fprintf(stderr, "Error decoding DCI msg\n");
return;
}
/* mexPrintf("Trying location (%d,%d), %s, CRC: 0x%x\n",
locations[i].ncce, locations[i].L, dci_format_string(formats[f]), crc_rem);
*/
}
}
@ -148,16 +183,20 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexutils_write_f(pdcch.pdcch_llr, &plhs[1], nof_bits, 1);
}
if (nlhs >= 3) {
mexutils_write_f(pdcch.pdcch_rm_f, &plhs[2], 3*(dci_msg.nof_bits+16), 1);
mexutils_write_cf(pdcch.pdcch_symbols[0], &plhs[2], 36*pdcch.nof_cce, 1);
}
chest_dl_free(&chest);
lte_fft_free(&fft);
pdcch_free(&pdcch);
regs_free(&regs);
for (i=0;i<cell.nof_ports;i++) {
free(ce[i]);
}
free(input_symbols);
free(input_signal);
free(input_fft);
return;
}

@ -1,19 +1,28 @@
/*
* 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,
/**
*
* \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,
* 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/>.
*
* 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/.
*
*/
#include <string.h>

@ -1,19 +1,28 @@
/*
* 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,
/**
*
* \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,
* 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/>.
*
* 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/.
*
*/
#include <string.h>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,61 +0,0 @@
clear
NofENB = 1;
for i=1:NofENB
enb = lteTestModel('1.1','5MHz');
enb.TotSubframes = 10;
if (i == 1)
tx_signal = lteTestModelTool(enb);
else
tx_signal = tx_signal + lteTestModelTool(enb);
end
end
corrcfg.PSS='On';
corrcfg.SSS='On';
corrcfg.CellRS='On';
cec = struct; % Channel estimation config structure
cec.PilotAverage = 'UserDefined'; % Type of pilot symbol averaging
cec.FreqWindow = 9; % Frequency window size
cec.TimeWindow = 9; % Time window size
cec.InterpType = 'Linear'; % 2D interpolation type
cec.InterpWindow = 'Centered'; % Interpolation window type
cec.InterpWinSize = 1; % Interpolation window size
addpath('../../debug/lte/phy/lib/sync/test')
addpath('../../debug/lte/phy/lib/ch_estimation/test')
%tx_signal = signal;
enb = struct('NDLRB',6,'CyclicPrefix','Normal','DuplexMode','FDD');
[cellid, offset] = lteCellSearch(enb, tx_signal,1);
enb.NCellID=cellid;
disp(offset)
enb.NSubframe = 0;
rxWaveform = tx_signal(1+offset:end,:);
rxGrid = lteOFDMDemodulate(enb,rxWaveform);
enb.CellRefP = 4;
[hest, nest] = lteDLChannelEstimate(enb,cec,rxGrid);
griddims = lteResourceGridSize(enb); % Resource grid dimensions
L = griddims(2);
pbchIndices = ltePBCHIndices(enb);
[pbchRx, pbchHest] = lteExtractResources( ...
pbchIndices, rxGrid(:,1:L,:), hest(:,1:L,:,:));
% Decode PBCH
[bchBits, pbchSymbols, nfmod4, mib, enb.CellRefP] = ltePBCHDecode( ...
enb, pbchRx, pbchHest, nest);
% Parse MIB bits
enb = lteMIB(mib, enb)
%plot(angle(hest(:,[1 4],1,1)));

@ -1,105 +0,0 @@
%% PDCCH Blind Search and DCI Decoding
%% Cell-Wide Settings
% A structure |enbConfig| is used to configure the eNodeB.
Npackets = 1;
SNR_values =20;%linspace(-5,3,8);
enbConfig.NDLRB = 15; % No of Downlink RBs in total BW
enbConfig.CyclicPrefix = 'Normal'; % CP length
enbConfig.CFI = 3; ; % 4 PDCCH symbols as NDLRB <= 10
enbConfig.Ng = 'Sixth'; % HICH groups
enbConfig.CellRefP = 2; % 1-antenna ports
enbConfig.NCellID = 10; % Physical layer cell identity
enbConfig.NSubframe = 0; % Subframe number 0
enbConfig.DuplexMode = 'FDD'; % Frame structure
enbConfig.PHICHDuration = 'Normal';
%% DCI Message Generation
% Generate a DCI message to be mapped to the PDCCH.
dciConfig.DCIFormat = 'Format1A'; % DCI message format
dciConfig.Allocation.RIV = 26; % Resource indication value
% Create DCI message for given configuration
[dciMessage, dciMessageBits] = lteDCI(enbConfig, dciConfig);
%% DCI Channel Coding
C_RNTI = 65535; % 16-bit UE-specific mask
pdcchConfig.RNTI = C_RNTI; % Radio network temporary identifier
pdcchConfig.PDCCHFormat = 3; % PDCCH format
% DCI message bits coding to form coded DCI bits
codedDciBits = lteDCIEncode(pdcchConfig, dciMessageBits);
%% PDCCH Bits Generation
pdcchDims = ltePDCCHInfo(enbConfig);
% Initialize elements with -1 to indicate that all the bits are unused
pdcchBits = -1*ones(pdcchDims.MTot, 1);
% Perform search space for UE-specific control channel candidates.
candidates = ltePDCCHSpace(enbConfig, pdcchConfig, {'bits', '1based'});
Ncad=randi(length(candidates),1,1);
% Map PDCCH payload on available UE-specific candidate. In this example the
% first available candidate is used to map the coded DCI bits.
pdcchBits ( candidates(Ncad, 1) : candidates(Ncad, 2) ) = codedDciBits;
%% PDCCH Complex-Valued Modulated Symbol Generation
pdcchSymbols = ltePDCCH(enbConfig, pdcchBits);
pdcchIndices = ltePDCCHIndices(enbConfig,{'1based'});
decoded = zeros(size(SNR_values));
decoded_liblte = zeros(size(SNR_values));
Nports = enbConfig.CellRefP;
ueConfig.RNTI = C_RNTI;
subframe_tx = lteDLResourceGrid(enbConfig);
subframe_tx(pdcchIndices) = pdcchSymbols;
addpath('../../debug/lte/phy/lib/phch/test')
for snr_idx=1:length(SNR_values)
SNRdB = SNR_values(snr_idx);
for i=1:Npackets
%% Noise Addition
SNR = 10^(SNRdB/10); % Linear SNR
N0 = 1/(sqrt(2.0*Nports)*SNR);
noise = N0*complex(randn(size(subframe_tx)), randn(size(subframe_tx))); % Generate noise
subframe_rx = sum(subframe_tx + noise,3); % Add noise to PDCCH symbols
pdcchSymbolsNoisy = subframe_rx(pdcchIndices(:,1));
%% PDCCH Decoding
recPdcchBits = ltePDCCHDecode(enbConfig, pdcchSymbolsNoisy);
%% Blind Decoding using DCI Search
[rxDCI, rxDCIBits] = ltePDCCHSearch(enbConfig, ueConfig, recPdcchBits);
decoded(snr_idx) = decoded(snr_idx) + length(rxDCI);
[found_liblte, llr, viterbi_in] = liblte_pdcch(enbConfig, ueConfig.RNTI, subframe_rx);
decoded_liblte(snr_idx) = decoded_liblte(snr_idx)+found_liblte;
end
fprintf('SNR: %.1f\n',SNRdB)
end
if (Npackets>1)
plot(SNR_values,1-decoded/Npackets,SNR_values,1-decoded_liblte/Npackets)
grid on
legend('Matlab','libLTE')
else
disp(decoded_liblte)
end

@ -1,102 +0,0 @@
%clear
rmc = lteRMCDL('R.10');
NofPortsTx=2;
SNR_values_db=linspace(-6,0,4);
Nrealizations=50;
enb = struct('NCellID',0,'NDLRB',50,'CellRefP',NofPortsTx,'CyclicPrefix','Normal','DuplexMode','FDD','NSubframe',0);
cfg.Seed = 8; % Random channel seed
cfg.NRxAnts = 1; % 1 receive antenna
cfg.DelayProfile = 'EVA'; % EVA delay spread
cfg.DopplerFreq = 120; % 120Hz Doppler frequency
cfg.MIMOCorrelation = 'Low'; % Low (no) MIMO correlation
cfg.InitTime = 0; % Initialize at time zero
cfg.NTerms = 16; % Oscillators used in fading model
cfg.ModelType = 'GMEDS'; % Rayleigh fading model type
cfg.InitPhase = 'Random'; % Random initial phases
cfg.NormalizePathGains = 'On'; % Normalize delay profile power
cfg.NormalizeTxAnts = 'On'; % Normalize for transmit antennas
cec.PilotAverage = 'UserDefined'; % Type of pilot averaging
cec.FreqWindow = 9; % Frequency window size
cec.TimeWindow = 9; % Time window size
cec.InterpType = 'linear'; % 2D interpolation type
cec.InterpWindow = 'Centered'; % Interpolation window type
cec.InterpWinSize = 1; % Interpolation window size
rmc.PDSCH.Modulation = '16QAM';
[waveform,rgrid,info] = lteRMCDLTool(rmc,[1;0;0;1]);
cfg.SamplingRate = info.SamplingRate;
addpath('../../debug/lte/phy/lib/phch/test')
error=zeros(length(SNR_values_db),2);
for snr_idx=1:length(SNR_values_db)
SNRdB = SNR_values_db(snr_idx); % Desired SNR in dB
SNR = 10^(SNRdB/20); % Linear SNR
errorReal = zeros(Nrealizations,2);
for i=1:Nrealizations
griddims = lteResourceGridSize(enb); % Resource grid dimensions
L = griddims(2);
rxWaveform = lteFadingChannel(cfg,waveform(:,1));
%% Additive Noise
N0 = 1/(sqrt(2.0*double(enb.CellRefP)*double(info.Nfft))*SNR);
% Create additive white Gaussian noise
noise = N0*complex(randn(size(rxWaveform)),randn(size(rxWaveform)));
rxWaveform = noise + rxWaveform;
% rxWaveform = downsampled;
% Number of OFDM symbols in a subframe
% OFDM demodulate signal
rxgrid = lteOFDMDemodulate(enb, rxWaveform);
% Perform channel estimation
[hest, nest] = lteDLChannelEstimate(enb, cec, rxgrid(:,1:L,:));
pbchIndices = ltePBCHIndices(enb);
[pbchRx, pbchHest] = lteExtractResources( ...
pbchIndices, rxgrid(:,1:L,:), hest(:,1:L,:,:));
% Decode PBCH
[bchBits, pbchSymbols, nfmod4, mib, nof_ports] = ltePBCHDecode( ...
enb, pbchRx, pbchHest, nest);
if (nof_ports ~= NofPortsTx)
errorReal(i,1)=1;
end
[nof_ports2, pbchSymbols2, pbchBits, ce, ce2, pbchRx2, pbchHest2,indices]=...
liblte_pbch(enb, rxWaveform, hest, nest);
if (nof_ports2 ~= NofPortsTx)
errorReal(i,2)=1;
end
% if (errorReal(i,1) ~= errorReal(i,2))
% i=1;
% end
end
error(snr_idx,:) = sum(errorReal);
fprintf('SNR: %.2f dB\n', SNR_values_db(snr_idx));
end
if (length(SNR_values_db) > 1)
plot(SNR_values_db, 1-error/Nrealizations)
grid on
xlabel('SNR (dB)');
ylabel('Pdet')
legend('Matlab','libLTE')
else
disp(error)
end

@ -1,76 +0,0 @@
filename='../../debug/dist_ra.dat';
enb.NDLRB = 50;
enb.CyclicPrefix = 'Normal';
enb.PHICHDuration = 'Normal';
enb.CFI = 2;
enb.Ng = 'Sixth';
enb.CellRefP = 1;
enb.NCellID = 196;
enb.NSubframe = 5;
enb.NTotalSubframes=1;
enb.DuplexMode = 'FDD';
dci.NDLRB = enb.NDLRB;
dci.DCIFormat = 'Format1C';
dci.AllocationType=1;
%dci.Allocation.Bitmap='01111000011110000';
%dci.Allocation.Subset=3;
dci.Allocation.RIV = 33;
dci.Allocation.Gap = 0;
dci.ModCoding=6;
dci.RV=0;
dci.DuplexMode = enb.DuplexMode;
dci.NTxAnts = enb.CellRefP;
pdcch.RNTI = 65535;
pdcch.PDCCHFormat = 3;
pdsch.Modulation='QPSK';
pdsch.RNTI=pdcch.RNTI;
if (enb.CellRefP == 1)
pdsch.TxScheme='Port0';
else
pdsch.TxScheme='TxDiversity';
end
pdsch.NLayers=enb.CellRefP;
pdsch.trblklen=176;
pdsch.RV=dci.RV;
% Begin frame generation
subframe = lteDLResourceGrid(enb);
%%% Create Reference Signals
rsAnt = lteCellRS(enb);
indAnt = lteCellRSIndices(enb);
subframe(indAnt) = rsAnt;
%%% Create PDCCH
[dciMessage,dciMessageBits] = lteDCI(enb,dci);
codedDciBits = lteDCIEncode(pdcch,dciMessageBits);
pdcchInfo = ltePDCCHInfo(enb);
pdcchBits = -1*ones(1,pdcchInfo.MTot);
candidates = ltePDCCHSpace(enb,pdcch,{'bits','1based'});
pdcchBits (candidates(1,1):candidates(1,2)) = codedDciBits;
pdcchSymbols = ltePDCCH(enb, pdcchBits);
pdcchIndices = ltePDCCHIndices(enb,{'1based'});
subframe(pdcchIndices) = pdcchSymbols;
% Create PDSCH
pdsch.prbset = lteDCIResourceAllocation(enb,dci);
[pdschIndices,pdschInfo] = ltePDSCHIndices(enb,pdsch,pdsch.prbset);
dlschTransportBlk=randi([0 1],pdsch.trblklen,1);
pdschcodeword = lteDLSCH(enb,pdsch,pdschInfo.G,dlschTransportBlk);
%crced = lteCRCEncode(dlschTransportBlk, '24A');
%encoded = lteTurboEncode(crced);
%pdschcodeword2 = lteRateMatchTurbo(encoded,pdschInfo.G,pdsch.RV);
pdschSymbols = ltePDSCH(enb,pdsch,pdschcodeword);
subframe(pdschIndices) = pdschSymbols;
txwaveform = lteOFDMModulate(enb,subframe);
write_complex(filename,sum(txwaveform,2));
fprintf('Written signal to %s\n',filename);

@ -1,144 +0,0 @@
SNR_values = linspace(-6,4,10);
Npackets = 200;
CFO=4/15;
m0=7;
m1=10;
%m0=26;
%m1=21;
recordedWaveform = x;
if (~isempty(recordedWaveform))
Npackets = floor(length(recordedWaveform)/19200)-1;
SNR_values = 0;
end
error = zeros(6,length(SNR_values));
enb = struct('NCellID',2,'NSubframe',0,'NDLRB',6,'CellRefP',1,'CyclicPrefix','Normal','DuplexMode','FDD');
sss=lteSSS(enb);
cfg.Seed = 2; % Random channel seed
cfg.NRxAnts = 1; % 1 receive antenna
cfg.DelayProfile = 'ETU'; % EVA delay spread
cfg.DopplerFreq = 144; % 120Hz Doppler frequency
cfg.MIMOCorrelation = 'Low'; % Low (no) MIMO correlation
cfg.NTerms = 16; % Oscillators used in fading model
cfg.ModelType = 'GMEDS'; % Rayleigh fading model type
cfg.InitPhase = 'Random'; % Random initial phases
cfg.NormalizePathGains = 'On'; % Normalize delay profile power
cfg.NormalizeTxAnts = 'On'; % Normalize for transmit antennas % Initialize at time zero
[s, c0, c1] = get_sc(mod(enb.NCellID,3));
subframe = lteDLResourceGrid(enb);
sssSym = lteSSS(enb);
sssInd = lteSSSIndices(enb);
subframe(sssInd) = sssSym;
N_id_1 = floor(enb.NCellID/3);
[txWaveform,info] = lteOFDMModulate(enb,subframe);
cfg.SamplingRate = info.SamplingRate;
fftSize = info.Nfft;
addpath('../../debug/lte/phy/lib/sync/test')
for snr_idx=1:length(SNR_values)
SNRdB = SNR_values(snr_idx);
for i=1:Npackets
%% Noise Addition
SNR = 10^(SNRdB/10); % Linear SNR
if (isempty(recordedWaveform))
cfg.InitTime = i*(10^-3);
[rxWaveform, info]= lteFadingChannel(cfg,txWaveform);
rxWaveform = txWaveform;
% Add CFO
freq = CFO/double(fftSize);
rxWaveform = rxWaveform.*exp(1i*2*pi*freq*(1:length(txWaveform))');
N0 = 1/(sqrt(2.0*enb.CellRefP*double(fftSize))*SNR);
noise = N0*complex(randn(size(rxWaveform)), randn(size(rxWaveform))); % Generate noise
rxWaveform = rxWaveform + noise;
else
rxWaveform = recordedWaveform(i*19200+1:(i+1)*19200);
end
offset = lteDLFrameOffset(enb,rxWaveform);
offsetVec(i)=offset;
rxWaveform = [rxWaveform(1+offset:end,:); zeros(offset,1)];
subframe_rx = lteOFDMDemodulate(enb,rxWaveform,1);
sss_rx = subframe_rx(lteSSSIndices(enb));
sss0=sss_rx(1:2:end);
sss1=sss_rx(2:2:end);
beta0=sss0.*c0';
beta1=sss1.*c1';
corr0=zeros(31,1);
for m=1:31
corr0(m)=sum(beta0.*s(m,:)');
end
corr0=abs(corr0).^2;
[m, idx]=max(corr0);
error(1,snr_idx) = error(1,snr_idx) + ((idx ~= m0 && idx ~= m1));
M=2;
Nm=10;
corr2=zeros(31,1);
for m=1:31
for j=0:M
idx=1+j*Nm:(j+1)*Nm;
corr2(m)=corr2(m)+abs(sum(beta0(idx).*s(m,idx)')).^2;
end
end
[m, idx]=max(corr2);
error(2,snr_idx) = error(2,snr_idx) + ((idx ~= m0 && idx ~= m1));
corr3=zeros(31,1);
for m=1:31
corr3(m)=abs(sum(beta0(2:end).*conj(beta0(1:end-1)).*transpose(s(m,2:end).*conj(s(m,1:end-1))))).^2;
end
[m, idx]=max(corr3);
error(3,snr_idx) = error(3,snr_idx) + ((idx ~= m0 && idx ~= m1));
% libLTE results
[n,sf_idx,lt_corr0]=liblte_sss(enb,rxWaveform,'full');
[m, idx]=max(lt_corr0);
error(4,snr_idx) = error(4,snr_idx) + ((idx ~= m0 && idx ~= m1));
[n,sf_idx,lt_corr2]=liblte_sss(enb,rxWaveform,'partial');
[m, idx]=max(lt_corr2);
error(5,snr_idx) = error(5,snr_idx) + ((idx ~= m0 && idx ~= m1));
[n,sf_idx,lt_corr3]=liblte_sss(enb,rxWaveform,'diff');
[m, idx]=max(lt_corr3);
error(6,snr_idx) = error(6,snr_idx) + ((idx ~= m0 && idx ~= m1));
end
end
if (length(SNR_values) > 1)
plot(SNR_values,1-error/Npackets)
legend('Full','Partial','Differential','Full-lt','Partial-lt','Differential-lt')
grid on
else
e=error/Npackets;
fprintf('Full (mt/lt): \t%f/%f\n',e(1),e(4));
fprintf('Partial (mt/lt):%f/%f\n',e(2),e(5));
fprintf('Diff (mt/lt): \t%f/%f\n',e(3),e(6));
end

@ -1,49 +0,0 @@
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
Loading…
Cancel
Save