mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Try not lost data on dsp (Less noise on small signals)
Use int64_t acc for values Use double on calculation Not cache freq on si5351_set_frequency_with_offset (to fast change in rare cases on cw mode, and process wrong DSP block) as i write before need change DSP delay tactic
This commit is contained in:
parent
77b5d0bcc8
commit
a2d90a5e91
79
dsp.c
79
dsp.c
|
|
@ -41,48 +41,57 @@ const int16_t sincos_tbl[48][2] = {
|
||||||
{-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 }
|
{-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t acc_samp_s;
|
int64_t acc_samp_s;
|
||||||
int32_t acc_samp_c;
|
int64_t acc_samp_c;
|
||||||
int32_t acc_ref_s;
|
int64_t acc_ref_s;
|
||||||
int32_t acc_ref_c;
|
int64_t acc_ref_c;
|
||||||
|
|
||||||
void
|
void
|
||||||
dsp_process(int16_t *capture, size_t length)
|
dsp_process(int16_t *capture, size_t length)
|
||||||
{
|
{
|
||||||
uint32_t *p = (uint32_t*)capture;
|
|
||||||
uint32_t len = length / 2;
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
int32_t samp_s = 0;
|
#if 1
|
||||||
int32_t samp_c = 0;
|
acc_samp_s = 0;
|
||||||
int32_t ref_s = 0;
|
acc_samp_c = 0;
|
||||||
int32_t ref_c = 0;
|
acc_ref_s = 0;
|
||||||
|
acc_ref_c = 0;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < length; i+=2) {
|
||||||
uint32_t sr = *p++;
|
int32_t ref = capture[i+0];
|
||||||
int16_t ref = sr & 0xffff;
|
int32_t smp = capture[i+1];
|
||||||
int16_t smp = (sr>>16) & 0xffff;
|
|
||||||
#ifdef ENABLED_DUMP
|
#ifdef ENABLED_DUMP
|
||||||
ref_buf[i] = ref;
|
ref_buf[i] = ref;
|
||||||
samp_buf[i] = smp;
|
samp_buf[i] = smp;
|
||||||
#endif
|
#endif
|
||||||
int32_t s = sincos_tbl[i][0];
|
int32_t s = ((int16_t *)sincos_tbl)[i+0];
|
||||||
int32_t c = sincos_tbl[i][1];
|
int32_t c = ((int16_t *)sincos_tbl)[i+1];
|
||||||
samp_s += smp * s / 16;
|
acc_samp_s += (smp * s);
|
||||||
samp_c += smp * c / 16;
|
acc_samp_c += (smp * c);
|
||||||
ref_s += ref * s / 16;
|
acc_ref_s += (ref * s);
|
||||||
ref_c += ref * c / 16;
|
acc_ref_c += (ref * c);
|
||||||
#if 0
|
}
|
||||||
uint32_t sc = *(uint32_t)&sincos_tbl[i];
|
#else
|
||||||
samp_s = __SMLABB(sr, sc, samp_s);
|
uint32_t len = length / 2;
|
||||||
samp_c = __SMLABT(sr, sc, samp_c);
|
int64_t samp_s = 0;
|
||||||
ref_s = __SMLATB(sr, sc, ref_s);
|
int64_t samp_c = 0;
|
||||||
ref_c = __SMLATT(sr, sc, ref_c);
|
int64_t ref_s = 0;
|
||||||
#endif
|
int64_t ref_c = 0;
|
||||||
|
// HI LO
|
||||||
|
int32_t *cos_sin = (int32_t *)sincos_tbl;
|
||||||
|
int32_t *ref_smp = (int32_t *)capture;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
//
|
||||||
|
samp_s = __SMLALBB(*ref_smp, *cos_sin, samp_s); // samp_s+= smp * sin
|
||||||
|
samp_c = __SMLALBT(*ref_smp, *cos_sin, samp_c); // samp_c+= smp * cos
|
||||||
|
ref_s = __SMLALTB(*ref_smp, *cos_sin, ref_s); // ref_s += ref * sin
|
||||||
|
ref_c = __SMLALTT(*ref_smp, *cos_sin, ref_c); // ref_s += ref * cos
|
||||||
|
ref_smp++;
|
||||||
|
cos_sin++;
|
||||||
}
|
}
|
||||||
acc_samp_s = samp_s;
|
acc_samp_s = samp_s;
|
||||||
acc_samp_c = samp_c;
|
acc_samp_c = samp_c;
|
||||||
acc_ref_s = ref_s;
|
acc_ref_s = ref_s;
|
||||||
acc_ref_c = ref_c;
|
acc_ref_c = ref_c;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -90,12 +99,12 @@ calculate_gamma(float gamma[2])
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
// calculate reflection coeff. by samp divide by ref
|
// calculate reflection coeff. by samp divide by ref
|
||||||
float rs = acc_ref_s;
|
double rs = acc_ref_s;
|
||||||
float rc = acc_ref_c;
|
double rc = acc_ref_c;
|
||||||
float rr = rs * rs + rc * rc;
|
double rr = rs * rs + rc * rc;
|
||||||
//rr = sqrtf(rr) * 1e8;
|
//rr = sqrtf(rr) * 1e8;
|
||||||
float ss = acc_samp_s;
|
double ss = acc_samp_s;
|
||||||
float sc = acc_samp_c;
|
double sc = acc_samp_c;
|
||||||
gamma[0] = (sc * rc + ss * rs) / rr;
|
gamma[0] = (sc * rc + ss * rs) / rr;
|
||||||
gamma[1] = (ss * rc - sc * rs) / rr;
|
gamma[1] = (ss * rc - sc * rs) / rr;
|
||||||
#elif 0
|
#elif 0
|
||||||
|
|
|
||||||
6
si5351.c
6
si5351.c
|
|
@ -354,13 +354,13 @@ int
|
||||||
si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength){
|
si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength){
|
||||||
uint8_t band;
|
uint8_t band;
|
||||||
int delay = DELAY_NORMAL;
|
int delay = DELAY_NORMAL;
|
||||||
if (freq == current_freq)
|
// if (freq == current_freq)
|
||||||
return delay;
|
// return delay;
|
||||||
uint32_t ofreq = freq + offset;
|
uint32_t ofreq = freq + offset;
|
||||||
uint32_t mul = 1, omul = 1;
|
uint32_t mul = 1, omul = 1;
|
||||||
uint32_t rdiv = SI5351_R_DIV_1;
|
uint32_t rdiv = SI5351_R_DIV_1;
|
||||||
uint32_t fdiv;
|
uint32_t fdiv;
|
||||||
current_freq = freq;
|
// current_freq = freq;
|
||||||
if (freq >= config.harmonic_freq_threshold * 7U) {
|
if (freq >= config.harmonic_freq_threshold * 7U) {
|
||||||
mul = 9;
|
mul = 9;
|
||||||
omul = 11;
|
omul = 11;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue