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
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
% [ ] 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);
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;
}
ct_symb_buf[r][c] = ct_symb_buf[r+NSYMROWPILOT][c];
}
- for(r=NCT_SYMB_BUF-NSYMROWPILOT, i=0; r<NSYMROWPILOT; r++, i++) {
+ for(r=NCT_SYMB_BUF-NSYMROWPILOT, i=0; r<NCT_SYMB_BUF; r++, i++) {
for(c=0; c<COHPSK_NC*ND; c++)
ct_symb_buf[r][c] = ch_symb[i][c];
}
/* check that sync is still good, fall out of sync on consecutive bad frames */
- corr_with_pilots(&corr, &mag, coh, coh->ct, 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)
if (coh->rx_baseband_log) {
for(c=0; c<COHPSK_NC*ND; c++) {
- for(i=0; i<nin; i++) {
- coh->rx_baseband_log[c*(M+M/P)*LOG_FRAMES*NSYMROWPILOT + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i];
+ for(i=0; i<nin; i++) {
+ coh->rx_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) {
if (coh->ch_symb_log) {
for(r=0; r<NSYMROWPILOT; r++, coh->ch_symb_log_r++) {
for(c=0; c<COHPSK_NC*ND; c++) {
- coh->ch_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()
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; i<NSYMROWPILOT*M; i++,j++)
+ for (j=0; i<NSW*NSYMROWPILOT*M; i++,j++)
coh->ch_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;
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;
}
}
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"
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;
#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];
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);
/* Main Loop ---------------------------------------------------------------------*/
for(f=0; f<FRAMES; f++) {
-
+ coh->frame = f;
+
/* --------------------------------------------------------*\
Mod
\*---------------------------------------------------------*/
//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);