/*---------------------------------------------------------------------------*\
FILE........: cohpsk_demod.c
AUTHOR......: David Rowe
DATE CREATED: April 6 2015
Given an input file of raw file (8kHz, 16 bit shorts) of COHPSK modem samples,
outputs a file of bits (note one bit per int, not compressed).
\*---------------------------------------------------------------------------*/
/*
Copyright (C) 2015 David Rowe
All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 2.1, as
published by the Free Software Foundation. This program is
distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include "codec2_cohpsk.h"
#include "cohpsk_defs.h"
#include "cohpsk_internal.h"
#include "codec2_fdmdv.h"
#include "octave.h"
#include "debug_alloc.h"
#define LOG_FRAMES 100
#define SYNC_FRAMES 12 /* sync state uses up extra log storage as we reprocess several times */
int opt_exists(char *argv[], int argc, char opt[]) {
int i;
for (i=0; irx_timing_log = (float*)MALLOC(sizeof(float)*SYNC_FRAMES*logframes*NSYMROWPILOT);
assert(cohpsk->rx_timing_log != NULL);
}
log_data_r = 0;
frames = 0;
nin_frame = COHPSK_NOM_SAMPLES_PER_FRAME;
while(fread(rx_fdm_scaled, sizeof(short), nin_frame, fin) == nin_frame) {
frames++;
cohpsk_set_frame(cohpsk, frames);
/* scale and demod */
for(i=0; irx_bits_lower[i] < 0.0;
fwrite(rx_bits_char, sizeof(char), COHPSK_BITS_PER_FRAME, fout);
for(i=0; irx_bits_upper[i] < 0.0;
fwrite(rx_bits_char, sizeof(char), COHPSK_BITS_PER_FRAME, fout);
}
else {
for(i=0; irx_bits_lower[i];
fwrite(rx_bits_double, sizeof(double), COHPSK_BITS_PER_FRAME, fout);
for(i=0; irx_bits_upper[i];
fwrite(rx_bits_double, sizeof(double), COHPSK_BITS_PER_FRAME, fout);
}
}
if (oct) {
for(r=0; ramp_[r][c];
rx_phi_log[log_data_r*COHPSK_NC*COHPSK_ND+c] = cohpsk->phi_[r][c];
rx_symb_log[log_data_r*COHPSK_NC*COHPSK_ND+c] = cohpsk->rx_symb[r][c];
}
}
f_est_log[frames-1] = cohpsk->f_est;
ratio_log[frames-1] = cohpsk->ratio;
//fprintf(stderr,"ratio: %f\n", cohpsk->ratio);
//printf("frames: %d log_data_r: %d\n", frames, log_data_r);
if (frames == logframes)
oct = 0;
}
}
/* if this is in a pipeline, we probably don't want the usual
buffering to occur */
if (fout == stdout) fflush(stdout);
}
fclose(fin);
fclose(fout);
/* optionally dump Octave files */
if (foct != NULL) {
octave_save_float(foct, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*COHPSK_ND, COHPSK_NC*COHPSK_ND);
octave_save_float(foct, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*COHPSK_ND, COHPSK_NC*COHPSK_ND);
octave_save_complex(foct, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*COHPSK_ND, COHPSK_NC*COHPSK_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);
}
cohpsk_destroy(cohpsk);
return 0;
}