Merge branch 'master' into uplink

This commit is contained in:
Ismael Gomez 2016-06-29 13:32:59 +02:00
commit 3e29960a79
6 changed files with 326 additions and 30 deletions

132
matlab/tests/phich_bler.m Normal file
View File

@ -0,0 +1,132 @@
clear
%% PHICH encoding/decoding
%% Setup simulation
Npackets = 80;
SNR_values = linspace(-6,0,6);
enable_fading=false;
addpath('../../debug/srslte/lib/phch/test')
%% Cell-Wide Settings
enbConfig.NDLRB = 50; % No of Downlink RBs in total BW
enbConfig.CyclicPrefix = 'Normal'; % CP length
enbConfig.Ng = 'One'; % HICH groups
enbConfig.CellRefP = 1; % 1-antenna ports
enbConfig.NCellID = 36; % Physical layer cell identity
enbConfig.NSubframe = 5; % Subframe number 0
enbConfig.DuplexMode = 'FDD'; % Frame structure
enbConfig.PHICHDuration = 'Normal';
%% Define HI resource
hi_res = [1 1];
ack_bit = 1;
%% Setup Fading channel model
if (enable_fading)
cfg.Seed = 8; % Random channel seed
cfg.NRxAnts = 1; % 1 receive antenna
cfg.DelayProfile = 'EPA'; % EVA delay spread
cfg.DopplerFreq = 5; % 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
end
% Setup channel equalizer
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 = 'Causal'; % Interpolation window type
cec.InterpWinSize = 1; % Interpolation window size
%% Generate TX subframe
subframe_tx = lteDLResourceGrid(enbConfig);
%% Genearte PHICH signal
hi_sym_tx = ltePHICH(enbConfig, [hi_res ack_bit]);
hi_indices = ltePHICHIndices(enbConfig);
subframe_tx(hi_indices)=hi_sym_tx;
%% Add references to subframe
cellRsSym = lteCellRS(enbConfig);
cellRsInd = lteCellRSIndices(enbConfig);
subframe_tx(cellRsInd) = cellRsSym;
%% Modulate signal
[txWaveform, info] = lteOFDMModulate(enbConfig,subframe_tx);
cfg.SamplingRate = info.SamplingRate;
%% Start simulation
decoded = zeros(size(SNR_values));
decoded_srslte = zeros(size(SNR_values));
for snr_idx=1:length(SNR_values)
SNRdB = SNR_values(snr_idx);
SNR = 10^(SNRdB/10); % Linear SNR
N0 = 1/(sqrt(2.0*enbConfig.CellRefP*double(info.Nfft))*SNR);
for i=1:Npackets
%% Fading
rxWaveform = sum(txWaveform,2);
if (enable_fading)
rxWaveform = lteFadingChannel(cfg,rxWaveform);
end
%% Noise Addition
noise = N0*complex(randn(size(rxWaveform)), randn(size(rxWaveform)));
rxWaveform = rxWaveform + noise;
%% Demodulate
subframe_rx = lteOFDMDemodulate(enbConfig, rxWaveform);
%% Channel estimation
if (enable_fading)
[hest, nest] = lteDLChannelEstimate(enbConfig, cec, subframe_rx);
else
hest=ones(size(subframe_rx));
nest=0;
end
%% Extract resources
phichSymbolsRx = subframe_rx(hi_indices);
phichSymbolsHest = hest(hi_indices);
%% PHICH decoding
[hi, hi_symbols] = ltePHICHDecode(enbConfig,hi_res, phichSymbolsRx, phichSymbolsHest, nest);
decoded(snr_idx) = decoded(snr_idx) + (hi == ack_bit);
%% Same with srsLTE
[hi_srslte, hi_symbols_srslte] = srslte_phich(enbConfig, hi_res, subframe_rx, hest, nest);
decoded_srslte(snr_idx) = decoded_srslte(snr_idx) + (hi_srslte == ack_bit);
end
fprintf('SNR: %.1f\n',SNRdB)
end
if (Npackets>1)
semilogy(SNR_values,1-decoded/Npackets,'bo-',...
SNR_values,1-decoded_srslte/Npackets, 'ro-')
grid on
legend('Matlab','srsLTE')
xlabel('SNR (dB)')
ylabel('BLER')
axis([min(SNR_values) max(SNR_values) 1/Npackets/10 1])
else
scatter(real(hi_symbols),imag(hi_symbols))
hold on
scatter(real(hi_symbols_srslte),imag(hi_symbols_srslte))
hold off
grid on;
axis([-2 2 -2 2])
disp(hi)
disp(hi_srslte)
end

View File

@ -70,6 +70,7 @@ add_test(phich_test_10 phich_test -p 1 -n 10 -e)
add_test(phich_test_102 phich_test -p 2 -n 10 -g 2)
add_test(phich_test_104 phich_test -p 4 -n 10 -e -l -g 1/2)
BuildMex(MEXNAME phich SOURCES phich_test_mex.c LIBRARIES srslte_static srslte_mex)
########################################################################
# PDCCH TEST

View File

@ -38,7 +38,7 @@
void help()
{
mexErrMsgTxt
("[cfi] = srslte_pdcch(enbConfig, rxWaveform)\n\n");
("[cfi] = srslte_pcfich(enbConfig, rxWaveform)\n\n");
}
/* the gateway function */

View File

@ -0,0 +1,173 @@
/**
*
* \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 <string.h>
#include "srslte/srslte.h"
#include "srslte/mex/mexutils.h"
/** MEX function to be called from MATLAB to test the channel estimator
*/
#define ENBCFG prhs[0]
#define HIRES prhs[1]
#define INPUT prhs[2]
#define NOF_INPUTS 3
void help()
{
mexErrMsgTxt
("[hi, symbols] = srslte_phich(enbConfig, hires, input_signal, [hest, nest])\n\n");
}
/* the gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int i;
srslte_cell_t cell;
srslte_phich_t phich;
srslte_chest_dl_t chest;
srslte_ofdm_t ofdm_rx;
srslte_regs_t regs;
uint32_t sf_idx;
cf_t *input_fft, *input_signal;
if (nrhs < NOF_INPUTS) {
help();
return;
}
if (mexutils_read_cell(ENBCFG, &cell)) {
help();
return;
}
if (mexutils_read_uint32_struct(ENBCFG, "NSubframe", &sf_idx)) {
help();
return;
}
if (srslte_chest_dl_init(&chest, cell)) {
mexErrMsgTxt("Error initializing equalizer\n");
return;
}
if (srslte_ofdm_rx_init(&ofdm_rx, cell.cp, cell.nof_prb)) {
mexErrMsgTxt("Error initializing FFT\n");
return;
}
if (srslte_regs_init(&regs, cell)) {
mexErrMsgTxt("Error initiating regs\n");
return;
}
if (srslte_phich_init(&phich, &regs, cell)) {
mexErrMsgTxt("Error creating PHICH object\n");
return;
}
// Read input signal
input_signal = NULL;
int insignal_len = mexutils_read_cf(INPUT, &input_signal);
if (insignal_len < 0) {
mexErrMsgTxt("Error reading input signal\n");
return;
}
if (insignal_len == SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp)) {
input_fft = input_signal;
} else {
input_fft = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
srslte_ofdm_rx_sf(&ofdm_rx, input_signal, input_fft);
free(input_signal);
}
cf_t *ce[SRSLTE_MAX_PORTS];
for (i=0;i<cell.nof_ports;i++) {
ce[i] = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
}
if (nrhs > NOF_INPUTS) {
cf_t *cearray = NULL;
mexutils_read_cf(prhs[NOF_INPUTS], &cearray);
cf_t *cearray_ptr = cearray;
for (i=0;i<cell.nof_ports;i++) {
for (int j=0;j<SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp);j++) {
ce[i][j] = *cearray_ptr;
cearray_ptr++;
}
}
if (cearray) {
free(cearray);
}
} else {
srslte_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 if (nrhs > NOF_INPUTS) {
noise_power = 0;
} else {
noise_power = srslte_chest_dl_get_noise_estimate(&chest);
}
// Read hires values
float *hires = NULL;
int nhires = mexutils_read_f(HIRES, &hires);
if (nhires != 2) {
mexErrMsgTxt("Expecting 2 values for hires parameter\n");
return;
}
uint32_t ngroup = (uint32_t) hires[0];
uint32_t nseq = (uint32_t) hires[1];
uint8_t ack;
float corr_res;
int n = srslte_phich_decode(&phich, input_fft, ce, noise_power, ngroup, nseq, sf_idx, &ack, &corr_res);
if (nlhs >= 1) {
if (n < 0) {
plhs[0] = mxCreateDoubleScalar(-1);
} else {
plhs[0] = mxCreateDoubleScalar(ack);
}
}
if (nlhs >= 2) {
mexutils_write_cf(phich.z, &plhs[1], 1, SRSLTE_PHICH_NBITS);
}
srslte_chest_dl_free(&chest);
srslte_ofdm_rx_free(&ofdm_rx);
srslte_phich_free(&phich);
srslte_regs_free(&regs);
for (i=0;i<cell.nof_ports;i++) {
free(ce[i]);
}
free(input_fft);
return;
}

View File

@ -241,18 +241,30 @@ int rf_uhd_open(char *args, void **h)
uhd_string_vector_make(&devices_str);
uhd_usrp_find("", &devices_str);
char args2[512];
// Allow NULL parameter
if (args == NULL) {
args = "";
}
}
/* If device type or name not given in args, choose a B200 */
if (args[0]=='\0') {
// If B200 is available, use it
if (find_string(devices_str, "type=b200") && !strstr(args, "recv_frame_size")) {
args = "type=b200,recv_frame_size=9232,send_frame_size=9232";
// If B200 is available, use it
args = "type=b200,recv_frame_size=9232,send_frame_size=9232";
} else if (find_string(devices_str, "type=x300")) {
// Else if X300 is available, set master clock rate now (can't be changed later)
args = "type=x300,master_clock_rate=184.32e6";
handler->dynamic_rate = false;
}
}
} else {
// If args is set and x300 type is specified, make sure master_clock_rate is defined
if (strstr(args, "type=x300") && !strstr(args, "master_clock_rate")) {
sprintf(args2, "%s,master_clock_rate=184.32e6",args);
args = args2;
handler->dynamic_rate = false;
}
}
/* Create UHD handler */
printf("Opening USRP with args: %s\n", args);
@ -261,7 +273,7 @@ int rf_uhd_open(char *args, void **h)
fprintf(stderr, "Error opening UHD: code %d\n", error);
return -1;
}
size_t channel = 0;
uhd_stream_args_t stream_args = {
.cpu_format = "fc32",
@ -301,28 +313,6 @@ int rf_uhd_open(char *args, void **h)
uhd_rx_metadata_make(&handler->rx_md_first);
uhd_tx_metadata_make(&handler->tx_md, false, 0, 0, false, false);
/* Find out if the master clock rate is configurable */
double cur_clock, new_clock;
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &cur_clock);
printf("Trying to dynamically change Master clock...\n");
uhd_usrp_set_master_clock_rate(handler->usrp, cur_clock/2, 0);
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &new_clock);
if (new_clock == cur_clock) {
handler->dynamic_rate = false;
/* Master clock rate is not configurable. Check if it is compatible with LTE */
int cur_clock_i = (int) cur_clock;
if (cur_clock_i % 1920000) {
fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6);
return -1;
} else {
printf("Master clock is not configurable. Using standard symbol sizes and sampling rates.\n");
srslte_use_standard_symbol_size(true);
}
} else {
printf("Master clock is configurable. Using reduced symbol sizes and sampling rates.\n");
handler->dynamic_rate = true;
}
return 0;
} else {
return SRSLTE_ERROR_INVALID_INPUTS;

View File

@ -440,7 +440,7 @@ bool srslte_ue_dl_decode_phich(srslte_ue_dl_t *q, uint32_t sf_idx, uint32_t n_pr
fprintf(stderr, "Error decoding PHICH\n");
return false;
}
if (ack_bit && distance > 1.5) {
if (ack_bit) {
return true;
} else {
return false;