All tests completed

This commit is contained in:
ismagom 2014-03-15 01:04:21 +00:00
parent f588d670ad
commit 6a514e4107
16 changed files with 558 additions and 73 deletions

View File

@ -1,32 +1,7 @@
Copyright (C) 2013-2014 Ismael Gomez Miguelez, <gomezi@tcd.ie>. 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

View File

@ -30,18 +30,15 @@ target_link_libraries(hl_example lte)
add_executable(ll_example ll_example.c)
target_link_libraries(ll_example lte)
#################################################################
# Applications
#################################################################
add_executable(synch_file synch_file.c)
target_link_libraries(synch_file lte)
#################################################################
# TO BE MOVED TO UNIT TESTS
#################################################################
add_executable(mib_test mib_test.c)
target_link_libraries(mib_test lte)
#################################################################
# Check if UHD C-API and Graphics library are available
#################################################################

View File

@ -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);

View File

@ -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);
}

View File

@ -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;i<m_ap;i++) {
//int m_ap = (nof_symbols%4)?(nof_symbols*4-2):nof_symbols*4;
int m_ap = 4 * nof_symbols;
for (i=0;i<m_ap/4;i++) {
y[0][4*i] = x[0][i]/sqrtf(2);
y[1][4*i] = 0;
y[2][4*i] = -conjf(x[1][i])/sqrtf(2);
@ -75,7 +76,7 @@ int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
y[2][4*i+3] = 0;
y[3][4*i+3] = conjf(x[2][i])/sqrtf(2);
}
return i;
return 4*i;
} else {
fprintf(stderr, "Number of ports must be 2 or 4 for transmit diversity\n");
return -1;
@ -129,8 +130,8 @@ int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols) {
int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_symbols) {
int i;
cf_t h0, h1, r0, r1;
float hh;
cf_t h0, h1, h2, h3, r0, r1, r2, r3;
float hh, hh02, hh13;
if (nof_ports == 2) {
/* TODO: Use VOLK here */
for (i=0;i<nof_symbols/2;i++) {
@ -145,31 +146,29 @@ int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS],
}
return i;
} else if (nof_ports == 4) {
/*
int m_ap = (nof_symbols%4)?((nof_symbols-2)/4):nof_symbols/4;
for (i=0;i<m_ap;i++) {
h0 = ce[0][2*i];
h1 = ce[1][2*i];
h2 = ce[2][2*i];
h3 = ce[3][2*i];
hh = crealf(h0)*crealf(h0)+cimagf(h0)*cimagf(h0)
+ crealf(h1)*crealf(h1)+cimagf(h1)*cimagf(h1)
+ crealf(h2)*crealf(h2)+cimagf(h2)*cimagf(h2)
h0 = ce[0][4*i];
h1 = ce[1][4*i+2];
h2 = ce[2][4*i];
h3 = ce[3][4*i+2];
hh02 = crealf(h0)*crealf(h0)+cimagf(h0)*cimagf(h0)
+ crealf(h2)*crealf(h2)+cimagf(h2)*cimagf(h2);
hh13 = crealf(h1)*crealf(h1)+cimagf(h1)*cimagf(h1)
+ crealf(h3)*crealf(h3)+cimagf(h3)*cimagf(h3);
r0 = y[0][2*i];
r1 = y[0][2*i+1];
r2 = y[0][2*i+2];
r3 = y[0][2*i+3];
r0 = y[0][4*i];
r1 = y[0][4*i+1];
r2 = y[0][4*i+2];
r3 = y[0][4*i+3];
x[0][i] = (conjf(h0)*r0 + conjf(h1)*r1)/hh * sqrt(2);
x[1][i] = (h1*conj(r0) + conj(h0)*r1)/hh * sqrt(2);
x[2][i] = (conjf(h0)*r0 + h1*conjf(r1))/hh * sqrt(2);
x[3][i] = (-h1*conj(r0) + conj(h0)*r1)/hh * sqrt(2);
x[0][i] = (conjf(h0)*r0 + h2*conjf(r1))/hh02 * sqrt(2);
x[1][i] = (-h2*conjf(r0) + conjf(h0)*r1)/hh02 * sqrt(2);
x[2][i] = (conjf(h1)*r2 + h3*conjf(r3))/hh13 * sqrt(2);
x[3][i] = (-h3*conjf(r2) + conjf(h1)*r3)/hh13 * sqrt(2);
}
*/
fprintf(stderr, "Error not implemented\n");
return -1;
return i;
} else {
fprintf(stderr, "Number of ports must be 2 or 4 for transmit diversity\n");
return -1;

View File

@ -58,7 +58,8 @@ ADD_EXECUTABLE(precoding_test precoding_test.c)
TARGET_LINK_LIBRARIES(precoding_test lte)
ADD_TEST(precoding_single precoding_test -n 1000 -m single)
ADD_TEST(precoding_diversity precoding_test -n 1000 -m diversity -l 2 -p 2)
ADD_TEST(precoding_diversity2 precoding_test -n 1000 -m diversity -l 2 -p 2)
ADD_TEST(precoding_diversity4 precoding_test -n 1024 -m diversity -l 4 -p 4)

View File

@ -141,7 +141,7 @@ int main(int argc, char **argv) {
/* generate channel */
for (i=0;i<nof_ports;i++) {
for (j=0;j<nof_symbols * nof_layers;j++) {
float hc = -1+(float) i/nof_ports + j/nof_symbols;
float hc = -1+(float) i/nof_ports;
h[i][j] = (3+hc) * cexpf(I * hc);
}
}

View File

@ -212,6 +212,9 @@ void pbch_free(pbch_t *q) {
if (q->pbch_llr) {
free(q->pbch_llr);
}
if (q->temp) {
free(q->temp);
}
if (q->pbch_rm_f) {
free(q->pbch_rm_f);
}

View File

@ -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)

Binary file not shown.

View File

@ -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();
printf("Exit\n");
exit(0);
fftwf_cleanup();
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);
}
}

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#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<MAX_PORTS_CTRL;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
exit(-1);
}
for (j=0;j<nof_re;j++) {
ce[i][j] = 1;
}
slot1_symbols[i] = buffer;
}
if (pbch_init(&pbch, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PBCH object\n");
exit(-1);
}
mib_tx.nof_ports = 1;
mib_tx.nof_prb = 50;
mib_tx.phich_length = EXTENDED;
mib_tx.phich_resources = R_1_6;
mib_tx.sfn = 124;
pbch_encode(&pbch, &mib_tx, slot1_symbols, nof_prb, 1);
pbch_decode_reset(&pbch);
if (1 != pbch_decode(&pbch, buffer, ce, nof_prb, 1, &mib_rx)) {
printf("Error decoding\n");
exit(-1);
}
pbch_free(&pbch);
if (buffer) {
free(buffer);
}
if (!memcmp(&mib_tx, &mib_rx, sizeof(pbch_mib_t))) {
printf("OK\n");
exit(0);
} else {
pbch_mib_fprint(stdout, &mib_rx);
exit(-1);
}
}

View File

@ -0,0 +1,44 @@
#
# 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/.
#
########################################################################
# SYNC TEST
########################################################################
ADD_EXECUTABLE(sync_test sync_test.c)
TARGET_LINK_LIBRARIES(sync_test lte)
ADD_TEST(sync_test_100 sync_test -o 100)
ADD_TEST(sync_test_400 sync_test -o 400)
########################################################################
# CFO TEST
########################################################################
ADD_EXECUTABLE(cfo_test cfo_test.c)
TARGET_LINK_LIBRARIES(cfo_test lte)
ADD_TEST(cfo_test_1 cfo_test -f 0.12345 -n 1000)
ADD_TEST(cfo_test_2 cfo_test -f 0.99849 -n 1000)

View File

@ -0,0 +1,119 @@
/**
*
* \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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>
#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<num_samples;i++) {
input[i] = 100 * (rand()/RAND_MAX + I*rand()/RAND_MAX);
output[i] = input[i];
}
if (cfo_init(&cfocorr, num_samples)) {
fprintf(stderr, "Error initiating CFO\n");
return -1;
}
cfo_correct(&cfocorr, output, freq);
cfo_correct(&cfocorr, output, -freq);
mse = 0;
for (i=0;i<num_samples;i++) {
mse += cabsf(input[i] - output[i]) / num_samples;
}
cfo_free(&cfocorr);
free(input);
free(output);
printf("MSE: %f\n", mse);
if (mse > MAX_MSE) {
printf("MSE too large\n");
exit(-1);
} else {
printf("Ok\n");
exit(0);
}
}

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>
#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);
}

View File

@ -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++) {
while (phase >= (float) h->size) {
phase -= (float) h->size;
}
while (phase < 0) {
phase += (float) h->size;
}
idx = (unsigned int) phase;
x[i] = h->tab[idx];
phase += phase_inc;
if (phase >= (float) h->size) {
phase -= (float) h->size;
}
if (phase <= 0) {
phase += (float) h->size;
}
}
}