Reduce jitter and use HPF to improve SNR

This commit is contained in:
Jan Hamal Dvořák 2024-07-16 18:56:30 +02:00
parent 38b7ec34f6
commit 3d38c5796b

View file

@ -45,10 +45,10 @@ static uint32_t lo_cos[LO_WORDS] __attribute__((__aligned__(1 << LO_BITS_DEPTH))
#define DECIMATE 4
#define RX_STRIDE (2 * IQ_SAMPLES * DECIMATE)
#define RX_BITS_DEPTH 13
#define RX_BITS_DEPTH 12
#define RX_WORDS (1 << (RX_BITS_DEPTH - 2))
static_assert(RX_STRIDE * 4 < RX_WORDS, "RX_STRIDE * 4 < RX_WORDS");
static_assert(RX_STRIDE * 4 <= RX_WORDS, "RX_STRIDE * 4 <= RX_WORDS");
static uint32_t rx_cos[RX_WORDS] __attribute__((__aligned__(1 << RX_BITS_DEPTH)));
@ -142,7 +142,7 @@ static void init_fb()
const uint16_t insn[] = {
pio_encode_mov_not(pio_pins, pio_pins) | pio_encode_sideset(1, 1) |
pio_encode_delay(0),
pio_encode_nop() | pio_encode_sideset(1, 0),
pio_encode_nop() | pio_encode_sideset(1, 0) | pio_encode_delay(0),
};
pio_program_t prog = {
@ -219,9 +219,7 @@ static void init_ad()
*/
pio_encode_in(pio_y, 32),
pio_encode_in(pio_x, 32),
pio_encode_set(pio_x, 0),
pio_encode_set(pio_y, 0),
pio_encode_jmp(1),
pio_encode_jmp_x_dec(2),
};
pio_program_t prog = {
@ -421,6 +419,7 @@ static void rf_rx_stop(void)
static void rf_rx(void)
{
const uint32_t base = (uint32_t)rx_cos;
uint32_t prevP = 0, prevN = 0, sample = 0, this = 0, prev = 0;
int pos = 0;
while (true) {
@ -458,25 +457,67 @@ static void rf_rx(void)
* We are allowing the counters to only go as high
* as sampling rate, but the I/Q conversion splits
* samples between two channels.
*
* On the other hand, we high-pass the signal before
* I/Q conversion and samples potentially add up
* constructively.
*/
max_amplitude /= sample_rate * 2;
max_amplitude /= sample_rate * 2 / 2;
for (int i = 0; i < IQ_SAMPLES; i++) {
int sI = 0, sQ = 0;
/* Convert to I/Q signal. */
// +I
sample = *cos_ptr++;
this = sample - prevP;
prevP = sample;
sI += this - prev;
prev = this;
sI += *cos_ptr++;
sI -= *cos_ptr++;
sample = *cos_ptr++;
this = sample - prevN;
prevN = sample;
sI -= this - prev;
prev = this;
sQ += *cos_ptr++;
sQ -= *cos_ptr++;
// +Q
sample = *cos_ptr++;
this = sample - prevP;
prevP = sample;
sQ += this - prev;
prev = this;
sI -= *cos_ptr++;
sI += *cos_ptr++;
sample = *cos_ptr++;
this = sample - prevN;
prevN = sample;
sQ -= this - prev;
prev = this;
sQ -= *cos_ptr++;
sQ += *cos_ptr++;
// -I
sample = *cos_ptr++;
this = sample - prevP;
prevP = sample;
sI -= this - prev;
prev = this;
sample = *cos_ptr++;
this = sample - prevN;
prevN = sample;
sI += this - prev;
prev = this;
// -Q
sample = *cos_ptr++;
this = sample - prevP;
prevP = sample;
sQ -= this - prev;
prev = this;
sample = *cos_ptr++;
this = sample - prevN;
prevN = sample;
sQ += this - prev;
prev = this;
int64_t I = sI;
int64_t Q = sQ;