Replace BPF with LPF after I/Q conversion
This commit is contained in:
parent
09b4c2c169
commit
4e6a29abbc
72
src/main.c
72
src/main.c
|
@ -382,10 +382,36 @@ static void rf_rx_stop(void)
|
|||
dma_t_samp = -1;
|
||||
}
|
||||
|
||||
inline static int next_sample(const uint32_t *buf, int *h)
|
||||
{
|
||||
int x1 = 2 * (buf[0] - buf[1]);
|
||||
int x2 = 0;
|
||||
int x3 = -2 * (buf[4] - buf[5]);
|
||||
int x4 = 0;
|
||||
|
||||
int sample = 18 * h[9] + 14 * h[8] - 32 * h[7] - 33 * h[6] + 106 * h[5] + 362 * h[4] +
|
||||
565 * h[3] + 565 * h[2] + 362 * h[1] + 106 * h[0] - 33 * x1 - 32 * x2 +
|
||||
14 * x3 + 18 * x4;
|
||||
|
||||
h[9] = h[5];
|
||||
h[8] = h[4];
|
||||
h[7] = h[3];
|
||||
h[6] = h[2];
|
||||
h[5] = h[1];
|
||||
h[4] = h[0];
|
||||
h[3] = x1;
|
||||
h[2] = x2;
|
||||
h[1] = x3;
|
||||
h[0] = x4;
|
||||
|
||||
return sample >> 10;
|
||||
}
|
||||
|
||||
static void rf_rx(void)
|
||||
{
|
||||
const uint32_t base = (uint32_t)rx_cos;
|
||||
int prev1 = 0, prev2 = 0, prev3 = 0, prev4 = 0;
|
||||
int prevI[10] = { 0 };
|
||||
int prevQ[10] = { 0 };
|
||||
int pos = 0;
|
||||
|
||||
while (true) {
|
||||
|
@ -416,48 +442,16 @@ static void rf_rx(void)
|
|||
/*
|
||||
* Since every 2 samples add to either +1 or -1,
|
||||
* the maximum amplitude in one direction is 1/2.
|
||||
*/
|
||||
int64_t max_amplitude = CLK_SYS_HZ / 2;
|
||||
|
||||
/*
|
||||
*
|
||||
* We are allowing the counters to only go as high
|
||||
* as sampling rate, but the I/Q conversion splits
|
||||
* samples between two channels.
|
||||
* as sampling rate.
|
||||
*/
|
||||
max_amplitude /= sample_rate * 2;
|
||||
int64_t max_amplitude = CLK_SYS_HZ / 2 / sample_rate;
|
||||
|
||||
for (int i = 0; i < IQ_SAMPLES; i++) {
|
||||
int sI = 0, sQ = 0;
|
||||
int pos, neg;
|
||||
|
||||
#define next_sample ((-(pos - neg) + prev2 * 2 - prev4))
|
||||
|
||||
// +I
|
||||
pos = *cos_ptr++;
|
||||
neg = *cos_ptr++;
|
||||
sI += next_sample;
|
||||
prev4 = prev3, prev3 = prev2, prev2 = prev1, prev1 = pos - neg;
|
||||
|
||||
// +Q
|
||||
pos = *cos_ptr++;
|
||||
neg = *cos_ptr++;
|
||||
sQ += next_sample;
|
||||
prev4 = prev3, prev3 = prev2, prev2 = prev1, prev1 = pos - neg;
|
||||
|
||||
// -I
|
||||
pos = *cos_ptr++;
|
||||
neg = *cos_ptr++;
|
||||
sI -= next_sample;
|
||||
prev4 = prev3, prev3 = prev2, prev2 = prev1, prev1 = pos - neg;
|
||||
|
||||
// -Q
|
||||
pos = *cos_ptr++;
|
||||
neg = *cos_ptr++;
|
||||
sQ -= next_sample;
|
||||
prev4 = prev3, prev3 = prev2, prev2 = prev1, prev1 = pos - neg;
|
||||
|
||||
int64_t I = sI / 4;
|
||||
int64_t Q = sQ / 4;
|
||||
int64_t I = next_sample(cos_ptr + 0, prevI);
|
||||
int64_t Q = next_sample(cos_ptr + 2, prevQ);
|
||||
cos_ptr += 8;
|
||||
|
||||
I *= gain;
|
||||
I -= (max_amplitude * 181) / 256;
|
||||
|
|
Loading…
Reference in a new issue