Wrote fsk_(get|put)_test_bits; modified fsk_(mod|demod) to use stdin and uint16_t...
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 25 Jan 2016 01:49:04 +0000 (01:49 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 25 Jan 2016 01:49:04 +0000 (01:49 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2653 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/CMakeLists.txt
codec2-dev/src/fsk_demod.c
codec2-dev/src/fsk_get_test_bits.c [new file with mode: 0644]
codec2-dev/src/fsk_mod.c
codec2-dev/src/fsk_put_test_bits.c [new file with mode: 0644]

index 94a49c9a47eb346ef9f4a121c7343bfa1b01affe..c5211ec7ca8eb798f3e6d83a484571fa64d8f845 100644 (file)
@@ -241,6 +241,12 @@ target_link_libraries(fsk_mod ${CMAKE_REQUIRED_LIBRARIES} codec2)
 add_executable(fsk_demod fsk_demod.c modem_probe.c octave.c)
 target_link_libraries(fsk_demod ${CMAKE_REQUIRED_LIBRARIES} codec2)
 
+add_executable(fsk_get_test_bits fsk_get_test_bits.c)
+target_link_libraries(fsk_get_test_bits ${CMAKE_REQUIRED_LIBRARIES} codec2)
+
+add_executable(fsk_put_test_bits fsk_put_test_bits.c)
+target_link_libraries(fsk_put_test_bits ${CMAKE_REQUIRED_LIBRARIES} codec2)
+
 add_executable(fm_demod fm_demod.c fm.c)
 target_link_libraries(fm_demod ${CMAKE_REQUIRED_LIBRARIES})
 
index 56679f3531161c805d0b422314ce29d067b1ebf4..6fd243d9c89b37a13d24471d73a7df72097569b1 100644 (file)
 
 #define MODEMPROBE_ENABLE
 #include "modem_probe.h"
+#include "codec2_fdmdv.h"
 
 int main(int argc,char *argv[]){
     struct FSK *fsk;
-    int Fs,Rs,f1,f2;
+    int Fs,Rs;
     FILE *fin,*fout;
     uint8_t *bitbuf;
+    int16_t *rawbuf;
     float *modbuf;
+    int i,t;
     
     if(argc<5){
-        printf("usage: %s SampleFreq SymbolFreq InputModemRawFile OutputOneBitPerCharFile [OctaveLogFile]\n",argv[0]);
+        fprintf(stderr,"usage: %s SampleFreq SymbolFreq InputModemRawFile OutputOneBitPerCharFile [OctaveLogFile]\n",argv[0]);
         exit(1);
     }
     
@@ -50,28 +53,52 @@ int main(int argc,char *argv[]){
     Rs = atoi(argv[2]);
     
     /* Open files */
-    fin = fopen(argv[3],"r");
-    fout = fopen(argv[4],"w");
+    if(strcmp(argv[3],"-")==0){
+               fin = stdin;
+       }else{
+               fin = fopen(argv[3],"r");
+       }
+       
+       if(strcmp(argv[4],"-")==0){
+               fout = stdout;
+       }else{
+               fout = fopen(argv[4],"w");
+       }
+
     
     if(argc>5)
                modem_probe_init("fsk2",argv[5]);
        
     /* set up FSK */
-    fsk = fsk_create(Fs,Rs,0,0);
+    fsk = fsk_create(Fs,Rs,1200,1600);
     
     if(fin==NULL || fout==NULL || fsk==NULL){
-        printf("Couldn't open test vector files\n");
+        fprintf(stderr,"Couldn't open test vector files\n");
         goto cleanup;
     }
     
     /* allocate buffers for processing */
     bitbuf = (uint8_t*)alloca(sizeof(uint8_t)*fsk->Nsym);
+    rawbuf = (int16_t*)alloca(sizeof(int16_t)*(fsk->N+fsk->Ts*2));
     modbuf = (float*)alloca(sizeof(float)*(fsk->N+fsk->Ts*2));
     
     /* Demodulate! */
-    while( fread(modbuf,sizeof(float),fsk_nin(fsk),fin) == fsk_nin(fsk) ){
+    while( fread(rawbuf,sizeof(int16_t),fsk_nin(fsk),fin) == fsk_nin(fsk) ){
+               for(i=0;i<fsk_nin(fsk);i++){
+                       modbuf[i] = ((float)rawbuf[i])/FDMDV_SCALE;
+               }
+               modem_probe_samp_f("t_d_sampin",modbuf,fsk_nin(fsk));
         fsk_demod(fsk,bitbuf,modbuf);
+        for(i=0;i<fsk->Nsym;i++){
+                       t = (int)bitbuf[i];
+                       modem_probe_samp_i("t_d_bitout",&t,1);
+               }
         fwrite(bitbuf,sizeof(uint8_t),fsk->Nsym,fout);
+        
+        if(fin == stdin || fout == stdin){
+                       fflush(fin);
+                       fflush(fout);
+               }
     }
     
     modem_probe_close();
diff --git a/codec2-dev/src/fsk_get_test_bits.c b/codec2-dev/src/fsk_get_test_bits.c
new file mode 100644 (file)
index 0000000..98cb61e
--- /dev/null
@@ -0,0 +1,92 @@
+/*---------------------------------------------------------------------------*\
+
+  FILE........: fsk_get_test_bits.c
+  AUTHOR......: Brady O'Brien
+  DATE CREATED: Januar 2016
+
+  Generates a pseudorandom sequence of bits for testing of fsk_mod and fsk_demod
+
+\*---------------------------------------------------------------------------*/
+
+
+/*
+  Copyright (C) 2016 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 <stdio.h>
+#include <string.h>
+#include "fsk.h"
+#include "codec2_fdmdv.h"
+
+#define FSK_FRAME_SIZE 100
+#define INIT_SEQ {0,1,1,0,1,0,0,1,1,1,1,0,1,1,0,0,0,0,1,0,1,1,0,1,0,1,0,1,0,0,1,1}
+
+uint8_t init[] = INIT_SEQ;
+
+int main(int argc,char *argv[]){
+    int bitcnt;
+    int i,j;
+    FILE *fout;
+    uint8_t *bitbuf;
+    
+    /* Seed the RNG with some constant */
+    srand(158324);
+    
+    if(argc<2){
+        fprintf(stderr,"usage: %s OutputBitsOnePerByte FrameCount\n",argv[0]);
+        exit(1);
+    }
+    
+    /* Extract parameters */
+    bitcnt = atoi(argv[2]);
+       
+       if(strcmp(argv[1],"-")==0){
+               fout = stdout;
+       }else{
+               fout = fopen(argv[1],"w");
+       }
+    
+    if(fout==NULL){
+        fprintf(stderr,"Couldn't open test vector files\n");
+        goto cleanup;
+    }
+    
+    /* allocate buffers for processing */
+    bitbuf = (uint8_t*)alloca(sizeof(uint8_t)*FSK_FRAME_SIZE);
+    
+    /* Write out sync frame and sequence */
+    for(i=0; i<FSK_FRAME_SIZE; i++){
+               bitbuf[i++] = 1;
+               bitbuf[i  ] = 0;
+       }
+       for(i=0;i<sizeof(init);i++){
+               bitbuf[FSK_FRAME_SIZE-sizeof(init)+i]=init[i];
+       }
+       fwrite(bitbuf,sizeof(uint8_t),FSK_FRAME_SIZE,fout);
+    for(i=0; i<bitcnt; i++){
+               for(j=0; j<FSK_FRAME_SIZE; j++){
+                       bitbuf[j] = rand()&0x1;
+               }
+               fwrite(bitbuf,sizeof(uint8_t),FSK_FRAME_SIZE,fout);
+               if(fout == stdout){
+                       fflush(fout);
+               }
+       }
+    
+    cleanup:
+    fclose(fout);
+}
index 8cfb51496a84c32d8c2e12a365575e9f8664ab9f..c5d66e7560bb37d234941c279d2acb4953034126 100644 (file)
 */
 
 #include <stdio.h>
+#include <string.h>
 #include "fsk.h"
+#include "codec2_fdmdv.h"
 
 int main(int argc,char *argv[]){
     struct FSK *fsk;
     int Fs,Rs,f1,f2;
+    int i;
     FILE *fin,*fout;
     uint8_t *bitbuf;
+    int16_t *rawbuf;
     float *modbuf;
     
     if(argc<7){
-        printf("usage: %s SampleFreq SymbolFreq TxFreq1 TxFreq2 InputOneBitPerCharFile OutputModFloatFile\n",argv[0]);
+        fprintf(stderr,"usage: %s SampleFreq SymbolFreq TxFreq1 TxFreq2 InputOneBitPerCharFile OutputModRawFile\n",argv[0]);
         exit(1);
     }
     
@@ -49,26 +53,44 @@ int main(int argc,char *argv[]){
     f1 = atoi(argv[3]);
     f2 = atoi(argv[4]);
     
-    /* Open files */
-    fin = fopen(argv[5],"r");
-    fout = fopen(argv[6],"w");
+    if(strcmp(argv[5],"-")==0){
+               fin = stdin;
+       }else{
+               fin = fopen(argv[5],"r");
+       }
+       
+       if(strcmp(argv[6],"-")==0){
+               fout = stdout;
+       }else{
+               fout = fopen(argv[6],"w");
+       }
+    
     
     /* set up FSK */
     fsk = fsk_create(Fs,Rs,f1,f2);
     
     if(fin==NULL || fout==NULL || fsk==NULL){
-        printf("Couldn't open test vector files\n");
+        fprintf(stderr,"Couldn't open test vector files\n");
         goto cleanup;
     }
     
     /* allocate buffers for processing */
     bitbuf = (uint8_t*)alloca(sizeof(uint8_t)*fsk->Nsym);
+    rawbuf = (int16_t*)alloca(sizeof(int16_t)*fsk->N);
     modbuf = (float*)alloca(sizeof(float)*fsk->N);
     
     /* Modulate! */
     while( fread(bitbuf,sizeof(uint8_t),fsk->Nsym,fin) == fsk->Nsym ){
         fsk_mod(fsk,modbuf,bitbuf);
-        fwrite(modbuf,sizeof(float),fsk->N,fout);
+        for(i=0; i<fsk->N; i++){
+                       rawbuf[i] = (int16_t)(modbuf[i]*(float)FDMDV_SCALE);
+               }
+        fwrite(rawbuf,sizeof(int16_t),fsk->N,fout);
+        
+               if(fin == stdin || fout == stdin){
+                       fflush(fin);
+                       fflush(fout);
+               }
     }
     
     cleanup:
diff --git a/codec2-dev/src/fsk_put_test_bits.c b/codec2-dev/src/fsk_put_test_bits.c
new file mode 100644 (file)
index 0000000..9ae664f
--- /dev/null
@@ -0,0 +1,96 @@
+/*---------------------------------------------------------------------------*\
+
+  FILE........: fsk_get_test_bits.c
+  AUTHOR......: Brady O'Brien
+  DATE CREATED: Januar 2016
+
+  Generates a pseudorandom sequence of bits for testing of fsk_mod and fsk_demod
+
+\*---------------------------------------------------------------------------*/
+
+
+/*
+  Copyright (C) 2016 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 <stdio.h>
+#include <string.h>
+#include "fsk.h"
+#include "codec2_fdmdv.h"
+
+#define FSK_FRAME_SIZE 100
+#define INIT_SEQ {0,1,1,0,1,0,0,1,1,1,1,0,1,1,0,0,0,0,1,0,1,1,0,1,0,1,0,1,0,0,1,1}
+
+uint8_t init[] = INIT_SEQ;
+uint8_t finit[sizeof(init)];
+
+int find_init(uint8_t next){
+       memmove(&finit[0],&finit[1],sizeof(init)-1);
+       finit[sizeof(init)-1] = next;
+       int err = 0;
+       for(int i = 0;i<sizeof(init); i++){
+               if(init[i]!=finit[i]) err++;
+       }
+       return err<=3;
+}
+
+int main(int argc,char *argv[]){
+    int bitcnt,bitcorr;
+    FILE *fin;
+    uint8_t bitbuf,cntbit;;
+    
+    /* Seed the RNG with some constant */
+    srand(158324);
+    
+    if(argc<1){
+        fprintf(stderr,"usage: %s InputBitsOnePerByte \n",argv[0]);
+        exit(1);
+    }
+    
+       
+       if(strcmp(argv[1],"-")==0){
+               fin = stdin;
+       }else{
+               fin = fopen(argv[1],"r");
+       }
+    
+    if(fin==NULL){
+        fprintf(stderr,"Couldn't open test vector files\n");
+        goto cleanup;
+    }
+    bitcnt = 0;
+    bitcorr = 0;
+    
+    /* Find frame start word */
+    do{
+               fread(&bitbuf,sizeof(uint8_t),1,fin);
+       }while(!find_init(bitbuf));
+       
+       
+    while(fread(&bitbuf,sizeof(uint8_t),1,fin)>0){
+               cntbit = rand()&0x1;
+               if( (cntbit>0)==(bitbuf>0))
+                       bitcorr++;
+               bitcnt++;
+               if(fin == stdin)
+                       fflush(fin);
+       }
+       fprintf(stderr,"FSK BER %f, bits tested %d, bit errors %d\n",((float)bitcorr/(float)bitcnt),bitcnt,bitcnt-bitcorr);
+    
+    cleanup:
+    fclose(fin);
+}