diff options
| author | drowe67 <[email protected]> | 2024-04-05 15:40:35 +1030 |
|---|---|---|
| committer | David Rowe <[email protected]> | 2024-04-05 15:40:35 +1030 |
| commit | 73482ea69de469986a23172509624a2e450bc273 (patch) | |
| tree | 014dd4d4389150d603ffebddedf3a687d841e888 | |
| parent | 1079f804b240df714cb5492d3cd1456502323653 (diff) | |
uncoded BER 0 with ofdm_mod/ofdm_demod, LDPC decode not working yet
| -rw-r--r-- | src/freedv_2020.c | 6 | ||||
| -rw-r--r-- | src/freedv_700.c | 7 | ||||
| -rw-r--r-- | src/interldpc.c | 40 | ||||
| -rw-r--r-- | src/interldpc.h | 3 | ||||
| -rw-r--r-- | src/ofdm.c | 29 | ||||
| -rw-r--r-- | src/ofdm_demod.c | 13 | ||||
| -rw-r--r-- | src/ofdm_internal.h | 22 | ||||
| -rw-r--r-- | src/ofdm_mod.c | 3 | ||||
| -rw-r--r-- | unittest/tofdm.c | 4 |
9 files changed, 66 insertions, 61 deletions
diff --git a/src/freedv_2020.c b/src/freedv_2020.c index 4a54b5b..9963819 100644 --- a/src/freedv_2020.c +++ b/src/freedv_2020.c @@ -248,7 +248,7 @@ int freedv_comprx_2020(struct freedv *f, COMP demod_in[]) { ofdm_demod(ofdm, rx_bits, demod_in); ofdm_extract_uw(ofdm, ofdm->rx_np, ofdm->rx_amp, rx_uw); - ofdm_disassemble_qpsk_modem_packet_with_text_amps( + ofdm_disassemble_psk_modem_packet_with_text_amps( ofdm, ofdm->rx_np, ofdm->rx_amp, payload_syms, payload_amps, txt_bits, &txt_sym_index); @@ -279,8 +279,8 @@ int freedv_comprx_2020(struct freedv *f, COMP demod_in[]) { uint8_t out_char[coded_bits_per_frame]; if (f->test_frames) { - Nerrs_raw = - count_uncoded_errors(ldpc, &f->ofdm->config, codeword_symbols_de, 0); + Nerrs_raw = count_uncoded_errors(ldpc, &f->ofdm->config, + codeword_symbols_de, payload_amps_de, 0); f->total_bit_errors += Nerrs_raw; f->total_bits += f->ofdm_bitsperframe; } diff --git a/src/freedv_700.c b/src/freedv_700.c index 8ab0cbb..257b80f 100644 --- a/src/freedv_700.c +++ b/src/freedv_700.c @@ -490,7 +490,7 @@ int freedv_comp_short_rx_ofdm(struct freedv *f, void *demod_in_8kHz, /* we have received enough modem frames to complete packet and run LDPC * decoder */ int txt_sym_index = 0; - ofdm_disassemble_qpsk_modem_packet_with_text_amps( + ofdm_disassemble_psk_modem_packet_with_text_amps( ofdm, rx_syms, rx_amps, payload_syms, payload_amps, txt_bits, &txt_sym_index); @@ -526,8 +526,9 @@ int freedv_comp_short_rx_ofdm(struct freedv *f, void *demod_in_8kHz, if (f->test_frames) { /* est uncoded BER from payload bits */ - Nerrs_raw = count_uncoded_errors( - ldpc, &f->ofdm->config, payload_syms_de, strlen(ofdm->data_mode)); + Nerrs_raw = + count_uncoded_errors(ldpc, &f->ofdm->config, payload_syms_de, + payload_amps_de, strlen(ofdm->data_mode)); f->total_bit_errors += Nerrs_raw; f->total_bits += Npayloadbitsperpacket; diff --git a/src/interldpc.c b/src/interldpc.c index 8cec647..cb6f964 100644 --- a/src/interldpc.c +++ b/src/interldpc.c @@ -134,17 +134,18 @@ void ldpc_encode_frame(struct LDPC *ldpc, int codeword[], for (j = 0; j < ldpc->NumberParityBits; i++, j++) codeword[i] = pbits[j]; } -void qpsk_modulate_frame(COMP tx_symbols[], int codeword[], int n) { +void psk_modulate_frame(int bps, COMP tx_symbols[], int codeword[], int n) { int s, i; - int dibit[2]; - complex float qpsk_symb; - - for (s = 0, i = 0; i < n; s += 2, i++) { - dibit[0] = codeword[s + 1] & 0x1; - dibit[1] = codeword[s] & 0x1; - qpsk_symb = qpsk_mod(dibit); - tx_symbols[i].real = crealf(qpsk_symb); - tx_symbols[i].imag = cimagf(qpsk_symb); + int bits[bps]; + complex float symb; + + assert((bps == 2) || (bps == 4)); + for (s = 0, i = 0; i < n; s += bps, i++) { + for (int b = 0; b < bps; b++) bits[b] = codeword[s + bps - 1 - b] & 0x1; + if (bps == 2) symb = qpsk_mod(bits); + if (bps == 4) symb = qam16_mod(bits); + tx_symbols[i].real = crealf(symb); + tx_symbols[i].imag = cimagf(symb); } } @@ -220,7 +221,8 @@ void ldpc_decode_frame(struct LDPC *ldpc, int *parityCheckCount, int *iter, of txt bits as this is done after we dissassemmble the frame */ int count_uncoded_errors(struct LDPC *ldpc, struct OFDM_CONFIG *config, - COMP codeword_symbols_de[], int crc16) { + COMP codeword_symbols_de[], float codeword_amps_de[], + int crc16) { int i, Nerrs; int coded_syms_per_frame = ldpc->coded_bits_per_frame / config->bps; @@ -248,12 +250,13 @@ int count_uncoded_errors(struct LDPC *ldpc, struct OFDM_CONFIG *config, ldpc_encode_frame(ldpc, test_codeword, tx_bits); for (i = 0; i < coded_syms_per_frame; i++) { - int bits[2]; + int bits[config->bps]; complex float s = codeword_symbols_de[i].real + I * codeword_symbols_de[i].imag; - qpsk_demod(s, bits); - rx_bits_raw[config->bps * i] = bits[1]; - rx_bits_raw[config->bps * i + 1] = bits[0]; + if (config->bps == 2) qpsk_demod(s, bits); + if (config->bps == 4) qam16_demod(s, bits, codeword_amps_de[i]); + for (int b = 0; b < config->bps; b++) + rx_bits_raw[config->bps * i + b] = bits[config->bps - 1 - b]; } Nerrs = 0; @@ -329,10 +332,11 @@ void ofdm_ldpc_interleave_tx(struct OFDM *ofdm, struct LDPC *ldpc, complex float tx_symbols[Nbitsperpacket / ofdm->bps]; ldpc_encode_frame(ldpc, codeword, tx_bits); - qpsk_modulate_frame(payload_symbols, codeword, Npayloadsymsperpacket); + psk_modulate_frame(ofdm->bps, payload_symbols, codeword, + Npayloadsymsperpacket); gp_interleave_comp(payload_symbols_inter, payload_symbols, Npayloadsymsperpacket); - ofdm_assemble_qpsk_modem_packet_symbols(ofdm, tx_symbols, - payload_symbols_inter, txt_bits); + ofdm_assemble_psk_modem_packet_symbols(ofdm, tx_symbols, + payload_symbols_inter, txt_bits); ofdm_txframe(ofdm, tx_sams, tx_symbols); } diff --git a/src/interldpc.h b/src/interldpc.h index 3b1d1ca..1c72558 100644 --- a/src/interldpc.h +++ b/src/interldpc.h @@ -49,7 +49,8 @@ void qpsk_modulate_frame(COMP tx_symbols[], int codeword[], int n); void ldpc_decode_frame(struct LDPC *ldpc, int *parityCheckCount, int *iter, uint8_t out_char[], float llr[]); int count_uncoded_errors(struct LDPC *ldpc, struct OFDM_CONFIG *config, - COMP codeword_symbols_de[], int crc16); + COMP codeword_symbols_de[], float codeword_amps_de[], + int crc16); int count_errors(uint8_t tx_bits[], uint8_t rx_bits[], int n); void count_errors_protection_mode(int protection_mode, int *pNerrs, int *pNcoded, uint8_t tx_bits[], @@ -2381,9 +2381,9 @@ void ofdm_get_demod_stats(struct OFDM *ofdm, struct MODEM_STATS *stats, /* * Assemble packet of bits from UW, payload bits, and txt bits */ -void ofdm_assemble_qpsk_modem_packet(struct OFDM *ofdm, uint8_t modem_frame[], - uint8_t payload_bits[], - uint8_t txt_bits[]) { +void ofdm_assemble_psk_modem_packet(struct OFDM *ofdm, uint8_t modem_frame[], + uint8_t payload_bits[], + uint8_t txt_bits[]) { int s, t; int p = 0; @@ -2410,10 +2410,10 @@ void ofdm_assemble_qpsk_modem_packet(struct OFDM *ofdm, uint8_t modem_frame[], /* * Assemble packet of symbols from UW, payload symbols, and txt bits */ -void ofdm_assemble_qpsk_modem_packet_symbols(struct OFDM *ofdm, - complex float modem_packet[], - COMP payload_syms[], - uint8_t txt_bits[]) { +void ofdm_assemble_psk_modem_packet_symbols(struct OFDM *ofdm, + complex float modem_packet[], + COMP payload_syms[], + uint8_t txt_bits[]) { complex float *payload = (complex float *)&payload_syms[0]; // complex has same memory layout int Nsymsperpacket = ofdm->bitsperpacket / ofdm->bps; @@ -2436,7 +2436,8 @@ void ofdm_assemble_qpsk_modem_packet_symbols(struct OFDM *ofdm, assert(u == Nuwsyms); assert(p == (Nsymsperpacket - Nuwsyms - Ntxtsyms)); - /* txt bit insertion only works for QPSK at this stage */ + /* txt bit insertion only works for QPSK at this stage, however QAM modes + * generally has no txt bits */ assert((Ntxtsyms == 0) || (ofdm->bps == 2)); for (t = 0; s < Nsymsperpacket; s++, t += 2) { dibit[1] = txt_bits[t] & 0x1; @@ -2451,11 +2452,11 @@ void ofdm_assemble_qpsk_modem_packet_symbols(struct OFDM *ofdm, * Disassemble a received packet of symbols into UW bits and payload data * symbols */ -void ofdm_disassemble_qpsk_modem_packet(struct OFDM *ofdm, - complex float rx_syms[], - float rx_amps[], COMP codeword_syms[], - float codeword_amps[], - short txt_bits[]) { +void ofdm_disassemble_psk_modem_packet(struct OFDM *ofdm, + complex float rx_syms[], float rx_amps[], + COMP codeword_syms[], + float codeword_amps[], + short txt_bits[]) { complex float *codeword = (complex float *)&codeword_syms[0]; // complex has same memory layout int Nsymsperpacket = ofdm->bitsperpacket / ofdm->bps; @@ -2495,7 +2496,7 @@ void ofdm_disassemble_qpsk_modem_packet(struct OFDM *ofdm, * Disassemble a received packet of symbols into UW bits and payload data * symbols */ -void ofdm_disassemble_qpsk_modem_packet_with_text_amps( +void ofdm_disassemble_psk_modem_packet_with_text_amps( struct OFDM *ofdm, complex float rx_syms[], float rx_amps[], COMP codeword_syms[], float codeword_amps[], short txt_bits[], int *textIndex) { diff --git a/src/ofdm_demod.c b/src/ofdm_demod.c index 0f3d802..f8dc7a5 100644 --- a/src/ofdm_demod.c +++ b/src/ofdm_demod.c @@ -473,8 +473,8 @@ int main(int argc, char *argv[]) { /* we have received enough frames to make a complete packet .... */ /* extract payload symbols from packet */ - ofdm_disassemble_qpsk_modem_packet(ofdm, rx_syms, rx_amps, payload_syms, - payload_amps, txt_bits); + ofdm_disassemble_psk_modem_packet(ofdm, rx_syms, rx_amps, payload_syms, + payload_amps, txt_bits); if (ldpc_en) { assert((ofdm_nuwbits + ofdm_ntxtbits + Npayloadbitsperpacket) <= @@ -492,8 +492,8 @@ int main(int argc, char *argv[]) { uint8_t out_char[Npayloadbitsperpacket]; if (testframes == true) { - Nerrs_raw = - count_uncoded_errors(&ldpc, ofdm_config, payload_syms_de, 0); + Nerrs_raw = count_uncoded_errors( + &ldpc, ofdm_config, payload_syms_de, payload_amps_de, 0); Terrs += Nerrs_raw; Tbits += Npayloadbitsperpacket; /* not counting errors in txt bits */ @@ -524,7 +524,7 @@ int main(int argc, char *argv[]) { assert(Npayloadsymsperpacket * ofdm_config->bps == Npayloadbitsperpacket); for (i = 0; i < Npayloadsymsperpacket; i++) { - int bits[2]; + int bits[ofdm->bps]; complex float s = payload_syms[i].real + I * payload_syms[i].imag; qpsk_demod(s, bits); rx_bits_char[ofdm_config->bps * i] = bits[1]; @@ -547,8 +547,7 @@ int main(int argc, char *argv[]) { memset(txt_bits, 0, ofdm_ntxtbits); uint8_t tx_bits[Nbitsperpacket]; ofdm_generate_payload_data_bits(payload_bits, Npayloadbitsperpacket); - ofdm_assemble_qpsk_modem_packet(ofdm, tx_bits, payload_bits, - txt_bits); + ofdm_assemble_psk_modem_packet(ofdm, tx_bits, payload_bits, txt_bits); /* count errors across UW, payload, txt bits */ int rx_bits[Nbitsperpacket]; diff --git a/src/ofdm_internal.h b/src/ofdm_internal.h index b57451a..af449d3 100644 --- a/src/ofdm_internal.h +++ b/src/ofdm_internal.h @@ -260,17 +260,17 @@ complex float qam16_mod(int *); void qpsk_demod(complex float, int *); void qam16_demod(complex float, int *, float); void ofdm_txframe(struct OFDM *, complex float *, complex float[]); -void ofdm_assemble_qpsk_modem_packet(struct OFDM *, uint8_t[], uint8_t[], - uint8_t[]); -void ofdm_assemble_qpsk_modem_packet_symbols(struct OFDM *, complex float[], - COMP[], uint8_t[]); -void ofdm_disassemble_qpsk_modem_packet(struct OFDM *, complex float rx_syms[], - float rx_amps[], COMP[], float[], - short[]); -void ofdm_disassemble_qpsk_modem_packet_with_text_amps(struct OFDM *, - complex float rx_syms[], - float rx_amps[], COMP[], - float[], short[], int *); +void ofdm_assemble_psk_modem_packet(struct OFDM *, uint8_t[], uint8_t[], + uint8_t[]); +void ofdm_assemble_psk_modem_packet_symbols(struct OFDM *, complex float[], + COMP[], uint8_t[]); +void ofdm_disassemble_psk_modem_packet(struct OFDM *, complex float rx_syms[], + float rx_amps[], COMP[], float[], + short[]); +void ofdm_disassemble_psk_modem_packet_with_text_amps(struct OFDM *, + complex float rx_syms[], + float rx_amps[], COMP[], + float[], short[], int *); void ofdm_extract_uw(struct OFDM *ofdm, complex float rx_syms[], float rx_amps[], uint8_t rx_uw[]); void ofdm_rand(uint16_t[], int); diff --git a/src/ofdm_mod.c b/src/ofdm_mod.c index d4c495e..23444f5 100644 --- a/src/ofdm_mod.c +++ b/src/ofdm_mod.c @@ -398,8 +398,7 @@ int main(int argc, char *argv[]) { /* assemble packet of bits then modulate */ uint8_t tx_bits_char[Nbitsperpacket]; - ofdm_assemble_qpsk_modem_packet(ofdm, tx_bits_char, data_bits, - txt_bits); + ofdm_assemble_psk_modem_packet(ofdm, tx_bits_char, data_bits, txt_bits); int tx_bits[Nbitsperpacket]; for (i = 0; i < Nbitsperpacket; i++) tx_bits[i] = tx_bits_char[i]; COMP tx_sams[Nsamperpacket]; diff --git a/unittest/tofdm.c b/unittest/tofdm.c index b4d60b7..0efcc60 100644 --- a/unittest/tofdm.c +++ b/unittest/tofdm.c @@ -324,8 +324,8 @@ int main(int argc, char *argv[]) { for (i = 0; i < ofdm_ntxtbits; i++) txt_bits[i] = 0; uint8_t tx_bits_char[ofdm_bitsperframe]; - ofdm_assemble_qpsk_modem_packet(ofdm, tx_bits_char, payload_bits, - txt_bits); + ofdm_assemble_psk_modem_packet(ofdm, tx_bits_char, payload_bits, + txt_bits); for (i = 0; i < ofdm_bitsperframe; i++) tx_bits[i] = tx_bits_char[i]; } |
