kicked off stand alone C program for testing coh psk with channel impairments
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 7 Apr 2015 02:51:22 +0000 (02:51 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 7 Apr 2015 02:51:22 +0000 (02:51 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2105 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/CMakeLists.txt
codec2-dev/src/cohpsk.c
codec2-dev/src/cohpsk_put_test_bits.c [new file with mode: 0644]
codec2-dev/unittest/CMakeLists.txt
codec2-dev/unittest/test_cohpsk_ch.c [new file with mode: 0644]

index 1cc1cc0b51f424ec939cc26cb66e6fc35863c38b..903961ca889e516082d78c384be9288b0a266344 100644 (file)
@@ -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}
index 647d84b5664b2f5f9eeeef5ed6f3d1dfa1f6ccea..1ecc0177a3446483ca61a580170761bce9cebeb4 100644 (file)
@@ -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 (file)
index 0000000..7b369e8
--- /dev/null
@@ -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 <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;
+}
+
index 7d1e98cb592471e02620a3a7cf1250adb3069c61..ad4ba7e283648d6f695dfcb888fcc9e99fe2c74b 100644 (file)
@@ -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 (file)
index 0000000..089a54f
--- /dev/null
@@ -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 <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;
+}
+