agc: adding squelch autotests (derived from example)
@@ -168,5 +168,60 @@ void autotest_agc_crcf_rssi_noise()
agc_crcf_destroy(q);
}
+//
+// Test squelch functionality
+//
+void autotest_agc_crcf_squelch()
+{
+ // create agc object, set loop bandwidth, and initialize parameters
+ agc_crcf q = agc_crcf_create();
+ agc_crcf_set_bandwidth(q, 0.25);
+ agc_crcf_set_signal_level(q,1e-3f); // initial guess at starting signal level
+
+ // initialize squelch functionality
+ agc_crcf_squelch_enable(q); // enable squelch
+ agc_crcf_squelch_set_threshold(q, -50); // threshold for detection [dB]
+ agc_crcf_squelch_set_timeout (q, 100); // timeout for hysteresis
+
+ // run agc
+ unsigned int num_samples = 2000; // total number of samples to run
+ unsigned int i;
+ for (i=0; i<num_samples; i++) {
+ // generate signal, applying tapering window appropriately
+ float gamma = 0.0f;
+ if (i < 500) gamma = 1e-3f;
+ else if (i < 550) gamma = 1e-3f + (1e-2f - 1e-3f)*(0.5f - 0.5f*cosf(M_PI*(float)(i- 500)/50.0f));
+ else if (i < 1450) gamma = 1e-2f;
+ else if (i < 1500) gamma = 1e-3f + (1e-2f - 1e-3f)*(0.5f + 0.5f*cosf(M_PI*(float)(i-1450)/50.0f));
+ else gamma = 1e-3f;
+ float complex x = gamma * cexpf(_Complex_I*2*M_PI*0.0193f*i);
+
+ // apply gain
+ float complex y;
+ agc_crcf_execute(q, x, &y);
+
+ // retrieve signal level [dB]
+ //rssi = agc_crcf_get_rssi(q);
+
+ // get squelch mode
+ int mode = agc_crcf_squelch_get_status(q);
+
+ // check certain conditions based on sample input (assuming 2000 samples)
+ switch (i) {
+ case 0: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_ENABLED); break;
+ case 500: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_ENABLED); break;
+ case 600: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_SIGNALHI); break;
+ case 1400: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_SIGNALHI); break;
+ case 1500: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_SIGNALLO); break;
+ case 1600: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_ENABLED); break;
+ case 1900: CONTEND_EQUALITY(mode, LIQUID_AGC_SQUELCH_ENABLED); break;
+ default:;
+ }
+ }
+
+ // destroy AGC object
+ agc_crcf_destroy(q);
+}
+
