diff --git a/lib/src/phy/ch_estimation/chest_sl.c b/lib/src/phy/ch_estimation/chest_sl.c index ea8f3ceb6..eff2dd51f 100644 --- a/lib/src/phy/ch_estimation/chest_sl.c +++ b/lib/src/phy/ch_estimation/chest_sl.c @@ -523,7 +523,7 @@ int srslte_chest_sl_get_psbch_dmrs(srslte_chest_sl_t* q, { uint32_t sample_pos = 0; uint32_t k = nof_prb * SRSLTE_NRE / 2 - 36; - uint32_t sf_nsymbols = SRSLTE_CP_NORM_SF_NSYMB; + uint32_t sf_nsymbols = (cp == SRSLTE_CP_NORM) ? SRSLTE_CP_NORM_SF_NSYMB : SRSLTE_CP_EXT_SF_NSYMB; // Get DMRSs for (uint32_t i = 0; i < sf_nsymbols; i++) { diff --git a/lib/src/phy/ch_estimation/test/CMakeLists.txt b/lib/src/phy/ch_estimation/test/CMakeLists.txt index 0d0bada33..1233bc7ad 100644 --- a/lib/src/phy/ch_estimation/test/CMakeLists.txt +++ b/lib/src/phy/ch_estimation/test/CMakeLists.txt @@ -57,3 +57,13 @@ add_executable(chest_nbiot_test_dl chest_nbiot_test_dl.c) target_link_libraries(chest_nbiot_test_dl srslte_phy) add_test(chest_nbiot_test_dl chest_nbiot_test_dl) + + +######################################################################## +# Sidelink Channel Estimation TEST +######################################################################## + +add_executable(chest_test_sl chest_test_sl.c) +target_link_libraries(chest_test_sl srslte_phy) + +add_test(chest_test_sl_psbch chest_test_sl) diff --git a/lib/src/phy/ch_estimation/test/chest_test_sl.c b/lib/src/phy/ch_estimation/test/chest_test_sl.c new file mode 100644 index 000000000..552ed3fba --- /dev/null +++ b/lib/src/phy/ch_estimation/test/chest_test_sl.c @@ -0,0 +1,154 @@ +/* + * Copyright 2013-2019 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * 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 "srslte/phy/common/phy_common.h" +#include +#include +#include +#include +#include +#include +#include + +uint32_t nof_prb = 25; +uint32_t N_sl_id = 1; +srslte_cp_t cp = SRSLTE_CP_NORM; +srslte_sl_tm_t tm = SRSLTE_SIDELINK_TM4; +bool run_psbch_test = true; + +void usage(char* prog) +{ + printf("Usage: %s [recov]\n", prog); + + printf("\t-p nof_prb [Default %d]\n", nof_prb); + printf("\t-e extended cyclic prefix [Default normal]\n"); + + printf("\t-c N_sl_id [Default %d]\n", N_sl_id); + printf("\t-t Sidelink transmission mode {1,2,3,4} [Default %d]\n", (tm + 1)); + + printf("\t-v increase verbosity\n"); +} + +void parse_args(int argc, char** argv) +{ + int opt; + while ((opt = getopt(argc, argv, "pecotv")) != -1) { + switch (opt) { + case 'p': + nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'e': + cp = SRSLTE_CP_EXT; + break; + case 'c': + N_sl_id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 't': + switch (strtol(argv[optind], NULL, 10)) { + case 1: + tm = SRSLTE_SIDELINK_TM1; + break; + case 2: + tm = SRSLTE_SIDELINK_TM2; + break; + case 3: + tm = SRSLTE_SIDELINK_TM3; + break; + case 4: + tm = SRSLTE_SIDELINK_TM4; + break; + default: + usage(argv[0]); + exit(-1); + } + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); + } + } +} + +int main(int argc, char** argv) +{ + parse_args(argc, argv); + + int sf_n_re = SRSLTE_CP_NSYMB(cp) * SRSLTE_NRE * nof_prb * 2; + cf_t* sf_buffer = srslte_vec_malloc(sizeof(cf_t) * sf_n_re); + bzero(sf_buffer, sizeof(cf_t) * sf_n_re); + + // Variables init Rx + cf_t* sf_buffer_rx = srslte_vec_malloc(sizeof(cf_t) * sf_n_re); + bzero(sf_buffer_rx, sizeof(cf_t) * sf_n_re); + + cf_t* dmrs_received[SRSLTE_SL_MAX_DMRS_SYMB] = {NULL}; + for (int i = 0; i < SRSLTE_SL_MAX_DMRS_SYMB; i++) { + dmrs_received[i] = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_NRE * nof_prb); + } + + // Variables init Tx + srslte_chest_sl_t q; + + if (run_psbch_test) { + // Tx + srslte_chest_sl_init_psbch_dmrs(&q); + srslte_chest_sl_gen_psbch_dmrs(&q, tm, N_sl_id); + srslte_chest_sl_put_psbch_dmrs(&q, sf_buffer, tm, nof_prb, cp); + + // Rx + srslte_chest_sl_psbch_ls_estimate_equalize(&q, sf_buffer, sf_buffer_rx, nof_prb, tm, cp); + srslte_chest_sl_get_psbch_dmrs(&q, sf_buffer_rx, dmrs_received, tm, nof_prb, cp); + + // Test + // TODO: add proper test + } + + // Print of received DMRS + printf("\n\nPrint of received DMRS\n"); + for (int i = 0; i < q.M_sc_rs; i++) { + printf("%i\t", i + 1); + for (int j = 0; j < q.nof_dmrs_symbols; j++) { + printf("%f\t%f\t", __real__ dmrs_received[j][i], __imag__ dmrs_received[j][i]); + } + printf("\n"); + } + + srslte_chest_sl_free(&q); + + if (sf_buffer) { + free(sf_buffer); + } + + if (sf_buffer_rx) { + free(sf_buffer_rx); + } + + for (int i = 0; i < SRSLTE_SL_MAX_DMRS_SYMB; i++) { + if (dmrs_received[i]) { + free(dmrs_received[i]); + } + } + + return SRSLTE_SUCCESS; +} \ No newline at end of file