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}
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;
}
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");
}
}
--- /dev/null
+/*---------------------------------------------------------------------------*\
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <errno.h>
+
+#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<COHPSK_BITS_PER_FRAME; i++) {
+ corr += (1.0 - 2.0*(rx_bits[i] & 0x1)) * (1.0 - 2.0*ptest_bits_coh[i]);
+ }
+
+ /* state logic */
+
+ next_state = state;
+
+ if (state == 0) {
+ fprintf(stderr, "corr %f\n", corr);
+ if (corr == COHPSK_BITS_PER_FRAME) {
+ next_state = 1;
+ ptest_bits_coh += COHPSK_BITS_PER_FRAME;
+ nerrors = COHPSK_BITS_PER_FRAME - corr;
+ nbits = COHPSK_BITS_PER_FRAME;
+ }
+ }
+
+ if (state == 1) {
+ nerrors += COHPSK_BITS_PER_FRAME - corr;
+ nbits += COHPSK_BITS_PER_FRAME;
+ ptest_bits_coh += COHPSK_BITS_PER_FRAME;
+ if (ptest_bits_coh >= 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;
+}
+
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)
--- /dev/null
+/*---------------------------------------------------------------------------*\
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#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<FRAMES; f++) {
+
+ /* --------------------------------------------------------*\
+ Mod
+ \*---------------------------------------------------------*/
+
+ memcpy(tx_bits, ptest_bits_coh, sizeof(int)*COHPSK_BITS_PER_FRAME);
+ ptest_bits_coh += COHPSK_BITS_PER_FRAME;
+ if (ptest_bits_coh >= 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<COHPSK_SAMPLES_PER_FRAME; r++) {
+ ch_fdm[r] = cadd(ch_fdm[r], noise[noise_r]);
+ noise_r++;
+ if (noise_r > noise_end)
+ noise_r = 0;
+ }
+
+ /* --------------------------------------------------------*\
+ Demod
+ \*---------------------------------------------------------*/
+
+ cohpsk_demod(coh, rx_bits, &reliable_sync_bit, ch_fdm);
+
+ corr = 0.0;
+ for(i=0; i<COHPSK_BITS_PER_FRAME; i++) {
+ corr += (1.0 - 2.0*(rx_bits[i] & 0x1)) * (1.0 - 2.0*ptest_bits_coh_rx[i]);
+ }
+
+ /* state logic to sybc up to test data */
+
+ next_state = state;
+
+ if (state == 0) {
+ fprintf(stderr, "corr %f\n", corr);
+ if (reliable_sync_bit && (corr == COHPSK_BITS_PER_FRAME)) {
+ next_state = 1;
+ ptest_bits_coh_rx += COHPSK_BITS_PER_FRAME;
+ nerrors = COHPSK_BITS_PER_FRAME - corr;
+ nbits = COHPSK_BITS_PER_FRAME;
+ }
+ }
+
+ if (state == 1) {
+ nerrors += COHPSK_BITS_PER_FRAME - corr;
+ nbits += COHPSK_BITS_PER_FRAME;
+ ptest_bits_coh_rx += COHPSK_BITS_PER_FRAME;
+ if (ptest_bits_coh_rx >= 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;
+}
+