From a5fe4636c891244d22d75cd2ba8cd7f539ba31e0 Mon Sep 17 00:00:00 2001 From: baobrien Date: Mon, 25 Jan 2016 01:49:04 +0000 Subject: [PATCH] Wrote fsk_(get|put)_test_bits; modified fsk_(mod|demod) to use stdin and uint16_t samples git-svn-id: https://svn.code.sf.net/p/freetel/code@2653 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/CMakeLists.txt | 6 ++ codec2-dev/src/fsk_demod.c | 41 ++++++++++--- codec2-dev/src/fsk_get_test_bits.c | 92 ++++++++++++++++++++++++++++ codec2-dev/src/fsk_mod.c | 34 +++++++++-- codec2-dev/src/fsk_put_test_bits.c | 96 ++++++++++++++++++++++++++++++ 5 files changed, 256 insertions(+), 13 deletions(-) create mode 100644 codec2-dev/src/fsk_get_test_bits.c create mode 100644 codec2-dev/src/fsk_put_test_bits.c diff --git a/codec2-dev/src/CMakeLists.txt b/codec2-dev/src/CMakeLists.txt index 94a49c9a..c5211ec7 100644 --- a/codec2-dev/src/CMakeLists.txt +++ b/codec2-dev/src/CMakeLists.txt @@ -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}) diff --git a/codec2-dev/src/fsk_demod.c b/codec2-dev/src/fsk_demod.c index 56679f35..6fd243d9 100644 --- a/codec2-dev/src/fsk_demod.c +++ b/codec2-dev/src/fsk_demod.c @@ -32,16 +32,19 @@ #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;iNsym;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 index 00000000..98cb61ea --- /dev/null +++ b/codec2-dev/src/fsk_get_test_bits.c @@ -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 . +*/ + + +#include +#include +#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 +#include #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; iN; 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 index 00000000..9ae664f9 --- /dev/null +++ b/codec2-dev/src/fsk_put_test_bits.c @@ -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 . +*/ + + +#include +#include +#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;i0){ + 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); +} -- 2.25.1