Refactor sample processing
This commit is contained in:
parent
178ba7bee0
commit
f294b09c98
68
src/main.c
68
src/main.c
|
@ -395,33 +395,44 @@ static void rf_rx_stop(void)
|
||||||
dma_t_samp = -1;
|
dma_t_samp = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static int next_sample(const uint32_t *buf, int *h)
|
struct IQ {
|
||||||
|
int I, Q;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline static struct IQ next_sample(const uint32_t *buf)
|
||||||
{
|
{
|
||||||
int x3 = 2 * (buf[0] - buf[1]);
|
static int h[11];
|
||||||
int x2 = 0;
|
|
||||||
int x1 = 2 * (buf[5] - buf[4]);
|
int x3 = buf[0] - buf[1];
|
||||||
int x0 = 0;
|
int x2 = buf[2] - buf[3];
|
||||||
|
int x1 = buf[5] - buf[4];
|
||||||
|
int x0 = buf[7] - buf[6];
|
||||||
|
|
||||||
const int c[] = { 4, 2, -8, -9, 19, 55 };
|
const int c[] = { 4, 2, -8, -9, 19, 55 };
|
||||||
|
|
||||||
int sample = 0;
|
int I = 0, Q = 0;
|
||||||
sample += (c[0]) * h[10];
|
|
||||||
sample += (c[0] + c[1]) * h[9];
|
Q += (c[0]) * h[10];
|
||||||
sample += (c[0] + c[1] + c[2]) * h[8];
|
I += (c[0] + c[1]) * h[9];
|
||||||
sample += (c[0] + c[1] + c[2] + c[3]) * h[7];
|
Q += (c[0] + c[1] + c[2]) * h[8];
|
||||||
sample += (c[1] + c[2] + c[3] + c[4]) * h[6];
|
I += (c[0] + c[1] + c[2] + c[3]) * h[7];
|
||||||
sample += (c[2] + c[3] + c[4] + c[5]) * h[5];
|
Q += (c[1] + c[2] + c[3] + c[4]) * h[6];
|
||||||
sample += (c[3] + c[4] + c[5] + c[5]) * h[4];
|
I += (c[2] + c[3] + c[4] + c[5]) * h[5];
|
||||||
sample += (c[4] + c[5] + c[5] + c[4]) * h[3];
|
Q += (c[3] + c[4] + c[5] + c[5]) * h[4];
|
||||||
sample += (c[5] + c[5] + c[4] + c[3]) * h[2];
|
I += (c[4] + c[5] + c[5] + c[4]) * h[3];
|
||||||
sample += (c[5] + c[4] + c[3] + c[2]) * h[1];
|
Q += (c[5] + c[5] + c[4] + c[3]) * h[2];
|
||||||
sample += (c[4] + c[3] + c[2] + c[1]) * h[0];
|
I += (c[5] + c[4] + c[3] + c[2]) * h[1];
|
||||||
sample += (c[3] + c[2] + c[1] + c[0]) * x3;
|
Q += (c[4] + c[3] + c[2] + c[1]) * h[0];
|
||||||
sample += (c[2] + c[1] + c[0]) * x2;
|
I += (c[3] + c[2] + c[1] + c[0]) * x3;
|
||||||
sample += (c[1] + c[0]) * x1;
|
Q += (c[2] + c[1] + c[0]) * x2;
|
||||||
sample += (c[0]) * x0;
|
I += (c[1] + c[0]) * x1;
|
||||||
sample *= gain;
|
Q += (c[0]) * x0;
|
||||||
sample /= 256;
|
|
||||||
|
I *= gain;
|
||||||
|
I /= 128;
|
||||||
|
|
||||||
|
Q *= gain;
|
||||||
|
Q /= 128;
|
||||||
|
|
||||||
h[10] = h[6];
|
h[10] = h[6];
|
||||||
h[9] = h[5];
|
h[9] = h[5];
|
||||||
|
@ -435,14 +446,12 @@ inline static int next_sample(const uint32_t *buf, int *h)
|
||||||
h[1] = x1;
|
h[1] = x1;
|
||||||
h[0] = x0;
|
h[0] = x0;
|
||||||
|
|
||||||
return sample;
|
return (struct IQ){ I, Q };
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rf_rx(void)
|
static void rf_rx(void)
|
||||||
{
|
{
|
||||||
const uint32_t base = (uint32_t)rx_cos;
|
const uint32_t base = (uint32_t)rx_cos;
|
||||||
int prevI[11] = { 0 };
|
|
||||||
int prevQ[11] = { 0 };
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -480,9 +489,10 @@ static void rf_rx(void)
|
||||||
int64_t max_amplitude = CLK_SYS_HZ / 2 / sample_rate;
|
int64_t max_amplitude = CLK_SYS_HZ / 2 / sample_rate;
|
||||||
|
|
||||||
for (int i = 0; i < IQ_SAMPLES; i++) {
|
for (int i = 0; i < IQ_SAMPLES; i++) {
|
||||||
int64_t I = next_sample(cos_ptr + 0, prevI);
|
struct IQ IQ = next_sample(cos_ptr);
|
||||||
int64_t Q = next_sample(cos_ptr + 2, prevQ);
|
int64_t I = IQ.I;
|
||||||
cos_ptr += 8;
|
int64_t Q = IQ.Q;
|
||||||
|
cos_ptr += 2 * DECIMATE;
|
||||||
|
|
||||||
I -= (max_amplitude * 181) / 256;
|
I -= (max_amplitude * 181) / 256;
|
||||||
I /= max_amplitude;
|
I /= max_amplitude;
|
||||||
|
|
Loading…
Reference in a new issue