From dc78cc912df65b51a6b83e482ed8fbe74e5a9fdb Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 8 Apr 2015 01:02:36 +0000 Subject: [PATCH] added state transition to lose sync on 3 bad frames. That'll do for a start, we can tune later, even make manually adjustable git-svn-id: https://svn.code.sf.net/p/freetel/code@2107 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/codec2_cohpsk.h | 2 +- codec2-dev/src/cohpsk.c | 35 +++++++++++++++++++++++++------- codec2-dev/src/cohpsk_internal.h | 3 ++- codec2-dev/unittest/tcohpsk.c | 5 +---- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/codec2-dev/src/codec2_cohpsk.h b/codec2-dev/src/codec2_cohpsk.h index 2f94c531..28b2f524 100644 --- a/codec2-dev/src/codec2_cohpsk.h +++ b/codec2-dev/src/codec2_cohpsk.h @@ -44,7 +44,7 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, int rx_bits[], COMP ct_symb_buf[][ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm_frame[], int sync, int *next_sync); void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC], int sync, int *next_sync); void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync); -int sync_state_machine(int sync, int next_sync); +int sync_state_machine(struct COHPSK *coh, int sync, int next_sync); void cohpsk_mod(struct COHPSK *cohpsk, COMP tx_fdm[], int tx_bits[]); void cohpsk_demod(struct COHPSK *cohpsk, int rx_bits[], int *reliable_sync_bit, COMP rx_fdm[]); diff --git a/codec2-dev/src/cohpsk.c b/codec2-dev/src/cohpsk.c index 758aca8a..87dd80e0 100644 --- a/codec2-dev/src/cohpsk.c +++ b/codec2-dev/src/cohpsk.c @@ -65,7 +65,9 @@ static COMP qpsk_mod[] = { {-1.0, 0.0} }; -void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sampling_points[], int t, float f_fine); +static int sampling_points[] = {0, 1, 6, 7}; + +void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine); /*---------------------------------------------------------------------------*\ @@ -238,7 +240,6 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, int rx_bits[], COMP ct_symb_buf[][ int p, r, c, i; COMP corr, rot, pi_on_4, phi_rect; float mag, phi_, amp_; - short sampling_points[] = {0, 1, 6, 7}; pi_on_4.real = cosf(M_PI/4); pi_on_4.imag = sinf(M_PI/4); @@ -338,7 +339,7 @@ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm } -void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sampling_points[], int t, float f_fine) +void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine) { COMP corr, f_fine_rect, f_corr; float mag; @@ -377,7 +378,6 @@ void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sa void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int sync, int *next_sync) { - int sampling_points[] = {0, 1, 6, 7}; int r,c,i,t; float f_fine, mag, max_corr, max_mag; COMP corr; @@ -406,7 +406,7 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int max_corr = 0; for (f_fine=-20; f_fine<=20; f_fine+=1.0) { for (t=0; t max_corr) { max_corr = cabsolute(corr); @@ -425,6 +425,7 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int if (max_corr/max_mag > 0.9) { fprintf(stderr, "in sync!\n"); *next_sync = 4; + coh->sync_timer = 0; } else { *next_sync = 0; @@ -489,6 +490,7 @@ void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync) { coh->ct_symb_ff_buf[r][c] = cmult(coh->ct_symb_ff_buf[r][c], coh->ff_phase); } } + } mag = cabsolute(coh->ff_phase); @@ -498,10 +500,29 @@ void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync) { } -int sync_state_machine(int sync, int next_sync) +int sync_state_machine(struct COHPSK *coh, int sync, int next_sync) { + COMP corr; + float mag; + if (sync == 1) next_sync = 2; + + if (sync == 4) { + + /* check that sync is still good */ + + corr_with_pilots(&corr, &mag, coh, coh->ct, coh->f_fine_est); + + if (cabsolute(corr)/mag < 0.9) + coh->sync_timer++; + + if (coh->sync_timer == 3) { + fprintf(stderr," lost sync ....\n"); + next_sync = 0; + } + } + sync = next_sync; return sync; @@ -602,7 +623,7 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM *reliable_sync_bit = 1; } - sync = sync_state_machine(sync, next_sync); + sync = sync_state_machine(coh, sync, next_sync); coh->sync = sync; } diff --git a/codec2-dev/src/cohpsk_internal.h b/codec2-dev/src/cohpsk_internal.h index 8925f43c..fc72326b 100644 --- a/codec2-dev/src/cohpsk_internal.h +++ b/codec2-dev/src/cohpsk_internal.h @@ -49,7 +49,8 @@ struct COHPSK { COMP ff_phase; COMP ct_symb_ff_buf[NSYMROWPILOT+2][PILOTS_NC]; int sync; - + int sync_timer; + struct FDMDV *fdmdv; }; diff --git a/codec2-dev/unittest/tcohpsk.c b/codec2-dev/unittest/tcohpsk.c index 4d9f050b..9f3762cc 100644 --- a/codec2-dev/unittest/tcohpsk.c +++ b/codec2-dev/unittest/tcohpsk.c @@ -59,7 +59,6 @@ int main(int argc, char *argv[]) COMP ch_fdm_frame[M*NSYMROWPILOT]; COMP rx_fdm_frame_bb[M*NSYMROWPILOT]; COMP ch_symb[NSYMROWPILOT][PILOTS_NC]; - COMP ct_symb_buf[2*NSYMROWPILOT][COHPSK_NC]; int rx_bits[COHPSK_BITS_PER_FRAME]; int tx_bits_log[COHPSK_BITS_PER_FRAME*FRAMES]; @@ -77,7 +76,6 @@ int main(int argc, char *argv[]) FILE *fout; int f, r, c, log_r, log_data_r, noise_r, i; int *ptest_bits_coh, *ptest_bits_coh_end; - float freq_hz; COMP phase_ch; struct FDMDV *fdmdv; @@ -87,7 +85,6 @@ int main(int argc, char *argv[]) COMP rx_filt_log[PILOTS_NC][(P+1)*NSYMROWPILOT*FRAMES]; int rx_filt_log_col_index = 0; float env[NT*P]; - COMP rx_filter_memory[PILOTS_NC][NFILTER]; float rx_timing; COMP tx_onesym[PILOTS_NC]; COMP rx_onesym[PILOTS_NC]; @@ -189,7 +186,7 @@ int main(int argc, char *argv[]) } //printf("f: %d sync: %d next_sync: %d\n", f, sync, next_sync); - sync = sync_state_machine(sync, next_sync); + sync = sync_state_machine(coh, sync, next_sync); /* --------------------------------------------------------*\ Log each vector -- 2.25.1