From 8ce5bda9485f3be78a6f6039ce67f13291b65002 Mon Sep 17 00:00:00 2001 From: drowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63> Date: Thu, 19 Apr 2018 23:55:49 +0000 Subject: [PATCH] reporting iters/pcc during sync, and cohpsk cmd line interface and results re-written to help test ofdm git-svn-id: https://svn.code.sf.net/p/freetel/code@3511 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/cohpsk_ch.c | 113 +++++++++++++++++++++++++----------- codec2-dev/src/ofdm_demod.c | 37 +++++++----- 2 files changed, 100 insertions(+), 50 deletions(-) diff --git a/codec2-dev/src/cohpsk_ch.c b/codec2-dev/src/cohpsk_ch.c index 76a5a31d..9ce6ab83 100644 --- a/codec2-dev/src/cohpsk_ch.c +++ b/codec2-dev/src/cohpsk_ch.c @@ -56,15 +56,28 @@ #define PAPR_TARGET 7.0 /* This file gets generated using the function write_noise_file in tcohpsk.m. You have to run - tcohpsk first (any variant) to load the function into Octave, e.g.: + tcohpsk first (any variant) to load the function into Octave, e.g. for Fs=7500Hz: - octave:17> tcohpsk - octave:18> write_noise_file("../raw/fading_samples.float", 7500, 7500*60) + octave:26> cohpsk_ch_fading("../raw/fast_fading_samples.float", 8000, 1.0, 8000*60) + octave:27> cohpsk_ch_fading("../raw/slow_fading_samples.float", 8000, 0.1, 8000*60) + + Note: for Fs=8000Hz operation 7500 Hz is OK - these are just the two path fading complex numbers, + a few % different in fading bandwidth won't matter. */ #define FAST_FADING_FILE_NAME "../../raw/fast_fading_samples.float" #define SLOW_FADING_FILE_NAME "../../raw/slow_fading_samples.float" +int opt_exists(char *argv[], int argc, char opt[]) { + int i; + for (i=0; i<argc; i++) { + if (strcmp(argv[i], opt) == 0) { + return i; + } + } + return 0; +} + int main(int argc, char *argv[]) { FILE *fin, *ffading, *fout; @@ -85,10 +98,10 @@ int main(int argc, char *argv[]) float hf_gain; COMP *ch_fdm_delay = NULL, aspread, aspread_2ms, delayed, direct; float tx_pwr, tx_pwr_fade, noise_pwr; - int frames, i, j, k, ret, clipped; + int frames, i, j, k, arg, Fs, ret, clipped, ssbfilt_en; float sam, peak, inclip, papr, CNo, snr3k, EbNo700; - - if (argc == 7) { + + if (argc > 3) { if (strcmp(argv[1], "-") == 0) fin = stdin; else if ( (fin = fopen(argv[1],"rb")) == NULL ) { fprintf(stderr, "Error opening input modem raw file: %s: %s.\n", @@ -104,15 +117,41 @@ int main(int argc, char *argv[]) } NodB = atof(argv[3]); - foff_hz = atof(argv[4]); - fading_en = atoi(argv[5]); - inclip = atof(argv[6]); + + Fs = COHPSK_FS; + if ((arg = opt_exists(argv, argc, "--Fs"))) { + Fs = atoi(argv[arg+1]); + } + + foff_hz = 0.0; + if ((arg = opt_exists(argv, argc, "-f"))) { + foff_hz = atoi(argv[arg+1]); + } + fading_en = 0; + if (opt_exists(argv, argc, "--fast")) { + fading_en = 1; + } + if (opt_exists(argv, argc, "--slow")) { + fading_en = 2; + } + inclip = 1.0; + if ((arg = opt_exists(argv, argc, "--clip"))) { + inclip = atof(argv[arg+1]); + } + ssbfilt_en = 1; + if ((arg = opt_exists(argv, argc, "--ssbfilt"))) { + ssbfilt_en = atof(argv[arg+1]); + } } else { - fprintf(stderr, "usage: %s InputRealModemRawFileFs7500Hz OutputRealModemRawFileFs7500Hz No(dB/Hz) FoffHz Fading[0-none 1-fast 2-slow] InputClip0to1\n", argv[0]); + fprintf(stderr, "usage: %s InputRealModemRawFile OutputRealModemRawFile No(dB/Hz) [--Fs SampleRateHz]" + " [-f FoffHz] [--slow] [--fast] [--clip 0to1] [--ssbfilt 0|1]\n", argv[0]); exit(1); } - fprintf(stderr, "NodB: %4.2f foff: %4.2f Hz fading: %d inclip: %4.2f\n", NodB, foff_hz, fading_en, inclip); + fprintf(stderr, "cohpsk_ch ----------------------------------------------------------------------------------\n"); + fprintf(stderr, "Fs: %d NodB: %4.2f foff: %4.2f Hz fading: %d inclip: %4.2f ssbfilt: %d\n", + Fs, NodB, foff_hz, fading_en, inclip, ssbfilt_en); + fprintf(stderr, "cohpsk_ch ----------------------------------------------------------------------------------\n"); phase_ch.real = 1.0; phase_ch.imag = 0.0; noise_r = 0; @@ -121,7 +160,7 @@ int main(int argc, char *argv[]) /* N = var = NoFs */ No = pow(10.0, NodB/10.0); - variance = COHPSK_FS*No; + variance = Fs*No; tx_pwr = tx_pwr_fade = noise_pwr = 0.0; clipped = 0; @@ -135,19 +174,21 @@ int main(int argc, char *argv[]) if (fading_en == 1) { ffading = fopen(FAST_FADING_FILE_NAME, "rb"); if (ffading == NULL) { - printf("Can't find fast fading file: %s\n", FAST_FADING_FILE_NAME); + fprintf(stderr, "-----------------------------------------------------\n"); + fprintf(stderr, "cohpsk_ch ERROR: Can't find fast fading file: %s\n", FAST_FADING_FILE_NAME); + fprintf(stderr, "-----------------------------------------------------\n"); exit(1); } - nhfdelay = floor(FAST_FADING_DELAY_MS*COHPSK_FS/1000); + nhfdelay = floor(FAST_FADING_DELAY_MS*Fs/1000); } if (fading_en == 2) { ffading = fopen(SLOW_FADING_FILE_NAME, "rb"); if (ffading == NULL) { - printf("Can't find slow fading file: %s\n", SLOW_FADING_FILE_NAME); + fprintf(stderr, "Can't find slow fading file: %s\n", SLOW_FADING_FILE_NAME); exit(1); } - nhfdelay = floor(SLOW_FADING_DELAY_MS*COHPSK_FS/1000); + nhfdelay = floor(SLOW_FADING_DELAY_MS*Fs/1000); } ch_fdm_delay = (COMP*)malloc((nhfdelay+COHPSK_NOM_SAMPLES_PER_FRAME)*sizeof(COMP)); @@ -161,7 +202,7 @@ int main(int argc, char *argv[]) for (i=0; i<4; i++) ret = fread(&hf_gain, sizeof(float), 1, ffading); - fprintf(stderr, "hf_gain: %f\n", hf_gain); + //fprintf(stderr, "hf_gain: %f\n", hf_gain); } for(i=0; i<HT_N; i++) { @@ -240,9 +281,9 @@ int main(int argc, char *argv[]) for(i=0; i<BUF_N; i++) { ret = fread(&aspread, sizeof(COMP), 1, ffading); - assert(ret == 1); + if (ret == 0) goto finish; ret = fread(&aspread_2ms, sizeof(COMP), 1, ffading); - assert(ret == 1); + if (ret == 0) goto finish; //printf("%f %f %f %f\n", aspread.real, aspread.imag, aspread_2ms.real, aspread_2ms.imag); direct = cmult(aspread, ch_fdm[i]); @@ -279,9 +320,14 @@ int main(int argc, char *argv[]) for(i=0, j=SSBFILT_N; i<BUF_N; i++,j++) { ssbfiltbuf[j] = ch_fdm[i].real; - ssbfiltout[i] = 0.0; - for(k=0; k<SSBFILT_N; k++) { - ssbfiltout[i] += ssbfiltbuf[j-k]*ssbfilt_coeff[k]; + if (ssbfilt_en) { + ssbfiltout[i] = 0.0; + for(k=0; k<SSBFILT_N; k++) { + ssbfiltout[i] += ssbfiltbuf[j-k]*ssbfilt_coeff[k]; + } + } + else { + ssbfiltout[i] = ch_fdm[i].real; } } @@ -314,27 +360,26 @@ int main(int argc, char *argv[]) if (fin == stdin) fflush(stdin); } + finish: fclose(fin); fclose(fout); - fprintf(stderr, "peak pwr.....: %7.2f\nav input pwr.: %7.2f\nav pwr fading: %7.2f\nnoise pwr....: %7.2f\nclipping.....: %7.2f %%\n", + fprintf(stderr, "cohpsk_ch -----------------------------------------------------------------------------\n"); + /* + fprintf(stderr, "peak pwr: %7.2f av input pwr.: %7.2f av fading pwr: %7.2f noise pwr....: %7.2f\n", peak*peak, tx_pwr/(frames*BUF_N), tx_pwr_fade/(frames*BUF_N), - noise_pwr/(frames*BUF_N), - 100.0*clipped/frames + noise_pwr/(frames*BUF_N) ); + */ papr = 10*log10(peak*peak/(tx_pwr/(frames*BUF_N))); - CNo = 10*log10(tx_pwr/(noise_pwr/(COHPSK_FS/2))); // single sided spctrum magic IDFK! + CNo = 10*log10(tx_pwr/(noise_pwr/(Fs/2))); // single sided spectrum magic IDFK! snr3k = CNo - 10*log10(3000); - EbNo700 = CNo - 10*log10(700) - 10*log10(6.0/4.0); // divide by bit rate and pilot overhead - fprintf(stderr, "PAPR (dB)....: %7.2f (target %3.2f)\nC/No (dB)....: %7.2f\nSNR3k........: %7.2f\nEb/No(Rb=700): %7.2f\n", - papr, - PAPR_TARGET, - CNo, - snr3k, - EbNo700 - ); + EbNo700 = CNo - 10*log10(700); // divide by coded data bit rate + fprintf(stderr, "PAPR (dB) : %4.1f C/No (dB): %4.1f SNR3k: %5.2f Eb/No(Rb=700): %5.2f\n", + papr, CNo, snr3k,EbNo700); + fprintf(stderr, "cohpsk_ch -----------------------------------------------------------------------------\n"); return 0; } diff --git a/codec2-dev/src/ofdm_demod.c b/codec2-dev/src/ofdm_demod.c index 8fc12874..dc625e53 100644 --- a/codec2-dev/src/ofdm_demod.c +++ b/codec2-dev/src/ofdm_demod.c @@ -155,8 +155,11 @@ int main(int argc, char *argv[]) } int Nerrs_raw[interleave_frames]; int Nerrs_coded[interleave_frames]; + int iter[interleave_frames]; + int parityCheckCount[interleave_frames]; + for(i=0; i<interleave_frames; i++) { - Nerrs_raw[i] = Nerrs_coded[i] = 0; + Nerrs_raw[i] = Nerrs_coded[i] = iter[i] = parityCheckCount[i] = 0; } ofdm = ofdm_create(OFDM_CONFIG_700D); @@ -175,7 +178,6 @@ int main(int argc, char *argv[]) char rx_bits_char[Nbitsperframe]; int rx_uw[OFDM_NUWBITS]; f = 0; Nerrs = Terrs = Tbits = Terrs2 = Tbits2 = Terrs_coded = Tbits_coded = frame_count = 0; - int parityCheckCount, iter; float EsNo = 10; fprintf(stderr,"Warning EsNo: %f hard coded\n", EsNo); @@ -246,15 +248,15 @@ int main(int argc, char *argv[]) char next_sync_state_interleaver[OFDM_STATE_STR]; strcpy(next_sync_state_interleaver, ofdm->sync_state_interleaver); - if (strcmp(ofdm->sync_state_interleaver,"search") == 0) { + if ((strcmp(ofdm->sync_state_interleaver,"search") == 0) && (ofdm->frame_count >= (interleave_frames-1))) { symbols_to_llrs(llr, codeword_symbols_de, codeword_amps_de, EsNo, coded_syms_per_frame); - iter = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount); - Nerrs = data_bits_per_frame - parityCheckCount; - for(i=0; i<20; i++) - fprintf(stderr,"%d ", out_char[i]); - fprintf(stderr,"\n"); - fprintf(stderr, "iter: %d pcc: %d Nerrs: %d\n", iter, parityCheckCount, Nerrs); - if ((Nerrs < 10)) { + iter[0] = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount[0]); + Nerrs_coded[0] = data_bits_per_frame - parityCheckCount[0]; + //for(i=0; i<20; i++) + // fprintf(stderr,"%d ", out_char[i]); + //fprintf(stderr,"\n"); + //fprintf(stderr, " iter: %d pcc: %d Nerrs: %d\n", iter, parityCheckCount, Nerrs); + if ((Nerrs_coded[0] == 0) && (iter[0] <= 5)) { /* sucessful decode! */ strcpy(next_sync_state_interleaver, "synced"); ofdm->frame_count_interleaver = interleave_frames; @@ -298,8 +300,8 @@ int main(int argc, char *argv[]) symbols_to_llrs(llr, &codeword_symbols_de[j*coded_syms_per_frame], &codeword_amps_de[j*coded_syms_per_frame], EsNo, coded_syms_per_frame); - iter = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount); - fprintf(stderr,"j: %d iter: %d parityCheckCount: %d\n", j, iter, parityCheckCount); + iter[j] = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount[j]); + //fprintf(stderr,"j: %d iter: %d pcc: %d\n", j, iter[j], parityCheckCount[j]); if (testframes) { Nerrs = 0; for(i=0; i<data_bits_per_frame; i++) { @@ -369,11 +371,14 @@ int main(int argc, char *argv[]) } if (ofdm->verbose) { - int r = ofdm->frame_count_interleaver % interleave_frames; - fprintf(stderr, "f: %3d st: %-6s uw_errs: %2d %1d inter_st: %-6s inter_fr: %2d Nerrs_raw: %3d Nerrs_coded: %3d foff: %4.1f", - f, ofdm->last_sync_state, ofdm->uw_errors, ofdm->sync_counter, + int r=0; + if (testframes) { + r = (ofdm->frame_count_interleaver - 1 ) % interleave_frames; + } + fprintf(stderr, "%3d st: %-6s euw: %2d %1d f: %5.1f ist: %-6s %2d eraw: %3d ecdd: %3d iter: %3d pcc: %3d", + f, ofdm->last_sync_state, ofdm->uw_errors, ofdm->sync_counter, ofdm->foff_est_hz, ofdm->last_sync_state_interleaver, ofdm->frame_count_interleaver, - Nerrs_raw[r], Nerrs_coded[r], ofdm->foff_est_hz); + Nerrs_raw[r], Nerrs_coded[r], iter[r], parityCheckCount[r]); fprintf(stderr, "\n"); } -- 2.25.1