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})
#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);
}
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();
--- /dev/null
+/*---------------------------------------------------------------------------*\
+
+ 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);
+}
*/
#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);
}
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:
--- /dev/null
+/*---------------------------------------------------------------------------*\
+
+ 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);
+}