From 540eb98fdb79927ef5c4ac680de340ffe76bc678 Mon Sep 17 00:00:00 2001 From: ismagom Date: Mon, 1 Dec 2014 22:09:30 +0000 Subject: [PATCH] Added PSS mex test --- lte/phy/lib/sync/test/CMakeLists.txt | 2 + lte/phy/lib/sync/test/pss_mex.c | 87 ++++++++++++++++++++++++++++ matlab/tests/sync_test.m | 22 +++++-- 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 lte/phy/lib/sync/test/pss_mex.c diff --git a/lte/phy/lib/sync/test/CMakeLists.txt b/lte/phy/lib/sync/test/CMakeLists.txt index d9f8c49b3..285bd5a21 100644 --- a/lte/phy/lib/sync/test/CMakeLists.txt +++ b/lte/phy/lib/sync/test/CMakeLists.txt @@ -29,6 +29,8 @@ IF(${CUHD_FIND} GREATER -1) TARGET_LINK_LIBRARIES(pss_usrp lte_phy cuhd) ENDIF(${CUHD_FIND} GREATER -1) +BuildMex(MEXNAME pss SOURCES pss_mex.c LIBRARIES lte_phy liblte_mex) + ######################################################################## # SYNC TEST ######################################################################## diff --git a/lte/phy/lib/sync/test/pss_mex.c b/lte/phy/lib/sync/test/pss_mex.c new file mode 100644 index 000000000..4a1c9dda0 --- /dev/null +++ b/lte/phy/lib/sync/test/pss_mex.c @@ -0,0 +1,87 @@ +/* + * 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 + ("[offset,corr] = liblte_pss(enbConfig, inputSignal)\n\n"); +} + +/* the gateway function */ +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) +{ + + int i; + lte_cell_t cell; + pss_synch_t pss; + cf_t *input_symbols; + int frame_len; + + if (nrhs != NOF_INPUTS) { + help(); + return; + } + + if (mexutils_read_cell(ENBCFG, &cell)) { + help(); + return; + } + + /** Allocate input buffers */ + frame_len = mexutils_read_cf(INPUT, &input_symbols); + if (frame_len < 0) { + mexErrMsgTxt("Error reading input symbols\n"); + return; + } + + if (pss_synch_init_fft(&pss, frame_len, lte_symbol_sz(cell.nof_prb))) { + fprintf(stderr, "Error initiating PSS\n"); + exit(-1); + } + if (pss_synch_set_N_id_2(&pss, cell.id%2)) { + fprintf(stderr, "Error setting N_id_2=%d\n",cell.id%2); + exit(-1); + } + + int peak_idx = pss_synch_find_pss(&pss, input_symbols, NULL); + + if (nlhs >= 1) { + plhs[0] = mxCreateLogicalScalar(peak_idx); + } + if (nlhs >= 2) { + mexutils_write_cf(pss.conv_output, &plhs[1], frame_len, 1); + } + + pss_synch_free(&pss); + free(input_symbols); + + return; +} + diff --git a/matlab/tests/sync_test.m b/matlab/tests/sync_test.m index d91320aeb..005b20b67 100644 --- a/matlab/tests/sync_test.m +++ b/matlab/tests/sync_test.m @@ -1,32 +1,44 @@ enb = lteTestModel('1.1','5MHz'); Ntrials = 1; -SNR_values =-10;%linspace(-18,-10,8); +SNR_values =-20;%linspace(-18,-10,8); tx_offset = randi(50,Ntrials,1); -tx_offset = 50; diff=zeros(size(SNR_values)); +diff_lt=zeros(size(SNR_values)); tx_signal = lteTestModelTool(enb); tx_power = mean(tx_signal.*conj(tx_signal)); +corrcfg.PSS='On'; +corrcfg.SSS='On'; +corrcfg.CellRS='Off'; + +addpath('../../debug/lte/phy/lib/sync/test') + for snr_idx=1:length(SNR_values) SNRdB = SNR_values(snr_idx); rx_offset = zeros(size(tx_offset)); + rx_offset_lt = zeros(size(tx_offset)); for i=1:Ntrials SNR = 10^(SNRdB/10); % Linear SNR tx = [zeros(tx_offset(i),1); tx_signal]; N0 = tx_power/(sqrt(2.0)*SNR); noise = N0*complex(randn(size(tx)), randn(size(tx))); % Generate noise rx=noise+tx; - [rx_offset(i),corr] = lteDLFrameOffset(enb,rx); + [rx_offset(i),corr] = lteDLFrameOffset(enb,rx,corrcfg); + [rx_offset_lt(i),corr_lt] = liblte_pss(enb,rx); end diff(snr_idx)=sum(abs(rx_offset-tx_offset)); + diff_lt(snr_idx)=sum(abs(rx_offset_lt-tx_offset)); disp(SNRdB) end if (Ntrials == 1) - plot(corr) + len=1:length(corr)-rx_offset(i)-3840; + len2=rx_offset(i)+1+3840:length(corr); + plot(len,corr(len)/max(corr(len)),... + len,abs(corr_lt(len2))/max(abs(corr_lt(len2)))); else - plot(SNR_values,diff); + plot(SNR_values,diff,SNR_values,diff_lt); end