/*---------------------------------------------------------------------------*\ FILE........: fdmdv_demod.c AUTHOR......: David Rowe DATE CREATED: April 30 2012 Given an input raw file (8kHz, 16 bit shorts) of FDMDV modem samples outputs a file of bits. The output file is assumed to be arranged as codec frames of 56 bits (7 bytes) which are received as two 28 bit modem frames. Demod states can be optionally logged to an Octave file for display using the Octave script fdmdv_demod_c.m. This is useful for checking demod performance. \*---------------------------------------------------------------------------*/ /* Copyright (C) 2012 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 #include #include #include #include "fdmdv.h" #include "octave.h" #define BITS_PER_CODEC_FRAME (2*FDMDV_BITS_PER_FRAME) #define BYTES_PER_CODEC_FRAME (BITS_PER_CODEC_FRAME/8) /* lof of information we want to dump to Octave */ #define MAX_FRAMES 50*60 /* 1 minute at 50 symbols/s */ int main(int argc, char *argv[]) { FILE *fin, *fout; struct FDMDV *fdmdv; char packed_bits[BYTES_PER_CODEC_FRAME]; int rx_bits[FDMDV_BITS_PER_FRAME]; int codec_bits[2*FDMDV_BITS_PER_FRAME]; COMP rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME]; short rx_fdm_scaled[FDMDV_MAX_SAMPLES_PER_FRAME]; int i, bit, byte, c; int nin, nin_prev; int sync_bit; int state, next_state; int f; FILE *foct = NULL; struct FDMDV_STATS stats; float *rx_fdm_log; int rx_fdm_log_col_index; COMP rx_symbols_log[FDMDV_NSYM][MAX_FRAMES]; int coarse_fine_log[MAX_FRAMES]; float rx_timing_log[MAX_FRAMES]; float foff_log[MAX_FRAMES]; int sync_bit_log[MAX_FRAMES]; int rx_bits_log[FDMDV_BITS_PER_FRAME*MAX_FRAMES]; float snr_est_log[MAX_FRAMES]; float *rx_spec_log; int max_frames_reached; if (argc < 3) { printf("usage: %s InputModemRawFile OutputBitFile [OctaveDumpFile]\n", argv[0]); printf("e.g %s hts1a_fdmdv.raw hts1a.c2\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 modem sample file: %s: %s.\n", argv[1], strerror(errno)); exit(1); } if (strcmp(argv[2], "-") == 0) fout = stdout; else if ( (fout = fopen(argv[2],"wb")) == NULL ) { fprintf(stderr, "Error opening output bit file: %s: %s.\n", argv[2], strerror(errno)); exit(1); } /* malloc some of the bigger variables to prevent out of stack problems */ rx_fdm_log = (float*)malloc(sizeof(float)*FDMDV_MAX_SAMPLES_PER_FRAME*MAX_FRAMES); assert(rx_fdm_log != NULL); rx_spec_log = (float*)malloc(sizeof(float)*FDMDV_NSPEC*MAX_FRAMES); assert(rx_spec_log != NULL); fdmdv = fdmdv_create(); f = 0; state = 0; nin = FDMDV_NOM_SAMPLES_PER_FRAME; rx_fdm_log_col_index = 0; max_frames_reached = 0; while(fread(rx_fdm_scaled, sizeof(short), nin, fin) == nin) { for(i=0; i