From d04474d072e8e3a23fbb0957daee4a37d6ec8d60 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 28 Feb 2013 04:03:37 +0000 Subject: [PATCH] mod works with variable Nc, 10,14, 20 tested using Matlab demod. Demod currently broken git-svn-id: https://svn.code.sf.net/p/freetel/code@1177 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/fdmdv.c | 27 +++++++++------ codec2-dev/src/fdmdv_get_test_bits.c | 2 ++ codec2-dev/src/fdmdv_internal.h | 7 ++-- codec2-dev/src/test_bits.h | 50 +++++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 15 deletions(-) diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 8527a32a..03c3c3d8 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -125,9 +125,9 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc) int c, i, k; float carrier_freq; - assert(NC == FDMDV_NC); /* check public and private #defines match */ + //assert(NC == FDMDV_NC); /* check public and private #defines match */ assert(Nc <= NC); - assert(FDMDV_BITS_PER_FRAME == NC*NB); + //assert(FDMDV_BITS_PER_FRAME == NC*NB); assert(FDMDV_NOM_SAMPLES_PER_FRAME == M); assert(FDMDV_MAX_SAMPLES_PER_FRAME == (M+M/P)); @@ -137,9 +137,13 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc) f->Nc = Nc; + f->ntest_bits = Nc*NB*4; f->current_test_bit = 0; - for(i=0; irx_test_bits_mem = (int*)malloc(sizeof(int)*f->ntest_bits); + assert(f->rx_test_bits_mem != NULL); + for(i=0; intest_bits; i++) f->rx_test_bits_mem[i] = 0; + assert((sizeof(test_bits)/sizeof(int)) >= f->ntest_bits); f->tx_pilot_bit = 0; @@ -256,6 +260,7 @@ void CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv) assert(fdmdv != NULL); KISS_FFT_FREE(fdmdv->fft_pilot_cfg); KISS_FFT_FREE(fdmdv->fft_cfg); + free(fdmdv->rx_test_bits_mem); free(fdmdv); } @@ -279,11 +284,12 @@ int CODEC2_WIN32SUPPORT fdmdv_bits_per_frame(struct FDMDV *fdmdv) void CODEC2_WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *f, int tx_bits[]) { int i; + int bits_per_frame = fdmdv_bits_per_frame(f); - for(i=0; icurrent_test_bit]; f->current_test_bit++; - if (f->current_test_bit > (NTEST_BITS-1)) + if (f->current_test_bit > (f->ntest_bits-1)) f->current_test_bit = 0; } } @@ -1087,31 +1093,32 @@ void CODEC2_WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync, { int i,j; float ber; + int bits_per_frame = fdmdv_bits_per_frame(f); /* Append to our memory */ - for(i=0,j=FDMDV_BITS_PER_FRAME; intest_bits-bits_per_frame; i++,j++) f->rx_test_bits_mem[i] = f->rx_test_bits_mem[j]; - for(i=NTEST_BITS-FDMDV_BITS_PER_FRAME,j=0; intest_bits-bits_per_frame,j=0; intest_bits; i++,j++) f->rx_test_bits_mem[i] = rx_bits[j]; /* see how many bit errors we get when checked against test sequence */ *bit_errors = 0; - for(i=0; intest_bits; i++) { *bit_errors += test_bits[i] ^ f->rx_test_bits_mem[i]; //printf("%d %d %d %d\n", i, test_bits[i], f->rx_test_bits_mem[i], test_bits[i] ^ f->rx_test_bits_mem[i]); } /* if less than a thresh we are aligned and in sync with test sequence */ - ber = (float)*bit_errors/NTEST_BITS; + ber = (float)*bit_errors/f->ntest_bits; *sync = 0; if (ber < 0.2) *sync = 1; - *ntest_bits = NTEST_BITS; + *ntest_bits = f->ntest_bits; } diff --git a/codec2-dev/src/fdmdv_get_test_bits.c b/codec2-dev/src/fdmdv_get_test_bits.c index 04db3d0b..c45d80f8 100644 --- a/codec2-dev/src/fdmdv_get_test_bits.c +++ b/codec2-dev/src/fdmdv_get_test_bits.c @@ -68,6 +68,8 @@ int main(int argc, char *argv[]) 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); diff --git a/codec2-dev/src/fdmdv_internal.h b/codec2-dev/src/fdmdv_internal.h index 455cc013..8c308a91 100644 --- a/codec2-dev/src/fdmdv_internal.h +++ b/codec2-dev/src/fdmdv_internal.h @@ -43,7 +43,7 @@ #define FS 8000 /* sample rate in Hz */ #define T (1.0/FS) /* sample period in seconds */ #define RS 50 /* symbol rate in Hz */ -#define NC 14 /* number of data carriers (plus one pilot in the centre) */ +#define NC 20 /* max number of data carriers (plus one pilot in the centre) */ #define NB 2 /* Bits/symbol for QPSK modulation */ #define RB (NC*RS*NB) /* bit rate */ #define M (FS/RS) /* oversampling factor */ @@ -56,8 +56,6 @@ #define P 4 /* oversample factor used for initial rx symbol filtering */ #define NFILTERTIMING (M+NFILTER+M) /* filter memory used for resampling after timing estimation */ -#define NTEST_BITS (NC*NB*4) /* length of test bit sequence */ - #define NPILOT_LUT (4*M) /* number of pilot look up table samples */ #define NPILOTCOEFF 30 /* number of FIR filter coeffs in LP filter */ #define NPILOTBASEBAND (NPILOTCOEFF+M+M/P) /* number of pilot baseband samples reqd for pilot LPF */ @@ -86,8 +84,9 @@ struct FDMDV { /* test data (test frame) states */ + int ntest_bits; int current_test_bit; - int rx_test_bits_mem[NTEST_BITS]; + int *rx_test_bits_mem; /* Modulator */ diff --git a/codec2-dev/src/test_bits.h b/codec2-dev/src/test_bits.h index 19d7a92f..d1c01a03 100644 --- a/codec2-dev/src/test_bits.h +++ b/codec2-dev/src/test_bits.h @@ -112,5 +112,53 @@ const int test_bits[]={ 1, 1, 1, - 0 + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 1, + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 1, + 1, + 0, + 0, + 0, + 1, + 0, + 1, + 1, + 1, + 0, + 1 }; -- 2.25.1