From 6e7c2045a76492cc0dba6ea451e59f321716de50 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 27 May 2015 21:26:36 +0000 Subject: [PATCH] test_cohpsk_ch version working well now, same as octave simulation for awgn and fading channels git-svn-id: https://svn.code.sf.net/p/freetel/code@2155 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tcohpsk.m | 10 ++--- codec2-dev/unittest/tcohpsk.c | 2 +- codec2-dev/unittest/test_cohpsk_ch.c | 63 ++++++++++++++++++---------- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/codec2-dev/octave/tcohpsk.m b/codec2-dev/octave/tcohpsk.m index b0b4a1ea..9b17886c 100644 --- a/codec2-dev/octave/tcohpsk.m +++ b/codec2-dev/octave/tcohpsk.m @@ -57,8 +57,8 @@ randn('state',1); % select which test ---------------------------------------------------------- %test = 'compare to c'; -%test = 'awgn'; -test = 'fading'; +test = 'awgn'; +%test = 'fading'; % some parameters that can be over ridden, e.g. to disable parts of modem @@ -70,7 +70,7 @@ Fs = 7500; % predefined tests .... if strcmp(test, 'compare to c') - frames = 35; + frames = 100; foff = 58.7; dfoff = -0.5/Fs; EsNodB = 8; @@ -84,7 +84,7 @@ end % should be BER around 0.015 to 0.02 if strcmp(test, 'awgn') - frames = 10; + frames = 100; foff = 0; dfoff = -0/Fs; EsNodB = 8; @@ -98,7 +98,7 @@ end if strcmp(test, 'fading'); frames = 100; - foff = 55; + foff = -10.5; dfoff = 0.0/Fs; EsNodB = 12; fading_en = 1; diff --git a/codec2-dev/unittest/tcohpsk.c b/codec2-dev/unittest/tcohpsk.c index 7e2ed1f2..6d258003 100644 --- a/codec2-dev/unittest/tcohpsk.c +++ b/codec2-dev/unittest/tcohpsk.c @@ -44,7 +44,7 @@ #include "comp_prim.h" #include "noise_samples.h" -#define FRAMES 35 /* LOG_FRAMES is #defined in cohpsk_internal.h */ +#define FRAMES 100 /* LOG_FRAMES is #defined in cohpsk_internal.h */ #define SYNC_FRAMES 12 /* sync state uses up extra log storage as we reprocess several times */ #define FRAMESL (SYNC_FRAMES*FRAMES) /* worst case is every frame is out of sync */ diff --git a/codec2-dev/unittest/test_cohpsk_ch.c b/codec2-dev/unittest/test_cohpsk_ch.c index f304eaec..6f9ae139 100644 --- a/codec2-dev/unittest/test_cohpsk_ch.c +++ b/codec2-dev/unittest/test_cohpsk_ch.c @@ -41,15 +41,23 @@ #include "cohpsk_internal.h" #define FRAMES 100 -#define SYNC_FRAMES 12 /* sync state uses up extra log storage as we reprocess several times */ -#define FRAMESL (SYNC_FRAMES*FRAMES) /* worst case is every frame is out of sync */ +#define SYNC_FRAMES 12 /* sync state uses up extra log storage as we reprocess several times */ + +/* defaults with no arguments */ #define FOFF_HZ 0.0 -#define ES_NO_DB 80.0 +#define ES_NO_DB 8.0 #define HF_DELAY_MS 2.0 #define CH_BUF_SZ (4*COHPSK_SAMPLES_PER_FRAME) +/* This file gets generated using the function write_noise_file in tcohpsk.m. You have to run + tcohpsk first (any variant) to load the function into Octave, e.g.: + + octave:17> tcohpsk + octave:18> write_noise_file("../raw/fading_samples.float", 7500, 7500*60) +*/ + #define FADING_FILE_NAME "../../raw/fading_samples.float" int main(int argc, char *argv[]) @@ -60,9 +68,9 @@ int main(int argc, char *argv[]) COMP ch_fdm[COHPSK_SAMPLES_PER_FRAME]; COMP ch_buf[CH_BUF_SZ]; int rx_bits[COHPSK_BITS_PER_FRAME]; - float rx_amp_log[NSYMROW*FRAMES][COHPSK_NC*ND]; - float rx_phi_log[NSYMROW*FRAMES][COHPSK_NC*ND]; - COMP rx_symb_log[NSYMROW*FRAMES][COHPSK_NC*ND]; + float *rx_amp_log; + float *rx_phi_log; + COMP *rx_symb_log; int f, r, i; int *ptest_bits_coh, *ptest_bits_coh_end, *ptest_bits_coh_rx; @@ -73,7 +81,7 @@ int main(int argc, char *argv[]) float EsNo, variance; COMP scaled_noise; float EsNodB, foff_hz; - int fading_en, nhfdelay, ret, nin_frame; + int fading_en, nhfdelay, ret, nin_frame, frames, framesl; float hf_gain; COMP *ch_fdm_delay, aspread, aspread_2ms, delayed, direct; FILE *ffading, *fout; @@ -88,18 +96,29 @@ int main(int argc, char *argv[]) EsNodB = ES_NO_DB; foff_hz = FOFF_HZ; fading_en = 0; - if (argc == 4) { + frames = FRAMES; + if (argc == 5) { EsNodB = atof(argv[1]); foff_hz = atof(argv[2]); fading_en = atoi(argv[3]); + frames = atoi(argv[4]); } fprintf(stderr, "EsNodB: %4.2f foff: %4.2f Hz fading: %d\n", EsNodB, foff_hz, fading_en); coh = cohpsk_create(); assert(coh != NULL); + framesl = SYNC_FRAMES*frames; coh->ch_symb_log_col_sz = COHPSK_NC*ND; - coh->ch_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*FRAMESL*coh->ch_symb_log_col_sz); + coh->ch_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*framesl*coh->ch_symb_log_col_sz); + assert(coh->ch_symb_log != NULL); + + rx_amp_log = (float *)malloc(sizeof(float)*frames*NSYMROW*COHPSK_NC*ND); + assert(rx_amp_log != NULL); + rx_phi_log = (float *)malloc(sizeof(float)*frames*NSYMROW*COHPSK_NC*ND); + assert(rx_phi_log != NULL); + rx_symb_log = (COMP *)malloc(sizeof(COMP)*frames*NSYMROW*COHPSK_NC*ND); + assert(rx_symb_log != NULL); ptest_bits_coh = ptest_bits_coh_rx = (int*)test_bits_coh; ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int); @@ -136,7 +155,7 @@ int main(int argc, char *argv[]) ch_fdm_delay[i].imag = 0.0; } - /* first values are HF gains */ + /* first values in file are HF gains */ for (i=0; i<4; i++) ret = fread(&hf_gain, sizeof(float), 1, ffading); @@ -145,7 +164,8 @@ int main(int argc, char *argv[]) /* Main Loop ---------------------------------------------------------------------*/ - for(f=0; fframe = f; tmp = nin_frame; cohpsk_demod(coh, rx_bits, &reliable_sync_bit, ch_buf, &tmp); ch_buf_n -= nin_frame; + //printf("nin_frame: %d tmp: %d ch_buf_n: %d\n", nin_frame, tmp, ch_buf_n); assert(ch_buf_n >= 0); if (ch_buf_n) memcpy(ch_buf, &ch_buf[nin_frame], sizeof(COMP)*ch_buf_n); @@ -275,9 +292,9 @@ int main(int argc, char *argv[]) for(r=0; ramp_[r][c]; - rx_phi_log[log_data_r][c] = coh->phi_[r][c]; - rx_symb_log[log_data_r][c] = coh->rx_symb[r][c]; + rx_amp_log[log_data_r*COHPSK_NC*ND+c] = coh->amp_[r][c]; + rx_phi_log[log_data_r*COHPSK_NC*ND+c] = coh->phi_[r][c]; + rx_symb_log[log_data_r*COHPSK_NC*ND+c] = coh->rx_symb[r][c]; } } } @@ -287,9 +304,9 @@ int main(int argc, char *argv[]) printf("%4.3f %d %d\n", (float)nerrors/nbits, nbits, nerrors); printf("tx var: %f noise var: %f rx var: %f\n", - tx_pwr/(FRAMES*COHPSK_SAMPLES_PER_FRAME), - noise_pwr/(FRAMES*COHPSK_SAMPLES_PER_FRAME), - rx_pwr/(FRAMES*COHPSK_SAMPLES_PER_FRAME) + tx_pwr/(frames*COHPSK_SAMPLES_PER_FRAME), + noise_pwr/(frames*COHPSK_SAMPLES_PER_FRAME), + rx_pwr/(frames*COHPSK_SAMPLES_PER_FRAME) ); if (fading_en) { free(ch_fdm_delay); -- 2.25.1