diff --git a/COPYRIGHT b/COPYRIGHT index de839a6ac..6b399f6a5 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,32 +1,7 @@ Copyright (C) 2013-2014 Ismael Gomez Miguelez, . All rights reserved. -The following copyright notices are for libraries used within Iris_Modules: +The following copyright notices are for libraries used within libLTE: ------------------------------------------------------------ -Boost Software License - Version 1.0 - August 17th, 2003 ------------------------------------------------------------ - -Permission is hereby granted, free of charge, to any person or -organization obtaining a copy of the software and accompanying -documentation covered by this license (the "Software") to use, reproduce, -display, distribute, execute, and transmit the Software, and to prepare -derivative works of the Software, and to permit third-parties to whom -the Software is furnished to do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated -by a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO -EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE -BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT -OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ----------------------------------------------------------- CLibrary.py diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a3f33e811..21d3cdba8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,16 +30,13 @@ target_link_libraries(hl_example lte) add_executable(ll_example ll_example.c) target_link_libraries(ll_example lte) -add_executable(synch_file synch_file.c) -target_link_libraries(synch_file lte) - ################################################################# -# TO BE MOVED TO UNIT TESTS +# Applications ################################################################# -add_executable(mib_test mib_test.c) -target_link_libraries(mib_test lte) +add_executable(synch_file synch_file.c) +target_link_libraries(synch_file lte) ################################################################# diff --git a/lte/include/lte/phch/pbch.h b/lte/include/lte/phch/pbch.h index 36cbb7315..4d0dd1366 100644 --- a/lte/include/lte/phch/pbch.h +++ b/lte/include/lte/phch/pbch.h @@ -90,7 +90,7 @@ void pbch_free(pbch_t *q); int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], int nof_prb, float ebno, pbch_mib_t *mib); void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_prb, int nof_ports); - +void pbch_decode_reset(pbch_t *q); void pbch_mib_fprint(FILE *stream, pbch_mib_t *mib); bool pbch_exists(int nframe, int nslot); diff --git a/lte/lib/fec/src/viterbi.c b/lte/lib/fec/src/viterbi.c index 614fbb48a..0b7351a10 100644 --- a/lte/lib/fec/src/viterbi.c +++ b/lte/lib/fec/src/viterbi.c @@ -175,7 +175,13 @@ void viterbi_free(viterbi_t *q) { /* symbols are real-valued */ int viterbi_decode_f(viterbi_t *q, float *symbols, char *data) { - vec_quant_fuc(symbols, q->symbols_uc, 32, 127.5, 255, 3 * (q->framebits + q->K - 1)); + int len; + if (q->tail_biting) { + len = 3 * q->framebits; + } else { + len = 3 * (q->framebits + q->K - 1); + } + vec_quant_fuc(symbols, q->symbols_uc, 32, 127.5, 255, len); return q->decode(q, q->symbols_uc, data); } diff --git a/lte/lib/mimo/src/precoding.c b/lte/lib/mimo/src/precoding.c index fad5947c0..dd136a01a 100644 --- a/lte/lib/mimo/src/precoding.c +++ b/lte/lib/mimo/src/precoding.c @@ -51,10 +51,11 @@ int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports, y[0][2*i+1] = x[1][i]/sqrtf(2); y[1][2*i+1] = conjf(x[0][i])/sqrtf(2); } - return i; + return 2*i; } else if (nof_ports == 4) { - int m_ap = (nof_symbols%4)?(nof_symbols*4-2):nof_symbols*4; - for (i=0;ipbch_llr) { free(q->pbch_llr); } + if (q->temp) { + free(q->temp); + } if (q->pbch_rm_f) { free(q->pbch_rm_f); } diff --git a/lte/lib/phch/test/CMakeLists.txt b/lte/lib/phch/test/CMakeLists.txt new file mode 100644 index 000000000..d9e11a510 --- /dev/null +++ b/lte/lib/phch/test/CMakeLists.txt @@ -0,0 +1,42 @@ +# +# Copyright 2012-2013 The libLTE Developers. See the +# COPYRIGHT file at the top-level directory of this distribution. +# +# 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. +# +# 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/. +# + +######################################################################## +# PBCH TEST +######################################################################## + +ADD_EXECUTABLE(pbch_test pbch_test.c) +TARGET_LINK_LIBRARIES(pbch_test lte) + +ADD_TEST(pbch_test_6 pbch_test -p 6 -c 100) +ADD_TEST(pbch_test_50 pbch_test -p 50 -c 50) + +######################################################################## +# PBCH FILE TEST +######################################################################## + +ADD_EXECUTABLE(pbch_file_test pbch_file_test.c) +TARGET_LINK_LIBRARIES(pbch_file_test lte) + +ADD_TEST(pbch_file_test pbch_file_test -i ${CMAKE_CURRENT_SOURCE_DIR}/h3g.mib.dat) + + + diff --git a/lte/lib/phch/test/h3g.mib.dat b/lte/lib/phch/test/h3g.mib.dat new file mode 100644 index 000000000..92d4a06ba Binary files /dev/null and b/lte/lib/phch/test/h3g.mib.dat differ diff --git a/examples/mib_test.c b/lte/lib/phch/test/pbch_file_test.c similarity index 92% rename from examples/mib_test.c rename to lte/lib/phch/test/pbch_file_test.c index 026b1d7cd..0d30f0b7e 100644 --- a/examples/mib_test.c +++ b/lte/lib/phch/test/pbch_file_test.c @@ -142,7 +142,7 @@ int base_init() { return 0; } -void base_close() { +void base_free() { int i; filesource_free(&fsrc); @@ -159,6 +159,10 @@ void base_close() { chest_free(&chest); lte_fft_free(&fft); + cfo_free(&cfocorr); + + pbch_free(&pbch); + } @@ -278,6 +282,11 @@ int main(int argc, char **argv) { switch(state) { case SYNC: INFO("State Sync, Slot idx=%d\n", frame_cnt); + fprintf(fmatlab, "input_buffer="); + vec_sc_prod_cfc(input_buffer, 1000.0, input_buffer, FLEN); + vec_fprint_c(fmatlab, input_buffer, FLEN); + vec_sc_prod_cfc(input_buffer, 0.0001, input_buffer, FLEN); + fprintf(fmatlab, ";\n"); mib_idx = sync_run(&synch, input_buffer); if (mib_idx != -1) { cell_id = sync_get_cell_id(&synch); @@ -320,8 +329,16 @@ int main(int argc, char **argv) { frame_cnt++; } - base_close(); + base_free(); + + fftwf_cleanup(); - printf("Exit\n"); - exit(0); + if (mib.nof_ports == 2 && mib.nof_prb == 50 && mib.phich_length == NORMAL + && mib.phich_resources == R_1 && mib.sfn == 28) { + printf("This is the h3g.mib.dat file\n"); + exit(0); + } else { + printf("Exit\n"); + exit(-1); + } } diff --git a/lte/lib/phch/test/pbch_test.c b/lte/lib/phch/test/pbch_test.c new file mode 100644 index 000000000..dec99d797 --- /dev/null +++ b/lte/lib/phch/test/pbch_test.c @@ -0,0 +1,129 @@ +/** + * + * \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. + * + * 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 +#include +#include +#include +#include + +#include "lte.h" + +int cell_id = 1; +int nof_prb = 6; + + +void usage(char *prog) { + printf("Usage: %s [cpv]\n", prog); + printf("\t-c cell id [Default %d]\n", cell_id); + printf("\t-p nof_prb [Default %d]\n", nof_prb); + printf("\t-v [set verbose to debug, default none]\n"); +} + +void parse_args(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "cpv")) != -1) { + switch(opt) { + case 'p': + nof_prb = atoi(argv[optind]); + break; + case 'c': + cell_id = atoi(argv[optind]); + break; + case 'v': + verbose++; + break; + default: + usage(argv[0]); + exit(-1); + } + } +} + + +int main(int argc, char **argv) { + pbch_t pbch; + cf_t *buffer = NULL; + pbch_mib_t mib_tx, mib_rx; + int i, j; + cf_t *ce[MAX_PORTS_CTRL]; + int nof_re; + cf_t *slot1_symbols[MAX_PORTS_CTRL]; + + parse_args(argc,argv); + + nof_re = CPNORM_NSYMB * nof_prb * RE_X_RB; + + /* init memory */ + buffer = malloc(sizeof(cf_t) * nof_re); + if (!buffer) { + perror("malloc"); + exit(-1); + } + for (i=0;i +#include +#include +#include +#include +#include +#include +#include + +#include "lte.h" + +#define MAX_MSE 0.1 + +float freq = 0; +int num_samples = 1000; + +void usage(char *prog) { + printf("Usage: %s -f freq -n num_samples\n", prog); +} + +void parse_args(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "nf")) != -1) { + switch (opt) { + case 'n': + num_samples = atoi(argv[optind]); + break; + case 'f': + freq = atof(argv[optind]); + break; + default: + usage(argv[0]); + exit(-1); + } + } +} + +int main(int argc, char **argv) { + int i; + cf_t *input, *output; + cfo_t cfocorr; + float mse; + + if (argc < 5) { + usage(argv[0]); + exit(-1); + } + + parse_args(argc, argv); + + input = malloc(sizeof(cf_t) * num_samples); + if (!input) { + perror("malloc"); + exit(-1); + } + output = malloc(sizeof(cf_t) * num_samples); + if (!output) { + perror("malloc"); + exit(-1); + } + + for (i=0;i MAX_MSE) { + printf("MSE too large\n"); + exit(-1); + } else { + printf("Ok\n"); + exit(0); + } +} diff --git a/lte/lib/sync/test/sync_test.c b/lte/lib/sync/test/sync_test.c new file mode 100644 index 000000000..348910894 --- /dev/null +++ b/lte/lib/sync/test/sync_test.c @@ -0,0 +1,152 @@ +/** + * + * \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. + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "lte.h" + +int cell_id = -1, offset = 0; + +#define FLEN 9600 + +void usage(char *prog) { + printf("Usage: %s [co]\n", prog); + printf("\t-c cell_id [Default check for all]\n"); + printf("\t-o offset [Default %d]\n", offset); +} + +void parse_args(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "co")) != -1) { + switch (opt) { + case 'c': + cell_id = atoi(argv[optind]); + break; + case 'o': + offset = atoi(argv[optind]); + break; + default: + usage(argv[0]); + exit(-1); + } + } +} + +int main(int argc, char **argv) { + int N_id_2, ns, find_ns; + cf_t *buffer, *fft_buffer; + cf_t pss_signal[PSS_LEN]; + float sss_signal0[SSS_LEN]; // for subframe 0 + float sss_signal5[SSS_LEN]; // for subframe 5 + int cid, max_cid, find_idx; + sync_t sync; + lte_fft_t ifft; + + parse_args(argc, argv); + + buffer = malloc(sizeof(cf_t) * FLEN); + if (!buffer) { + perror("malloc"); + exit(-1); + } + + fft_buffer = malloc(sizeof(cf_t) * 2 * FLEN); + if (!fft_buffer) { + perror("malloc"); + exit(-1); + } + + if (lte_ifft_init(&ifft, CPNORM, 6)) { + fprintf(stderr, "Error creating iFFT object\n"); + exit(-1); + } + + if (sync_init(&sync, FLEN)) { + fprintf(stderr, "Error initiating PSS/SSS\n"); + return -1; + } + + sync_set_threshold(&sync, 20); + sync_force_N_id_2(&sync, -1); + + if (cell_id == -1) { + cid = 0; + max_cid = 149; + } else { + cid = cell_id; + max_cid = cell_id; + } + while(cid <= max_cid) { + N_id_2 = cid%3; + + /* Generate PSS/SSS signals */ + pss_generate(pss_signal, N_id_2); + sss_generate(sss_signal0, sss_signal5, cid); + + for (ns=0;ns<2;ns++) { + memset(buffer, 0, sizeof(cf_t) * FLEN); + pss_put_slot(pss_signal, buffer, 6, CPNORM); + sss_put_slot(ns?sss_signal5:sss_signal0, buffer, 6, CPNORM); + + /* Transform to OFDM symbols */ + memset(fft_buffer, 0, sizeof(cf_t) * 2 * FLEN); + lte_ifft_run(&ifft, buffer, &fft_buffer[offset]); + + find_idx = sync_run(&sync, fft_buffer); + find_ns = sync_get_slot_id(&sync); + printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset, + ns, find_ns); + if (find_idx != offset + 960) { + printf("offset != find_offset: %d != %d\n", find_idx, offset + 960); + exit(-1); + } + if (ns*10 != find_ns) { + printf("ns != find_ns\n", 10 * ns, find_ns); + exit(-1); + } + } + cid++; + } + + free(fft_buffer); + free(buffer); + + sync_free(&sync); + lte_ifft_free(&ifft); + + fftwf_cleanup(); + + printf("Ok\n"); + exit(0); +} diff --git a/lte/lib/utils/src/cexptab.c b/lte/lib/utils/src/cexptab.c index d1e13ab93..158a19aaa 100644 --- a/lte/lib/utils/src/cexptab.c +++ b/lte/lib/utils/src/cexptab.c @@ -62,15 +62,16 @@ void cexptab_gen(cexptab_t *h, cf_t *x, float freq, int len) { float phase=0; for (i = 0; i < len; i++) { - idx = (unsigned int) phase; - x[i] = h->tab[idx]; - phase += phase_inc; - if (phase >= (float) h->size) { + while (phase >= (float) h->size) { phase -= (float) h->size; } - if (phase <= 0) { + while (phase < 0) { phase += (float) h->size; } + idx = (unsigned int) phase; + x[i] = h->tab[idx]; + phase += phase_inc; + } }