aboutsummaryrefslogtreecommitdiffstats
path: root/src/libsquelch
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-12-05 10:55:13 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-12-09 20:46:16 +0100
commitf2eb6b3e705e4e516e7a7a3947b05a7c72ab6c8a (patch)
tree2a062c4364d35411af4b2607604797c9dbf2b541 /src/libsquelch
parent9f901384deda96a7dd021923841885ec1e4f2d67 (diff)
Squelch improvement
Continuously calculate noise floor and lower threshold level if less noise was received. High noise or ongoing transmission during start of program will not cause a threshold that is too far above the actual noise floor.
Diffstat (limited to 'src/libsquelch')
-rw-r--r--src/libsquelch/squelch.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/libsquelch/squelch.c b/src/libsquelch/squelch.c
index 4edb84e..cd6afa3 100644
--- a/src/libsquelch/squelch.c
+++ b/src/libsquelch/squelch.c
@@ -44,9 +44,9 @@
*/
/* NOTE: SQUELCH must be calibrated !AFTER! DC bias, to get the actual noise floor */
-#define SQUELCH_INIT_TIME 1.1 /* wait some time before performing squelch */
-#define SQUELCH_AUTO_TIME 1.0 /* duration of squelch quelch calibration */
-#define SQUELCH_AUTO_OFFSET 6.0 /* auto calibration: offset above noise floor */
+#define SQUELCH_INIT_TIME 0.1 /* wait some time before performing squelch */
+#define SQUELCH_AUTO_TIME 0.5 /* duration of squelch quelch calibration */
+#define SQUELCH_AUTO_OFFSET 10.0 /* auto calibration: offset above noise floor */
void squelch_init(squelch_t *squelch, int chan, double threshold_db, double mute_time, double loss_time)
{
@@ -89,12 +89,19 @@ enum squelch_result squelch(squelch_t *squelch, double rf_level_db, double durat
squelch->auto_count += duration;
squelch->auto_level_sum += rf_level_db;
squelch->auto_level_count++;
- if (squelch->auto_count < SQUELCH_AUTO_TIME)
- return SQUELCH_MUTE;
- squelch->threshold_db = squelch->auto_level_sum / (double) squelch->auto_level_count;
- PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal measurement: %.1f dB noise floor, using threshold of %.1f dB\n", squelch->threshold_db, squelch->threshold_db + SQUELCH_AUTO_OFFSET);
- squelch->threshold_db += SQUELCH_AUTO_OFFSET;
- squelch->auto_state = 0;
+ if (squelch->auto_count >= SQUELCH_AUTO_TIME) {
+ double noise_db, threshold_db;
+ noise_db = squelch->auto_level_sum / (double) squelch->auto_level_count;
+ threshold_db = noise_db + SQUELCH_AUTO_OFFSET;
+ /* must be 0.1 dB smaller, so we prevent repeated debugging message with similar value */
+ if (threshold_db < squelch->threshold_db - 0.1) {
+ squelch->threshold_db = threshold_db;
+ PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal measurement: %.1f dB noise floor, using squelch threshold of %.1f dB\n", noise_db, threshold_db);
+ }
+ squelch->auto_count = 0.0;
+ squelch->auto_level_count = 0;
+ squelch->auto_level_sum = 0.0;
+ }
}
/* enough RF level, so we unmute when mute_count reched 0 */