Skip to content

Commit

Permalink
Add additional logging and try different way to calculate amps.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Dec 7, 2024
1 parent baf1790 commit 0293c65
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/freedv_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void FreeDVInterface::start(int txMode, int fifoSizeMs, bool singleRxThread, boo

if (usingReliableText)
{
log_info("creating RADE text object");
radeTextPtr_ = rade_text_create();
assert(radeTextPtr_ != nullptr);

Expand Down Expand Up @@ -680,6 +681,7 @@ void FreeDVInterface::setReliableText(const char* callsign)
// Special case for RADE.
if (rade_ != nullptr && radeTextPtr_ != nullptr)
{
log_info("generating RADE text string");
float eooSyms[rade_n_eoo_bits(rade_)];
rade_text_generate_tx_string(radeTextPtr_, callsign, strlen(callsign), eooSyms);
rade_tx_set_eoo_bits(rade_, eooSyms);
Expand Down
34 changes: 27 additions & 7 deletions src/pipeline/rade_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef struct {

_Complex float inbound_pending_syms[LDPC_TOTAL_SIZE_BITS / 2];
float inbound_pending_amps[LDPC_TOTAL_SIZE_BITS / 2];
float incomingData[LDPC_TOTAL_SIZE_BITS];

struct LDPC ldpc;
} rade_text_impl_t;
Expand Down Expand Up @@ -141,12 +142,14 @@ static int rade_text_ldpc_decode(rade_text_impl_t* obj, char* dest) {
assert(obj != NULL);
assert(dest != NULL);

_Complex float deinterleavedSyms[LDPC_TOTAL_SIZE_BITS / 2];
float deinterleavedAmps[LDPC_TOTAL_SIZE_BITS / 2];
_Complex float deinterleavedSyms[LDPC_TOTAL_SIZE_BITS];
float deinterleavedAmps[LDPC_TOTAL_SIZE_BITS];
float llr[LDPC_TOTAL_SIZE_BITS];
unsigned char output[LDPC_TOTAL_SIZE_BITS];
int parityCheckCount = 0;

//sd_to_llr(llr, obj->incomingData, LDPC_TOTAL_SIZE_BITS);
#if 1
// Use soft decision for the LDPC decoder.
int Npayloadsymsperpacket = LDPC_TOTAL_SIZE_BITS / 2;

Expand All @@ -173,11 +176,16 @@ static int rade_text_ldpc_decode(rade_text_impl_t* obj, char* dest) {

float EsNo = 3.0; // note: constant from freedv_700.c
meanAmplitude /= Npayloadsymsperpacket;

//meanAmplitude = sqrt(meanAmplitude);
for (int index = 0; index < Npayloadsymsperpacket; index++)
{
deinterleavedAmps[index] = meanAmplitude;
}
log_info("mean amplitude: %f", meanAmplitude);

symbols_to_llrs(llr, (COMP*)deinterleavedSyms, deinterleavedAmps, EsNo,
meanAmplitude, Npayloadsymsperpacket);
#endif
run_ldpc_decoder(&obj->ldpc, output, llr, &parityCheckCount);

// Data is valid if BER < 0.2
Expand Down Expand Up @@ -211,11 +219,19 @@ void rade_text_rx(rade_text_t ptr, float* syms)
// Copy over symbols prior to decode.
for (int index = 0; index < LDPC_TOTAL_SIZE_BITS / 2; index++)
{
//obj->incomingData[index] = syms[index];
#if 1
/*if (index < 4)*/ log_info("RX symbol: %f, %f", syms[2 * index], syms[2 * index + 1]);
complex float symbol = CMPLXF(syms[2 * index], syms[2 * index + 1]);
*(complex float*)&obj->inbound_pending_syms[index] = symbol * cmplx(ROT45);

float* sym = (float*)&obj->inbound_pending_syms[index];
obj->inbound_pending_amps[index] = sqrt(pow(sym[0], 2) + pow(sym[1], 2));
*(complex float*)&obj->inbound_pending_syms[index] = symbol * CMPLXF(cosf(M_PI/4), sinf(M_PI/4));

//float* sym = (float*)&obj->inbound_pending_syms[index];
obj->inbound_pending_amps[index] = cabsf(obj->inbound_pending_syms[index]);
/*if (index < 4)*/ log_info("RX symbol rotated: %f, %f, amp: %f",
crealf(obj->inbound_pending_syms[index]),
cimagf(obj->inbound_pending_syms[index]),
obj->inbound_pending_amps[index]);
#endif
}

// We have all the bits we need, so we're ready to decode.
Expand Down Expand Up @@ -329,10 +345,14 @@ void rade_text_generate_tx_string(
LDPC_TOTAL_SIZE_BITS / 2);*/

// Generate floats based on the bits.
char debugString[256];
for (int index = 0; index < LDPC_TOTAL_SIZE_BITS; index++)
{
syms[index] = 2.0*impl->tx_text[index] - 1.0;
debugString[index] = impl->tx_text[index] ? '1' : '0';
}
debugString[LDPC_TOTAL_SIZE_BITS] = 0;
log_info("generated bits: %s", debugString);
}

void rade_text_set_rx_callback(rade_text_t ptr, on_text_rx_t text_rx_fn, void* state)
Expand Down

0 comments on commit 0293c65

Please sign in to comment.