From 3cda76a39471bf68d9bed1b943dc3d3d0c8e0279 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Tue, 7 Apr 2015 02:51:22 +0000 Subject: [PATCH] kicked off stand alone C program for testing coh psk with channel impairments git-svn-id: https://svn.code.sf.net/p/freetel/code@2105 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/CMakeLists.txt | 3 + codec2-dev/src/cohpsk.c | 8 +- codec2-dev/src/cohpsk_put_test_bits.c | 103 +++++++++++++++++++ codec2-dev/unittest/CMakeLists.txt | 3 + codec2-dev/unittest/test_cohpsk_ch.c | 140 ++++++++++++++++++++++++++ 5 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 codec2-dev/src/cohpsk_put_test_bits.c create mode 100644 codec2-dev/unittest/test_cohpsk_ch.c diff --git a/codec2-dev/src/CMakeLists.txt b/codec2-dev/src/CMakeLists.txt index 1cc1cc0b..903961ca 100644 --- a/codec2-dev/src/CMakeLists.txt +++ b/codec2-dev/src/CMakeLists.txt @@ -266,6 +266,9 @@ target_link_libraries(cohpsk_demod ${CMAKE_REQUIRED_LIBRARIES} codec2) add_executable(cohpsk_get_test_bits cohpsk_get_test_bits.c) target_link_libraries(cohpsk_get_test_bits ${CMAKE_REQUIRED_LIBRARIES} codec2) +add_executable(cohpsk_put_test_bits cohpsk_put_test_bits.c) +target_link_libraries(cohpsk_put_test_bits ${CMAKE_REQUIRED_LIBRARIES} codec2) + install(TARGETS codec2 EXPORT codec2-config LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/codec2-dev/src/cohpsk.c b/codec2-dev/src/cohpsk.c index 647d84b5..1ecc0177 100644 --- a/codec2-dev/src/cohpsk.c +++ b/codec2-dev/src/cohpsk.c @@ -316,7 +316,7 @@ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm bin_est = num/den; coh->f_est = floor(bin_est/sc+0.5); - printf("coarse freq est: %f\n", coh->f_est); + fprintf(stderr, "coarse freq est: %f\n", coh->f_est); *next_sync = 1; } @@ -392,15 +392,15 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int coh->ff_rect.real = cosf(coh->f_fine_est*2.0*M_PI/RS); coh->ff_rect.imag = -sinf(coh->f_fine_est*2.0*M_PI/RS); - printf(" fine freq f: %f max_corr: %f max_mag: %f ct: %d\n", coh->f_fine_est, max_corr, max_mag, coh->ct); + fprintf(stderr, " fine freq f: %f max_corr: %f max_mag: %f ct: %d\n", coh->f_fine_est, max_corr, max_mag, coh->ct); if (max_corr/max_mag > 0.9) { - printf("in sync!\n"); + fprintf(stderr, "in sync!\n"); *next_sync = 4; } else { *next_sync = 0; - printf(" back to coarse freq offset est...\n"); + fprintf(stderr, " back to coarse freq offset est...\n"); } } diff --git a/codec2-dev/src/cohpsk_put_test_bits.c b/codec2-dev/src/cohpsk_put_test_bits.c new file mode 100644 index 00000000..7b369e89 --- /dev/null +++ b/codec2-dev/src/cohpsk_put_test_bits.c @@ -0,0 +1,103 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: cohpsk_put_test_bits.c + AUTHOR......: David Rowe + DATE CREATED: April 2015 + + Sinks a stream of test bits generated by cohpsk_get_test_bits, useful for + testing coh psk mod and demod. + +\*---------------------------------------------------------------------------*/ + + +/* + Copyright (C) 2015 David Rowe + + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 2, as + published by the Free Software Foundation. This program 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 General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include +#include +#include + +#include "codec2_cohpsk.h" +#include "test_bits_coh.h" + +int main(int argc, char *argv[]) +{ + FILE *fin; + int rx_bits[COHPSK_BITS_PER_FRAME]; + int *ptest_bits_coh, *ptest_bits_coh_end; + int state, next_state, i, nbits, nerrors; + float corr; + + if (argc < 2) { + printf("usage: %s InputOneBitPerIntFile\n", argv[0]); + exit(1); + } + + if (strcmp(argv[1], "-") == 0) fin = stdin; + else if ( (fin = fopen(argv[1],"rb")) == NULL ) { + fprintf(stderr, "Error opening input file: %s: %s.\n", + argv[1], strerror(errno)); + exit(1); + } + + ptest_bits_coh = (int*)test_bits_coh; + ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int); + + while (fread(rx_bits, sizeof(int), COHPSK_BITS_PER_FRAME, fin) == COHPSK_BITS_PER_FRAME) { + + corr = 0.0; + for(i=0; i= ptest_bits_coh_end) { + ptest_bits_coh = (int*)test_bits_coh; + } + } + + state = next_state; + + if (fin == stdin) fflush(stdin); + } + + fclose(fin); + printf("BER: %3.2f Nbits: %d Nerrors: %d\n", (float)nerrors/nbits, nbits, nerrors); + + return 0; +} + diff --git a/codec2-dev/unittest/CMakeLists.txt b/codec2-dev/unittest/CMakeLists.txt index 7d1e98cb..ad4ba7e2 100644 --- a/codec2-dev/unittest/CMakeLists.txt +++ b/codec2-dev/unittest/CMakeLists.txt @@ -54,6 +54,9 @@ target_link_libraries(tfdmdv codec2) add_executable(tcohpsk tcohpsk.c ../src/cohpsk.c ../src/octave.c) target_link_libraries(tcohpsk codec2) +add_executable(test_cohpsk_ch test_cohpsk_ch.c ../src/cohpsk.c ../src/octave.c) +target_link_libraries(test_cohpsk_ch codec2) + add_executable(t16_8 t16_8.c ../src/fdmdv.c ../src/kiss_fft.c) target_link_libraries(t16_8 codec2) diff --git a/codec2-dev/unittest/test_cohpsk_ch.c b/codec2-dev/unittest/test_cohpsk_ch.c new file mode 100644 index 00000000..089a54f2 --- /dev/null +++ b/codec2-dev/unittest/test_cohpsk_ch.c @@ -0,0 +1,140 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: ttest_cohpsk_ch.c + AUTHOR......: David Rowe + DATE CREATED: April 2015 + + Tests for the C version of the coherent PSK FDM modem with channel + impairments generated by Octave. + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2015 David Rowe + + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 2, as + published by the Free Software Foundation. This program 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 General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include +#include + +#include "codec2_cohpsk.h" +#include "test_bits_coh.h" +#include "octave.h" +#include "comp_prim.h" +#include "noise_samples.h" + +#define FRAMES 35 +#define FOFFHZ 10.5 + +int main(int argc, char *argv[]) +{ + struct COHPSK *coh; + int tx_bits[COHPSK_BITS_PER_FRAME]; + COMP tx_fdm[COHPSK_SAMPLES_PER_FRAME]; + COMP ch_fdm[COHPSK_SAMPLES_PER_FRAME]; + int rx_bits[COHPSK_BITS_PER_FRAME]; + + int f, r, i; + int *ptest_bits_coh, *ptest_bits_coh_end, *ptest_bits_coh_rx; + COMP phase_ch; + int noise_r, noise_end; + float corr; + int state, next_state, nerrors, nbits, reliable_sync_bit; + + coh = cohpsk_create(); + assert(coh != NULL); + + ptest_bits_coh = ptest_bits_coh_rx = (int*)test_bits_coh; + ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int); + phase_ch.real = 1.0; phase_ch.imag = 0.0; + noise_r = 0; + noise_end = sizeof(noise)/sizeof(int); + + /* Main Loop ---------------------------------------------------------------------*/ + + for(f=0; f= ptest_bits_coh_end) { + ptest_bits_coh = (int*)test_bits_coh; + } + + cohpsk_mod(coh, tx_fdm, tx_bits); + + /* --------------------------------------------------------*\ + Channel + \*---------------------------------------------------------*/ + + fdmdv_freq_shift(ch_fdm, tx_fdm, FOFFHZ, &phase_ch, COHPSK_SAMPLES_PER_FRAME); + + for(r=0; r noise_end) + noise_r = 0; + } + + /* --------------------------------------------------------*\ + Demod + \*---------------------------------------------------------*/ + + cohpsk_demod(coh, rx_bits, &reliable_sync_bit, ch_fdm); + + corr = 0.0; + for(i=0; i= ptest_bits_coh_end) { + ptest_bits_coh_rx = (int*)test_bits_coh; + } + } + + state = next_state; + } + + printf("BER: %3.2f Nbits: %d Nerrors: %d\n", (float)nerrors/nbits, nbits, nerrors); + + cohpsk_destroy(coh); + + return 0; +} + -- 2.25.1