fix: remove glitch on interpolation

This commit is contained in:
TT 2019-10-05 21:11:19 +09:00
parent 94659a22ba
commit 3a6de231c6
2 changed files with 10 additions and 3 deletions

9
main.c
View file

@ -43,8 +43,8 @@ bool sweep(bool break_on_operation);
static MUTEX_DECL(mutex);
#define DRIVE_STRENGTH_AUTO (-1)
//#define FREQ_HARMONICS 300000000
#define FREQ_HARMONICS (config.harmonic_freq_threshold)
#define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS)
int32_t frequency_offset = 5000;
int32_t frequency = 10000000;
@ -1292,6 +1292,13 @@ cal_interpolate(int s)
// found f between freqs at j and j+1
float k1 = (float)(f - src->_frequencies[j])
/ (src->_frequencies[j+1] - src->_frequencies[j]);
// avoid glitch between freqs in different harmonics mode
if (IS_HARMONIC_MODE(src->_frequencies[j]) != IS_HARMONIC_MODE(src->_frequencies[j+1])) {
// assume f[j] < f[j+1]
k1 = IS_HARMONIC_MODE(f) ? 1.0 : 0.0;
}
float k0 = 1.0 - k1;
for (eterm = 0; eterm < 5; eterm++) {
cal_data[eterm][i][0] = src->_cal_data[eterm][j][0] * k0 + src->_cal_data[eterm][j+1][0] * k1;

View file

@ -310,10 +310,10 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
int delay = 3;
uint32_t ofreq = freq + offset;
uint32_t rdiv = SI5351_R_DIV_1;
if (freq > config.harmonic_freq_threshold * 3) {
if (freq >= config.harmonic_freq_threshold * 3) {
freq /= 5;
ofreq /= 7;
} else if (freq > config.harmonic_freq_threshold) {
} else if (freq >= config.harmonic_freq_threshold) {
freq /= 3;
ofreq /= 5;
}