From 204fa8514438a85e56f4a4af6ab1e265196ea45a Mon Sep 17 00:00:00 2001 From: ismagom Date: Mon, 15 Dec 2014 23:34:44 +0000 Subject: [PATCH] Added MEX tests for PBCH and Viterbi --- lte/phy/include/liblte/phy/common/fft.h | 2 ++ lte/phy/include/liblte/phy/fec/viterbi.h | 4 ++++ lte/phy/lib/ch_estimation/src/chest_dl.c | 3 ++- lte/phy/lib/common/src/fft.c | 4 +++- lte/phy/lib/fec/src/viterbi.c | 8 +++++++- lte/phy/lib/fec/src/viterbi37_port.c | 3 +-- lte/phy/lib/fec/test/CMakeLists.txt | 2 ++ lte/phy/lib/mimo/src/precoding.c | 2 ++ lte/phy/lib/phch/test/CMakeLists.txt | 2 ++ matlab/tests/pdcch_test.m | 6 +++--- mex/include/liblte/mex/mexutils.h | 5 +++++ mex/lib/mexutils.c | 12 ++++++++++++ 12 files changed, 45 insertions(+), 8 deletions(-) diff --git a/lte/phy/include/liblte/phy/common/fft.h b/lte/phy/include/liblte/phy/common/fft.h index 3e20c475f..e9e2f781e 100644 --- a/lte/phy/include/liblte/phy/common/fft.h +++ b/lte/phy/include/liblte/phy/common/fft.h @@ -37,6 +37,8 @@ #include "liblte/phy/common/phy_common.h" #include "liblte/phy/utils/dft.h" +//#define LTE_FFT_NORMALIZE + typedef _Complex float cf_t; /* this is only a shortcut */ /* This is common for both directions */ diff --git a/lte/phy/include/liblte/phy/fec/viterbi.h b/lte/phy/include/liblte/phy/fec/viterbi.h index e3d8a9f59..5141ccf1a 100644 --- a/lte/phy/include/liblte/phy/fec/viterbi.h +++ b/lte/phy/include/liblte/phy/fec/viterbi.h @@ -42,6 +42,7 @@ typedef struct LIBLTE_API{ uint32_t K; uint32_t framebits; bool tail_biting; + float gain_quant; uint32_t poly[3]; int (*decode) (void*, uint8_t*, uint8_t*, uint32_t); void (*free) (void*); @@ -55,6 +56,9 @@ LIBLTE_API int viterbi_init(viterbi_t *q, uint32_t max_frame_length, bool tail_bitting); +LIBLTE_API void viterbi_set_gain_quant(viterbi_t *q, + float gain_quant); + LIBLTE_API void viterbi_free(viterbi_t *q); LIBLTE_API int viterbi_decode_f(viterbi_t *q, diff --git a/lte/phy/lib/ch_estimation/src/chest_dl.c b/lte/phy/lib/ch_estimation/src/chest_dl.c index 5a9c2e5b7..b8fed7838 100644 --- a/lte/phy/lib/ch_estimation/src/chest_dl.c +++ b/lte/phy/lib/ch_estimation/src/chest_dl.c @@ -115,7 +115,8 @@ 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.15, 0.7, 0.15}; + float f[3]={0.2, 0.6, 0.2}; chest_dl_set_filter_freq(q, f, 3); float t[2]={0.1, 0.9}; diff --git a/lte/phy/lib/common/src/fft.c b/lte/phy/lib/common/src/fft.c index b5818c979..3a13782b4 100644 --- a/lte/phy/lib/common/src/fft.c +++ b/lte/phy/lib/common/src/fft.c @@ -53,8 +53,10 @@ int lte_fft_init_(lte_fft_t *q, lte_cp_t cp, uint32_t nof_prb, dft_dir_t dir) { } dft_plan_set_mirror(&q->fft_plan, true); - dft_plan_set_norm(&q->fft_plan, true); dft_plan_set_dc(&q->fft_plan, true); +#ifdef LTE_FFT_NORMALIZE + dft_plan_set_norm(&q->fft_plan, true); +#endif q->symbol_sz = (uint32_t) symbol_sz; q->nof_symbols = CP_NSYMB(cp); diff --git a/lte/phy/lib/fec/src/viterbi.c b/lte/phy/lib/fec/src/viterbi.c index cb334bd33..ed7f5e924 100644 --- a/lte/phy/lib/fec/src/viterbi.c +++ b/lte/phy/lib/fec/src/viterbi.c @@ -119,6 +119,7 @@ int init37(viterbi_t *q, uint32_t poly[3], uint32_t framebits, bool tail_biting) q->K = 7; q->R = 3; q->framebits = framebits; + q->gain_quant = 32; q->tail_biting = tail_biting; q->decode = decode37; q->free = free37; @@ -152,6 +153,7 @@ int init39(viterbi_t *q, uint32_t poly[3], uint32_t framebits, bool tail_biting) q->R = 3; q->framebits = framebits; q->tail_biting = tail_biting; + q->gain_quant = 32; q->decode = decode39; q->free = free39; if (q->tail_biting) { @@ -173,6 +175,10 @@ int init39(viterbi_t *q, uint32_t poly[3], uint32_t framebits, bool tail_biting) } } +void viterbi_set_gain_quant(viterbi_t *q, float gain_quant) { + q->gain_quant = gain_quant; +} + int viterbi_init(viterbi_t *q, viterbi_type_t type, uint32_t poly[3], uint32_t max_frame_length, bool tail_bitting) { switch (type) { @@ -206,7 +212,7 @@ int viterbi_decode_f(viterbi_t *q, float *symbols, uint8_t *data, uint32_t frame } else { len = 3 * (frame_length + q->K - 1); } - vec_quant_fuc(symbols, q->symbols_uc, 32, 127.5, 255, len); + vec_quant_fuc(symbols, q->symbols_uc, q->gain_quant, 127.5, 255, len); return q->decode(q, q->symbols_uc, data, frame_length); } diff --git a/lte/phy/lib/fec/src/viterbi37_port.c b/lte/phy/lib/fec/src/viterbi37_port.c index 37070268a..3a530e2f3 100644 --- a/lte/phy/lib/fec/src/viterbi37_port.c +++ b/lte/phy/lib/fec/src/viterbi37_port.c @@ -77,7 +77,6 @@ void *create_viterbi37_port(uint32_t polys[3], uint32_t len) { free(vp); return NULL ; } - init_viterbi37_port(vp, 0); return vp; } @@ -179,7 +178,7 @@ int update_viterbi37_blk_port(void *p, uint8_t *syms, uint32_t nbits, uint32_t * uint32_t i, bst=0; uint32_t minmetric=UINT_MAX; for (i=0;i<64;i++) { - if (vp->old_metrics->w[i] < minmetric) { + if (vp->old_metrics->w[i] <= minmetric) { bst = i; minmetric = vp->old_metrics->w[i]; } diff --git a/lte/phy/lib/fec/test/CMakeLists.txt b/lte/phy/lib/fec/test/CMakeLists.txt index 0a7064c3e..2a6ff52c9 100644 --- a/lte/phy/lib/fec/test/CMakeLists.txt +++ b/lte/phy/lib/fec/test/CMakeLists.txt @@ -67,6 +67,8 @@ ADD_TEST(viterbi_1000_2 viterbi_test -n 100 -s 1 -l 1000 -k 7 -t -e 2.0) ADD_TEST(viterbi_1000_3 viterbi_test -n 100 -s 1 -l 1000 -k 7 -t -e 3.0) ADD_TEST(viterbi_1000_4 viterbi_test -n 100 -s 1 -l 1000 -k 7 -t -e 4.5) +BuildMex(MEXNAME viterbi SOURCES viterbi_test_mex.c LIBRARIES lte_phy liblte_mex) + ######################################################################## # CRC TEST ######################################################################## diff --git a/lte/phy/lib/mimo/src/precoding.c b/lte/phy/lib/mimo/src/precoding.c index b45b6fcb3..46c035ebc 100644 --- a/lte/phy/lib/mimo/src/precoding.c +++ b/lte/phy/lib/mimo/src/precoding.c @@ -174,6 +174,8 @@ int predecoding_diversity(precoding_t *q, cf_t *y, cf_t *h[MAX_PORTS], cf_t *x[M vec_sc_add_fff(modhh, noise_estimate, modhh, nof_symbols/2); } + vec_sc_prod_fff(modhh, 1/sqrt(2), modhh, nof_symbols/2); + // x[0] = r0·h0*/(|h0|+|h1|)+r1*·h1/(|h0|+|h1|) vec_prod_conj_ccc(r0,h0,q->tmp1, nof_symbols/2); vec_prod_conj_ccc(h1,r1,q->tmp2, nof_symbols/2); diff --git a/lte/phy/lib/phch/test/CMakeLists.txt b/lte/phy/lib/phch/test/CMakeLists.txt index 8a903710e..abc85bc61 100644 --- a/lte/phy/lib/phch/test/CMakeLists.txt +++ b/lte/phy/lib/phch/test/CMakeLists.txt @@ -33,6 +33,8 @@ 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) + ######################################################################## # PCFICH TEST diff --git a/matlab/tests/pdcch_test.m b/matlab/tests/pdcch_test.m index cf8d07232..1a9a21a3a 100644 --- a/matlab/tests/pdcch_test.m +++ b/matlab/tests/pdcch_test.m @@ -3,8 +3,8 @@ %% Cell-Wide Settings % A structure |enbConfig| is used to configure the eNodeB. -Npackets = 50; -SNR_values =linspace(-5,3,8); +Npackets = 1; +SNR_values =20;%linspace(-5,3,8); enbConfig.NDLRB = 15; % No of Downlink RBs in total BW enbConfig.CyclicPrefix = 'Normal'; % CP length @@ -67,7 +67,7 @@ subframe_tx(pdcchIndices) = pdcchSymbols; addpath('../../debug/lte/phy/lib/phch/test') -parfor snr_idx=1:length(SNR_values) +for snr_idx=1:length(SNR_values) SNRdB = SNR_values(snr_idx); for i=1:Npackets diff --git a/mex/include/liblte/mex/mexutils.h b/mex/include/liblte/mex/mexutils.h index c225355cd..0c2aef266 100644 --- a/mex/include/liblte/mex/mexutils.h +++ b/mex/include/liblte/mex/mexutils.h @@ -61,6 +61,11 @@ LIBLTE_API int mexutils_write_cf(cf_t *buffer, uint32_t nr, uint32_t nc); +LIBLTE_API int mexutils_write_uint8(uint8_t *buffer, + mxArray **ptr, + uint32_t nr, + uint32_t nc); + LIBLTE_API int mexutils_read_f(const mxArray *ptr, float **buffer); diff --git a/mex/lib/mexutils.c b/mex/lib/mexutils.c index fb8e96c7d..7706917a4 100644 --- a/mex/lib/mexutils.c +++ b/mex/lib/mexutils.c @@ -25,6 +25,7 @@ * */ +#include #include #include "liblte/phy/common/phy_common.h" #include "liblte/mex/mexutils.h" @@ -126,3 +127,14 @@ int mexutils_write_f(float *buffer, mxArray **ptr, uint32_t nr, uint32_t nc) { } } + +int mexutils_write_uint8(uint8_t *buffer, mxArray **ptr, uint32_t nr, uint32_t nc) { + *ptr = mxCreateNumericMatrix(nr, nc, mxUINT8_CLASS, mxREAL); + if (*ptr) { + uint8_t *outr = (uint8_t*) mxGetPr(*ptr); + memcpy(outr, buffer, nr*nc*sizeof(uint8_t)); + return nc*nr; + } else { + return -1; + } +}