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[]);
{-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);
/*---------------------------------------------------------------------------*\
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);
}
-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;
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;
max_corr = 0;
for (f_fine=-20; f_fine<=20; f_fine+=1.0) {
for (t=0; t<NSYMROWPILOT; t++) {
- corr_with_pilots(&corr, &mag, coh, sampling_points, t, f_fine);
+ corr_with_pilots(&corr, &mag, coh, t, f_fine);
//printf(" f: %f t: %d corr: %f %f\n", f_fine, t, corr.real, corr.imag);
if (cabsolute(corr) > max_corr) {
max_corr = cabsolute(corr);
if (max_corr/max_mag > 0.9) {
fprintf(stderr, "in sync!\n");
*next_sync = 4;
+ coh->sync_timer = 0;
}
else {
*next_sync = 0;
coh->ct_symb_ff_buf[r][c] = cmult(coh->ct_symb_ff_buf[r][c], coh->ff_phase);
}
}
+
}
mag = cabsolute(coh->ff_phase);
}
-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;
*reliable_sync_bit = 1;
}
- sync = sync_state_machine(sync, next_sync);
+ sync = sync_state_machine(coh, sync, next_sync);
coh->sync = sync;
}
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];
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;
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];
}
//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