--- /dev/null
+% cohpsk_demod.m
+% David Rowe May 2015
+%
+% Plot Octave outputs from cohpsk_demod_plot
+
+Nc=7; Nd=2;
+
+load ../build_linux/src/cohpsk_demod.txt
+load ../build_linux/src/cohpsk_put_test_bits.txt
+
+figure(1)
+clf;
+
+% plot combined signals to show diversity gains
+
+combined = rx_symb_log_c(:,1:Nc);
+for d=2:Nd
+ combined += rx_symb_log_c(:, (d-1)*Nc+1:d*Nc);
+end
+plot(combined*exp(j*pi/4)/sqrt(Nd),'+')
+title('Scatter');
+axis([-2 2 -2 2])
+
+figure(2)
+clf;
+subplot(211)
+plot(rx_phi_log_c)
+title('phase')
+subplot(212)
+plot(rx_amp_log_c)
+title('amplitide')
+
+figure(3)
+subplot(211)
+plot(rx_timing_log_c)
+title('rx timing');
+subplot(212)
+stem(ratio_log_c)
+title('Sync ratio');
+
+figure(4);
+clf;
+plot(nerr_log_c);
+title('Bit Errors');
+
+figure(5);
+clf;
+plot(error_positions_hist_c);
+title('Error Position Histogram');
#include "octave.h"
#define LOG_FRAMES 100
+#define SYNC_FRAMES 12 /* sync state uses up extra log storage as we reprocess several times */
int main(int argc, char *argv[])
{
float *rx_amp_log;
float *rx_phi_log;
COMP *rx_symb_log;
+ float f_est_log[LOG_FRAMES], ratio_log[LOG_FRAMES];
int i, r, c, log_data_r, oct, logframes;
if (argc < 3) {
assert(rx_phi_log != NULL);
rx_symb_log = (COMP *)malloc(sizeof(COMP)*logframes*NSYMROW*COHPSK_NC*ND);
assert(rx_symb_log != NULL);
+ cohpsk->rx_timing_log = (float*)malloc(sizeof(float)*SYNC_FRAMES*logframes*NSYMROWPILOT);
+ assert(cohpsk->rx_timing_log != NULL);
}
log_data_r = 0;
rx_symb_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->rx_symb[r][c];
}
}
+
+ f_est_log[frames-1] = cohpsk->f_est;
+ ratio_log[frames-1] = cohpsk->ratio;
+
//printf("frames: %d log_data_r: %d\n", frames, log_data_r);
if (frames == logframes)
oct = 0;
octave_save_float(foct, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);
octave_save_float(foct, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);
octave_save_complex(foct, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);
+ octave_save_float(foct, "rx_timing_log_c", (float*)cohpsk->rx_timing_log, 1, cohpsk->rx_timing_log_index, cohpsk->rx_timing_log_index);
+ octave_save_float(foct, "f_est_log_c", f_est_log, 1, logframes, logframes);
+ octave_save_float(foct, "ratio_log_c", ratio_log, 1, logframes, logframes);
fclose(foct);
}
#include "codec2_cohpsk.h"
#include "test_bits_coh.h"
+#include "octave.h"
+
+#define LOG_FRAMES 100
int main(int argc, char *argv[])
{
- FILE *fin;
+ FILE *fin, *foct;
int rx_bits[COHPSK_BITS_PER_FRAME];
- int *ptest_bits_coh, *ptest_bits_coh_end;
+ int *ptest_bits_coh, *ptest_bits_coh_end;
int state, next_state, i, nbits, errors, nerrors;
- int error_positions_hist[COHPSK_BITS_PER_FRAME];
+ int error_positions_hist[COHPSK_BITS_PER_FRAME], logframes;
+ int nerr_log[LOG_FRAMES];
for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
error_positions_hist[i] = 0;
if (argc < 2) {
- printf("usage: %s InputOneBitPerIntFile\n", argv[0]);
+ fprintf(stderr, "usage: %s InputOneBitPerIntFile [OctaveLogFile]\n", argv[0]);
exit(1);
}
exit(1);
}
+ foct = NULL;
+ logframes = 0;
+ if (argc == 3) {
+ if ( (foct = fopen(argv[2],"wt")) == NULL ) {
+ fprintf(stderr, "Error opening output Octave file: %s: %s.\n",
+ argv[2], strerror(errno));
+ exit(1);
+ }
+ }
+
+ for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
+ error_positions_hist[i] = 0;
+
ptest_bits_coh = (int*)test_bits_coh;
ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
+ state = 0; nbits = 0; nerrors = 0;
while (fread(rx_bits, sizeof(int), COHPSK_BITS_PER_FRAME, fin) == COHPSK_BITS_PER_FRAME) {
errors = 0;
for(i=0; i<COHPSK_BITS_PER_FRAME; i++) {
errors += (rx_bits[i] & 0x1) ^ ptest_bits_coh[i];
if (state == 1) {
- if ((rx_bits[i] & 0x1) ^ ptest_bits_coh[i])
+ if ((state == 1 ) && (rx_bits[i] & 0x1) ^ ptest_bits_coh[i])
error_positions_hist[i]++;
}
}
+ //printf("state: %d errors: %d nerrors: %d\n", state, errors, nerrors);
/* state logic */
ptest_bits_coh += COHPSK_BITS_PER_FRAME;
nerrors = errors;
nbits = COHPSK_BITS_PER_FRAME;
+ if (logframes < LOG_FRAMES)
+ nerr_log[logframes++] = errors;
}
}
if (ptest_bits_coh >= ptest_bits_coh_end) {
ptest_bits_coh = (int*)test_bits_coh;
}
+ if (logframes < LOG_FRAMES)
+ nerr_log[logframes++] = errors;
}
state = next_state;
if (fin == stdin) fflush(stdin);
}
+ if (foct != NULL) {
+ octave_save_int(foct, "nerr_log_c", nerr_log, 1, logframes);
+ octave_save_int(foct, "error_positions_hist_c", error_positions_hist, 1, logframes);
+ fclose(foct);
+ }
+
fclose(fin);
- printf("BER: %4.3f Nbits: %d Nerrors: %d\n", (float)nerrors/nbits, nbits, nerrors);
+ fprintf(stderr, "BER: %4.3f Nbits: %d Nerrors: %d\n", (float)nerrors/nbits, nbits, nerrors);
return 0;
}