From c9153acbf61039bcff3fdfc53ec86cd5d3de4070 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 17 May 2015 01:26:20 +0000 Subject: [PATCH] tcohpsk.c not crashing, syncing up OK git-svn-id: https://svn.code.sf.net/p/freetel/code@2131 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/cohpsk.m | 7 ++++-- codec2-dev/octave/tcohpsk.m | 42 ++++++++++++++++++++++++++------ codec2-dev/src/cohpsk.c | 26 +++++++++++--------- codec2-dev/src/cohpsk_internal.h | 3 ++- codec2-dev/unittest/tcohpsk.c | 25 +++++++++++-------- 5 files changed, 71 insertions(+), 32 deletions(-) diff --git a/codec2-dev/octave/cohpsk.m b/codec2-dev/octave/cohpsk.m index 78a1794a..6be9c591 100644 --- a/codec2-dev/octave/cohpsk.m +++ b/codec2-dev/octave/cohpsk.m @@ -643,7 +643,7 @@ function [ch_symb rx_timing rx_filt rx_baseband afdmdv f_est] = rate_Fs_rx_proce endfunction -void update_ct_symb_buf(COMP ct_symb_buf, ch_symb, Nct_sym_buf, Nsymbrowpilot) +function ct_symb_buf = update_ct_symb_buf(ct_symb_buf, ch_symb, Nct_sym_buf, Nsymbrowpilot) % update memory in symbol buffer @@ -719,13 +719,16 @@ function [next_sync cohpsk] = frame_sync_fine_freq_est(cohpsk, ch_symb, sync, ne if sync == 1 corr = 0; mag = 0; + f_fine_rect = exp(-j*cohpsk.f_fine_est*2*pi*sampling_points/Rs)'; for c=1:Nc*Nd + f_corr_vec = f_fine_rect .* ct_symb_buf(cohpsk.ct+sampling_points,c); for p=1:length(sampling_points) - corr += pilot2(p, c-Nc*floor((c-1)/Nc)) * ct_symb_buf(cohpsk.ct + sampling_points,c); + corr += pilot2(p, c-Nc*floor((c-1)/Nc)) * f_corr_vec(p); mag += abs(f_corr_vec(p)); end end cohpsk.ratio = abs(corr)/mag; + %printf("f_fine_est: %f ratio: %f\n", cohpsk.f_fine_est, cohpsk.ratio); end endfunction diff --git a/codec2-dev/octave/tcohpsk.m b/codec2-dev/octave/tcohpsk.m index 42954845..c529ec1a 100644 --- a/codec2-dev/octave/tcohpsk.m +++ b/codec2-dev/octave/tcohpsk.m @@ -26,13 +26,41 @@ randn('state',1); % [ ] set up various tests we use to characterise modem for easy % repeating when we change modem -frames = 100; -foff = -40; -dfoff = -0.5/Fs; -EsNodB = 12; -fading_en = 1; -hf_delay_ms = 2; -compare_with_c = 0; +test = 'compare to c'; + +if strcmp(test, 'compare to c') + frames = 10; + foff = 0; + dfoff = 0; + EsNodB = 12; + fading_en = 0; + hf_delay_ms = 2; + compare_with_c = 1; +end + +% should be BER around 0.015 to 0.02 + +if strcmp(test, 'awgn') + frames = 100; + foff = 0; + dfoff = 0; + EsNodB = 8; + fading_en = 0; + hf_delay_ms = 2; + compare_with_c = 0; +end + +% Similar to AWGN - should be BER around 0.015 to 0.02 + +if strcmp(test, 'fading'); + frames = 100; + foff = -40; + dfoff = -0.5/Fs; + EsNodB = 12; + fading_en = 1; + hf_delay_ms = 2; + compare_with_c = 0; +end EsNo = 10^(EsNodB/10); diff --git a/codec2-dev/src/cohpsk.c b/codec2-dev/src/cohpsk.c index e3e88bf8..d158a0e7 100644 --- a/codec2-dev/src/cohpsk.c +++ b/codec2-dev/src/cohpsk.c @@ -431,16 +431,15 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], coh->ff_rect.real = cosf(coh->f_fine_est*2.0*M_PI/RS); coh->ff_rect.imag = -sinf(coh->f_fine_est*2.0*M_PI/RS); - fprintf(stderr, " fine freq f: %f max_corr: %f max_mag: %f ct: %d\n", coh->f_fine_est, max_corr, max_mag, coh->ct); + fprintf(stderr, " [%d] fine freq f: %6.2f max_coff: %f max_mag: %f ct: %d\n", coh->frame, coh->f_fine_est, max_corr, max_mag, coh->ct); if (max_corr/max_mag > 0.7) { - fprintf(stderr, " [%d] encouraging sync word!\n", coh->frame); + fprintf(stderr, " [%d] encouraging sync word!\n", coh->frame); coh->sync_timer = 0; *next_sync = 1; } else { *next_sync = 0; - fprintf(stderr, " [%d] back to coarse freq offset est...\n", coh->frame); } coh->ratio = max_corr/max_mag; } @@ -458,7 +457,7 @@ void update_ct_symb_buf(COMP ct_symb_buf[][COHPSK_NC*ND], COMP ch_symb[][COHPSK_ ct_symb_buf[r][c] = ct_symb_buf[r+NSYMROWPILOT][c]; } - for(r=NCT_SYMB_BUF-NSYMROWPILOT, i=0; rct, 0.0); + corr_with_pilots(&corr, &mag, coh, coh->ct, coh->f_fine_est); // printf("%f\n", cabsolute(corr)/mag); if (cabsolute(corr)/mag < 0.5) @@ -589,11 +588,12 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[NSYMROWPILOT][COHPSK if (coh->rx_baseband_log) { for(c=0; crx_baseband_log[c*(M+M/P)*LOG_FRAMES*NSYMROWPILOT + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i]; + for(i=0; irx_baseband_log[c*(M+M/P)*LOG_FRAMES*NSYMROWPILOT + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i]; + } } - } - coh->rx_baseband_log_col_index += nin; + coh->rx_baseband_log_col_index += nin; + assert(coh->rx_baseband_log_col_index <= coh->rx_baseband_log_col_sz); } if (coh->rx_filt_log) { @@ -609,12 +609,13 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[NSYMROWPILOT][COHPSK if (coh->ch_symb_log) { for(r=0; rch_symb_log_r++) { for(c=0; cch_symb_log[coh->ch_symb_log_r*COHPSK_NC*ND* + c] = ch_symb[r][c]; + coh->ch_symb_log[coh->ch_symb_log_r*COHPSK_NC*ND + c] = ch_symb[r][c]; } } } } + /*---------------------------------------------------------------------------*\ FUNCTION....: cohpsk_demod() @@ -646,8 +647,9 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM for (i=0; i<(NSW-1)*NSYMROWPILOT*M; i++) coh->ch_fdm_frame_buf[i] = coh->ch_fdm_frame_buf[i+NSYMROWPILOT*M]; - for (j=0; ich_fdm_frame_buf[i] = rx_fdm[j]; + //printf("i: %d j: %d rx_fdm[0]: %f %f\n", i,j, rx_fdm[0].real, rx_fdm[0].imag); next_sync = sync = coh->sync; nin = M; @@ -697,7 +699,7 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM frame_sync_fine_freq_est(coh, &ch_symb[(NSW-1)*NSYMROWPILOT], sync, &next_sync); if (fabs(coh->f_fine_est) > 2.0) { - fprintf(stderr, " [%d] Hmm %f is a bit big so back to coarse est ...\n", coh->frame, coh->f_fine_est); + fprintf(stderr, " [%d] Hmm %f is a bit big :(\n", coh->frame, coh->f_fine_est); next_sync = 0; } } diff --git a/codec2-dev/src/cohpsk_internal.h b/codec2-dev/src/cohpsk_internal.h index 76d81525..ddbb8084 100644 --- a/codec2-dev/src/cohpsk_internal.h +++ b/codec2-dev/src/cohpsk_internal.h @@ -34,7 +34,7 @@ one copy */ #define NSW 3 /* number of sync window frames */ -#define LOG_FRAMES 35 +#define LOG_FRAMES 2 /* todo: re-arrange logging and tcohpsk.c so this can be moved */ #include "fdmdv_internal.h" #include "kiss_fft.h" @@ -66,6 +66,7 @@ struct COHPSK { COMP *rx_baseband_log; int rx_baseband_log_col_index; + int rx_baseband_log_col_sz; COMP *rx_filt_log; int rx_filt_log_col_index; COMP *ch_symb_log; diff --git a/codec2-dev/unittest/tcohpsk.c b/codec2-dev/unittest/tcohpsk.c index 74371dc4..8afee755 100644 --- a/codec2-dev/unittest/tcohpsk.c +++ b/codec2-dev/unittest/tcohpsk.c @@ -44,10 +44,13 @@ #include "comp_prim.h" #include "noise_samples.h" -#define FRAMES LOG_FRAMES /* #defined in cohpsk_internal.h */ -#define RS 50 -#define FOFF 10.5 -#define ESNODB 8.0 +#define FRAMES LOG_FRAMES /* 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 */ + +#define RS 50 +#define FOFF 10.5 +#define ESNODB 8.0 extern float pilots_coh[][PILOTS_NC]; @@ -98,10 +101,11 @@ int main(int argc, char *argv[]) fdmdv = coh->fdmdv; assert(coh != NULL); - coh->rx_filt_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*(P+1)*NSYMROWPILOT*FRAMES); - coh->rx_baseband_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*(M+M/P)*NSYMROWPILOT*FRAMES); - coh->ch_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*FRAMES*COHPSK_NC*ND); - + coh->rx_filt_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*(P+1)*NSYMROWPILOT*FRAMESL); + coh->rx_baseband_log_col_sz = M*NSYMROWPILOT*FRAMESL; + coh->rx_baseband_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*(M+M/P)*NSYMROWPILOT*FRAMESL); + coh->ch_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*FRAMESL*COHPSK_NC*ND); + log_r = log_data_r = noise_r = log_bits = 0; ptest_bits_coh = (int*)test_bits_coh; ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int); @@ -119,7 +123,8 @@ int main(int argc, char *argv[]) /* Main Loop ---------------------------------------------------------------------*/ for(f=0; fframe = f; + /* --------------------------------------------------------*\ Mod \*---------------------------------------------------------*/ @@ -205,7 +210,7 @@ int main(int argc, char *argv[]) //octave_save_complex(fout, "rx_fdm_frame_bb_log_c", (COMP*)rx_fdm_frame_bb_log, 1, M*NSYMROWPILOT*FRAMES, M*NSYMROWPILOT*FRAMES); octave_save_complex(fout, "rx_baseband_log_c", (COMP*)coh->rx_baseband_log, COHPSK_NC*ND, coh->rx_baseband_log_col_index, (M+M/P)*FRAMES*NSYMROWPILOT); octave_save_complex(fout, "rx_filt_log_c", (COMP*)coh->rx_filt_log, COHPSK_NC*ND, coh->rx_filt_log_col_index, (P+1)*FRAMES*NSYMROWPILOT); - octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND); + octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND); octave_save_complex(fout, "ct_symb_ff_log_c", (COMP*)ct_symb_ff_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND); octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); octave_save_float(fout, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND); -- 2.25.1