From f2e000b3cfca639c4bad50724a811e290083a890 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 3 Mar 2013 10:19:59 +0000 Subject: [PATCH] Variable Nc working for NC=14,16,20 git-svn-id: https://svn.code.sf.net/p/freetel/code@1186 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/codec2_fdmdv.h | 8 ++-- codec2-dev/src/fdmdv_demod.c | 58 ++++++++++++++++++++-------- codec2-dev/src/fdmdv_get_test_bits.c | 2 +- codec2-dev/src/fdmdv_put_test_bits.c | 50 ++++++++++++++++++------ 4 files changed, 85 insertions(+), 33 deletions(-) diff --git a/codec2-dev/src/codec2_fdmdv.h b/codec2-dev/src/codec2_fdmdv.h index 649ec530..d85b8902 100644 --- a/codec2-dev/src/codec2_fdmdv.h +++ b/codec2-dev/src/codec2_fdmdv.h @@ -4,10 +4,10 @@ AUTHOR......: David Rowe DATE CREATED: April 14 2012 - A 1400 bit/s Frequency Division Multiplexed Digital Voice (FDMDV) - modem. Used for digital audio over HF SSB. See README_fdmdv.txt for - more information, and fdmdv_mod.c and fdmdv_demod.c for example - usage. + A 1400 bit/s (nominal) Frequency Division Multiplexed Digital Voice + (FDMDV) modem. Used for digital audio over HF SSB. See + README_fdmdv.txt for more information, and fdmdv_mod.c and + fdmdv_demod.c for example usage. The name codec2_fdmdv.h is used to make it unique when "make installed". diff --git a/codec2-dev/src/fdmdv_demod.c b/codec2-dev/src/fdmdv_demod.c index 5414b266..2559ee5b 100644 --- a/codec2-dev/src/fdmdv_demod.c +++ b/codec2-dev/src/fdmdv_demod.c @@ -43,9 +43,6 @@ #include "codec2_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 */ @@ -54,9 +51,9 @@ 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]; + char *packed_bits; + int *rx_bits; + int *codec_bits; COMP rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME]; short rx_fdm_scaled[FDMDV_MAX_SAMPLES_PER_FRAME]; int i, bit, byte, c; @@ -77,10 +74,13 @@ int main(int argc, char *argv[]) float snr_est_log[MAX_FRAMES]; float *rx_spec_log; int max_frames_reached; + int bits_per_fdmdv_frame; + int bits_per_codec_frame; + int bytes_per_codec_frame; int Nc; if (argc < 3) { - printf("usage: %s InputModemRawFile OutputBitFile [OctaveDumpFile]\n", argv[0]); + printf("usage: %s InputModemRawFile OutputBitFile [Nc] [OctaveDumpFile]\n", argv[0]); printf("e.g %s hts1a_fdmdv.raw hts1a.c2\n", argv[0]); exit(1); } @@ -99,9 +99,33 @@ int main(int argc, char *argv[]) exit(1); } - Nc = FDMDV_NC; + if (argc >= 4) { + Nc = atoi(argv[3]); + if ((Nc % 2) != 0) { + fprintf(stderr, "Error number of carriers must be a multiple of 2\n"); + exit(1); + } + if ((Nc < 2) || (Nc > FDMDV_NC_MAX) ) { + fprintf(stderr, "Error number of carriers must be btween 2 and %d\n", FDMDV_NC_MAX); + exit(1); + } + } + else + Nc = FDMDV_NC; + fdmdv = fdmdv_create(Nc); + bits_per_fdmdv_frame = fdmdv_bits_per_frame(fdmdv); + bits_per_codec_frame = 2*fdmdv_bits_per_frame(fdmdv); + assert((bits_per_codec_frame % 8) == 0); /* make sure integer number of bytes per frame */ + bytes_per_codec_frame = bits_per_codec_frame/8; + + /* malloc some buffers that are dependant on Nc */ + + packed_bits = (char*)malloc(bytes_per_codec_frame); assert(packed_bits != NULL); + rx_bits = (int*)malloc(sizeof(int)*bits_per_codec_frame); assert(rx_bits != NULL); + codec_bits = (int*)malloc(2*sizeof(int)*bits_per_fdmdv_frame); assert(codec_bits != NULL); + /* malloc some of the larger variables to prevent out of stack problems */ rx_fdm_log = (COMP*)malloc(sizeof(COMP)*FDMDV_MAX_SAMPLES_PER_FRAME*MAX_FRAMES); @@ -142,7 +166,7 @@ int main(int argc, char *argv[]) rx_timing_log[f] = stats.rx_timing; coarse_fine_log[f] = stats.fest_coarse_fine; sync_bit_log[f] = sync_bit; - memcpy(&rx_bits_log[FDMDV_BITS_PER_FRAME*f], rx_bits, sizeof(int)*FDMDV_BITS_PER_FRAME); + memcpy(&rx_bits_log[bits_per_fdmdv_frame*f], rx_bits, sizeof(int)*bits_per_fdmdv_frame); snr_est_log[f] = stats.snr_est; fdmdv_get_rx_spectrum(fdmdv, &rx_spec_log[f*FDMDV_NSPEC], rx_fdm, nin_prev); @@ -163,20 +187,20 @@ int main(int argc, char *argv[]) case 0: if (sync_bit == 0) { next_state = 1; - memcpy(codec_bits, rx_bits, FDMDV_BITS_PER_FRAME*sizeof(int)); + memcpy(codec_bits, rx_bits, bits_per_fdmdv_frame*sizeof(int)); } else next_state = 0; break; case 1: if (sync_bit == 1) { - memcpy(&codec_bits[FDMDV_BITS_PER_FRAME], rx_bits, FDMDV_BITS_PER_FRAME*sizeof(int)); + memcpy(&codec_bits[bits_per_fdmdv_frame], rx_bits, bits_per_fdmdv_frame*sizeof(int)); /* pack bits, MSB received first */ bit = 7; byte = 0; - memset(packed_bits, 0, BYTES_PER_CODEC_FRAME); - for(i=0; i FDMDV_NC_MAX) ) { + fprintf(stderr, "Error number of carriers must be between 2 and %d\n", FDMDV_NC_MAX); + exit(1); + } + } + else + Nc = FDMDV_NC; + + fdmdv = fdmdv_create(Nc); + + bits_per_fdmdv_frame = fdmdv_bits_per_frame(fdmdv); + bits_per_codec_frame = 2*fdmdv_bits_per_frame(fdmdv); + assert((bits_per_codec_frame % 8) == 0); /* make sure integer number of bytes per frame */ + bytes_per_codec_frame = bits_per_codec_frame/8; + fprintf(stderr, "bits_per_fdmdv_frame: %d bits_per_codec_frame: %d bytes_per_codec_frame: %d\n", + bits_per_fdmdv_frame, bits_per_codec_frame, bytes_per_codec_frame); + + packed_bits = (char*)malloc(bytes_per_codec_frame); + assert(packed_bits != NULL); + rx_bits = (int*)malloc(sizeof(int)*bits_per_codec_frame); + assert(rx_bits != NULL); + total_bit_errors = 0; total_bits = 0; - while(fread(packed_bits, sizeof(char), BYTES_PER_CODEC_FRAME, fin) == BYTES_PER_CODEC_FRAME) { + while(fread(packed_bits, sizeof(char), bytes_per_codec_frame, fin) == bytes_per_codec_frame) { /* unpack bits, MSB first */ bit = 7; byte = 0; - for(i=0; i> bit) & 0x1; //printf("%d 0x%x %d\n", i, packed_bits[byte], rx_bits[i]); bit--; @@ -78,7 +106,7 @@ int main(int argc, char *argv[]) byte++; } } - assert(byte == BYTES_PER_CODEC_FRAME); + assert(byte == bytes_per_codec_frame); fdmdv_put_test_bits(fdmdv, &test_frame_sync, &bit_errors, &ntest_bits, rx_bits); if (test_frame_sync == 1) { @@ -88,7 +116,7 @@ int main(int argc, char *argv[]) } else printf("-"); - fdmdv_put_test_bits(fdmdv, &test_frame_sync, &bit_errors, &ntest_bits, &rx_bits[FDMDV_BITS_PER_FRAME]); + fdmdv_put_test_bits(fdmdv, &test_frame_sync, &bit_errors, &ntest_bits, &rx_bits[bits_per_fdmdv_frame]); if (test_frame_sync == 1) { total_bit_errors += bit_errors; total_bits = total_bits + ntest_bits; -- 2.25.1