diff options
author | Brennan Ashton <bashton@brennanashton.com> | 2018-04-06 15:00:36 -0700 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-06-25 20:59:56 +0200 |
commit | 28c1644e663b744417d3712f588dcadb98700f40 (patch) | |
tree | c41c58702ea308763bce778c34f814f8646fc702 | |
parent | 0c4e231953c6ac62a1dede2c7ba63a4c3a6b3f43 (diff) |
Restore ability to use absolute thresholding with corr_est
-rw-r--r-- | gr-digital/grc/digital_corr_est_cc.xml | 14 | ||||
-rw-r--r-- | gr-digital/include/gnuradio/digital/corr_est_cc.h | 24 | ||||
-rw-r--r-- | gr-digital/lib/corr_est_cc_impl.cc | 62 | ||||
-rw-r--r-- | gr-digital/lib/corr_est_cc_impl.h | 5 |
4 files changed, 82 insertions, 23 deletions
diff --git a/gr-digital/grc/digital_corr_est_cc.xml b/gr-digital/grc/digital_corr_est_cc.xml index 1a1c449efb..8afd157ea9 100644 --- a/gr-digital/grc/digital_corr_est_cc.xml +++ b/gr-digital/grc/digital_corr_est_cc.xml @@ -32,6 +32,20 @@ <type>float</type> </param> + <param> + <name>Threshold Method</name> + <key>threshold_method</key> + <type>enum</type> + <option> + <name>Absolute</name> + <key>digital.corr_est_cc.THRESHOLD_ABSOLUTE</key> + </option> + <option> + <name>Dynamic</name> + <key>digital.corr_est_cc.THRESHOLD_DYNAMIC</key> + </option> + </param> + <sink> <name>in</name> <type>complex</type> diff --git a/gr-digital/include/gnuradio/digital/corr_est_cc.h b/gr-digital/include/gnuradio/digital/corr_est_cc.h index 237a499b6b..f61b62636e 100644 --- a/gr-digital/include/gnuradio/digital/corr_est_cc.h +++ b/gr-digital/include/gnuradio/digital/corr_est_cc.h @@ -87,20 +87,28 @@ namespace gr { public: typedef boost::shared_ptr<corr_est_cc> sptr; + enum tm_type { + THRESHOLD_DYNAMIC, + THRESHOLD_ABSOLUTE, + }; + /*! * Make a block that correlates against the \p symbols vector * and outputs a phase and symbol timing estimate. * - * \param symbols Set of symbols to correlate against (e.g., a - * sync word). - * \param sps Samples per symbol - * \param mark_delay tag marking delay in samples after the - * corr_start tag - * \param threshold Threshold of correlator, relative to a 100% - * correlation (1.0). Default is 0.9. + * \param symbols Set of symbols to correlate against (e.g., a + * sync word). + * \param sps Samples per symbol + * \param mark_delay tag marking delay in samples after the + * corr_start tag + * \param threshold Threshold of correlator, relative to a 100% + * correlation (1.0). Default is 0.9. + * \param threshold_method Method for computing threshold. + * */ static sptr make(const std::vector<gr_complex> &symbols, - float sps, unsigned int mark_delay, float threshold=0.9); + float sps, unsigned int mark_delay, float threshold=0.9, + tm_type threshold_method=THRESHOLD_ABSOLUTE); virtual std::vector<gr_complex> symbols() const = 0; virtual void set_symbols(const std::vector<gr_complex> &symbols) = 0; diff --git a/gr-digital/lib/corr_est_cc_impl.cc b/gr-digital/lib/corr_est_cc_impl.cc index 5157f8f6de..764781b0e0 100644 --- a/gr-digital/lib/corr_est_cc_impl.cc +++ b/gr-digital/lib/corr_est_cc_impl.cc @@ -39,21 +39,25 @@ namespace gr { corr_est_cc::sptr corr_est_cc::make(const std::vector<gr_complex> &symbols, float sps, unsigned int mark_delay, - float threshold) + float threshold, + tm_type threshold_method) { return gnuradio::get_initial_sptr - (new corr_est_cc_impl(symbols, sps, mark_delay, threshold)); + (new corr_est_cc_impl(symbols, sps, mark_delay, threshold, + threshold_method)); } corr_est_cc_impl::corr_est_cc_impl(const std::vector<gr_complex> &symbols, float sps, unsigned int mark_delay, - float threshold) + float threshold, + tm_type threshold_method) : sync_block("corr_est_cc", io_signature::make(1, 1, sizeof(gr_complex)), io_signature::make(1, 2, sizeof(gr_complex))), d_src_id(pmt::intern(alias())) { d_sps = sps; + d_threshold_method = threshold_method; // In order to easily support the optional second output, // don't deal with an unbounded max number of output items. @@ -195,7 +199,23 @@ namespace gr { corr_est_cc_impl::_set_threshold(float threshold) { d_stashed_threshold = threshold; - d_pfa = -logf(1.0f-threshold); + + // TODO: Right now two methods are computed this should be conditional + switch (d_threshold_method) { + case THRESHOLD_DYNAMIC: + d_pfa = -logf(1.0f-threshold); + break; + case THRESHOLD_ABSOLUTE: + default: + // Compute a correlation threshold. + // Compute the value of the discrete autocorrelation of the matched + // filter with offset 0 (aka the autocorrelation peak). + float corr = 0; + for(size_t i = 0; i < d_symbols.size(); i++) + corr += abs(d_symbols[i]*conj(d_symbols[i])); + d_thresh = threshold*corr*corr; + break; + } } void @@ -231,21 +251,35 @@ namespace gr { volk_32fc_magnitude_squared_32f(&d_corr_mag[0], corr, noutput_items); float detection = 0; - for(int i = 0; i < noutput_items; i++) { - detection += d_corr_mag[i]; + if(d_threshold_method == THRESHOLD_DYNAMIC) + { + for(int i = 0; i < noutput_items; i++) { + detection += d_corr_mag[i]; + } + detection /= static_cast<float>(noutput_items); + detection *= d_pfa; } - detection /= static_cast<float>(noutput_items); - detection *= d_pfa; int isps = (int)(d_sps + 0.5f); int i = 0; while(i < noutput_items) { - // Look for the correlator output to cross the threshold. - // Sum power over two consecutive symbols in case we're offset - // in time. If off by 1/2 a symbol, the peak of any one point - // is much lower. - float corr_mag = d_corr_mag[i] + d_corr_mag[i+1]; - if(corr_mag <= 4*detection) { + float corr_mag; + switch (d_threshold_method) { + case THRESHOLD_DYNAMIC: + // Look for the correlator output to cross the threshold. + // Sum power over two consecutive symbols in case we're offset + // in time. If off by 1/2 a symbol, the peak of any one point + // is much lower. + corr_mag = (d_corr_mag[i] + d_corr_mag[i+1]) * 0.5f; + d_thresh = 2 * detection; + break; + case THRESHOLD_ABSOLUTE: + default: + corr_mag = d_corr_mag[i]; + break; + } + + if (corr_mag <= d_thresh) { i++; continue; } diff --git a/gr-digital/lib/corr_est_cc_impl.h b/gr-digital/lib/corr_est_cc_impl.h index e0d4c8ef25..75f9e2c700 100644 --- a/gr-digital/lib/corr_est_cc_impl.h +++ b/gr-digital/lib/corr_est_cc_impl.h @@ -47,13 +47,16 @@ namespace gr { float d_scale; float d_pfa; // probability of false alarm + tm_type d_threshold_method; + void _set_mark_delay(unsigned int mark_delay); void _set_threshold(float threshold); public: corr_est_cc_impl(const std::vector<gr_complex> &symbols, float sps, unsigned int mark_delay, - float threshold=0.9); + float threshold=0.9, + tm_type threshold_method=THRESHOLD_ABSOLUTE); ~corr_est_cc_impl(); std::vector<gr_complex> symbols() const; |