From 9377783dbb7eb2fcfbe194f1f9b33462c8c0ba3b Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 12 Apr 2018 02:42:24 +0000 Subject: [PATCH] codec2-dev building again but may have broken some ofdm or dr_rs232 code, still testing git-svn-id: https://svn.code.sf.net/p/freetel/code@3466 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/drs232_ldpc.c | 4 +- codec2-dev/src/fsk_mod_ext_vco.c | 4 +- codec2-dev/src/ldpc_dec.c | 59 +++++++++++++---- codec2-dev/src/mpdecode_core.c | 107 ++++++++++++++++++++++++++++++- codec2-dev/src/mpdecode_core.h | 7 +- 5 files changed, 163 insertions(+), 18 deletions(-) diff --git a/codec2-dev/src/drs232_ldpc.c b/codec2-dev/src/drs232_ldpc.c index 40bb7061..31a4deca 100755 --- a/codec2-dev/src/drs232_ldpc.c +++ b/codec2-dev/src/drs232_ldpc.c @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) { uint8_t packet[BYTES_PER_PACKET+CRC_BYTES]; uint8_t abyte; uint16_t tx_checksum, rx_checksum, packet_errors, packets; - int CodeLength, iter; + int CodeLength, iter, parityCheckCount; struct LDPC ldpc; assert(sizeof(uw) == UW_BITS); @@ -227,7 +227,7 @@ int main(int argc, char *argv[]) { /* now LDPC decode */ sd_to_llr(llr, symbol_buf_no_rs232, CodeLength); - iter = run_ldpc_decoder(&ldpc, unpacked_packet, llr); + iter = run_ldpc_decoder(&ldpc, unpacked_packet, llr, &parityCheckCount); /* pack into bytes */ diff --git a/codec2-dev/src/fsk_mod_ext_vco.c b/codec2-dev/src/fsk_mod_ext_vco.c index 137bdab7..91151f25 100644 --- a/codec2-dev/src/fsk_mod_ext_vco.c +++ b/codec2-dev/src/fsk_mod_ext_vco.c @@ -86,8 +86,10 @@ int main(int argc,char *argv[]){ /* 2 FSK -d/2, +d/2 */ /* 4 FSK -3*d/2, -d/2, +d/2, 3*d/2 */ + /* note: drive is inverted, a higher tone drives VCO voltage lower */ + float symf = sym; - float level = d*(symf - ((float)m-1)*0.5); + float level = d*(((float)m-1)*0.5 - symf); assert(level <= 32767.0); assert(level >= -32768.0); short level_short = (short)level; diff --git a/codec2-dev/src/ldpc_dec.c b/codec2-dev/src/ldpc_dec.c index edf14bb3..479771a8 100644 --- a/codec2-dev/src/ldpc_dec.c +++ b/codec2-dev/src/ldpc_dec.c @@ -68,7 +68,7 @@ void extract_output(char out_char[], int DecodedBits[], int ParityCheckCount[], int main(int argc, char *argv[]) { int CodeLength, NumberParityBits; - int i, r, num_ok, num_runs, codename; + int i, r, num_ok, num_runs, codename, parityCheckCount, mute, state, next_state, frame; char out_char[CODELENGTH], *adetected_data; struct LDPC ldpc; double *ainput; @@ -84,13 +84,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "usage: %s InOneSymbolPerDouble OutOneBitPerByte [--sd] [--half] [--code CodeName]\n\n", argv[0]); fprintf(stderr, " InOneSymbolPerDouble Input file of double LLRs, use - for the \n"); fprintf(stderr, " file names to use stdin/stdout\n"); - fprintf(stderr, " --code Treat input file samples as Soft Decision\n"); - fprintf(stderr, " demod outputs rather than LLRs\n"); + fprintf(stderr, " --code Use LDPC code CodeName\n"); fprintf(stderr, " --sd Treat input file samples as Soft Decision\n"); fprintf(stderr, " demod outputs rather than LLRs\n"); fprintf(stderr, " --half Load framesize/2 input samples for each decode\n"); fprintf(stderr, " attempt, only output decoded bits if decoder\n"); fprintf(stderr, " converges. Form of frame sync.\n"); + fprintf(stderr, " --mute Only output frames with < 10%% parity check fails\n"); fprintf(stderr, "\n"); exit(0); } @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) for(r=0; r 2.625 ) return( 0 ); @@ -67,6 +66,31 @@ static float LambdaAPPstar( float mag1, return( fabs( mag1 + correction( mag1 + mag2 ) - correction( mag2 - mag1 ) ) ); } +/* Values for linear approximation (DecoderType=5) */ + +#define AJIAN -0.24904163195436 +#define TJIAN 2.50681740420944 + +/* The linear-log-MAP algorithm */ + +static float max_star0( + float delta1, + float delta2 ) +{ + register float diff; + + diff = delta2 - delta1; + + if ( diff > TJIAN ) + return( delta2 ); + else if ( diff < -TJIAN ) + return( delta1 ); + else if ( diff > 0 ) + return( delta2 + AJIAN*(diff-TJIAN) ); + else + return( delta1 - AJIAN*(diff+TJIAN) ); +} + void init_c_v_nodes(struct c_node *c_nodes, int shift, int NumberParityBits, @@ -562,7 +586,7 @@ void SumProduct( int BitErrors[], /* Convenience function to call LDPC decoder from C programs */ -int run_ldpc_decoder(struct LDPC *ldpc, char out_char[], double input[]) { +int run_ldpc_decoder(struct LDPC *ldpc, char out_char[], double input[], int *parityCheckCount) { int max_iter, dec_type; float q_scale_factor, r_scale_factor; int max_row_weight, max_col_weight; @@ -635,6 +659,8 @@ int run_ldpc_decoder(struct LDPC *ldpc, char out_char[], double input[]) { int iter = extract_output(out_char, DecodedBits, ParityCheckCount, max_iter, CodeLength, NumberParityBits); + *parityCheckCount = ParityCheckCount[iter-1]; + /* Clean up memory */ free(ParityCheckCount); @@ -702,6 +728,81 @@ void sd_to_llr(double llr[], double sd[], int n) { } +/* + output[] is symbol likelihood + + Note we assume fading[] is real, it is also possible to compute + with complex fading. +*/ + +void Demod2D(float symbol_likelihood[], /* output, M*number_symbols */ + COMP r[], /* received QPSK symbols, number_symbols */ + COMP S_matrix[], /* constellation of size M */ + float EsNo, + float fading[], /* real fading values, number_symbols */ + int number_symbols) +{ + int M=4; + int i,j; + float tempsr, tempsi, Er, Ei; + + /* determine output */ + + for (i=0;i> 1; + } + mask = 1 << bps - 1; + + for (k=0;k> 1; + } + } + for (k=0;k