aboutsummaryrefslogtreecommitdiffstats
path: root/src/sdr
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2011-12-17 16:04:15 +0100
committerSylvain Munaut <tnt@246tNt.com>2011-12-17 16:04:58 +0100
commit135ce0561e0cfa08cfe0e0a80f30de373375888a (patch)
treee2d998c3ff75211624844e617e0b74c98f994f26 /src/sdr
parent010025b7c9940a147d59b1194f25c16fa84f4ed9 (diff)
sdr/pi4cxpsk: Add method to detect modulation order
Just another possible method to differentiate FACCH3 from TCH3 Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/sdr')
-rw-r--r--src/sdr/pi4cxpsk.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/sdr/pi4cxpsk.c b/src/sdr/pi4cxpsk.c
index 3ac9abe..3f47c0f 100644
--- a/src/sdr/pi4cxpsk.c
+++ b/src/sdr/pi4cxpsk.c
@@ -657,4 +657,48 @@ err:
return rv;
}
+/*! \brief Estimates modulation order by comparing power of x^2 vs x^4
+ * \param[in] burst_in Complex signal of the burst
+ * \param[in] sps Oversampling used in the input complex signal
+ * \param[in] freq_shift Frequency shift to pre-apply to burst_in (rad/sym)
+ * \returns <0 for error. 2 for BPSK, 4 for QPSK.
+ */
+int
+gmr1_pi4cxpsk_mod_order(struct osmo_cxvec *burst_in, int sps, float freq_shift)
+{
+ struct osmo_cxvec *burst = NULL;
+ float complex sb = 0.0f, sq = 0.0f;
+ float pb, pq;
+ int rv, i;
+
+ /* Normalize the burst and counter rotate by pi/4 */
+ burst = osmo_cxvec_sig_normalize(burst_in, 1, (freq_shift - (M_PIf/4)) / sps, NULL);
+ if (!burst) {
+ rv = -ENOMEM;
+ goto err;
+ }
+
+ DEBUG_SIGNAL("pi4cxpsk_burst", burst);
+
+ /* Detect modulation order by estimating power of x^2 vs x^4 */
+ for (i=0; i<burst->len; i++) {
+ float complex v;
+ v = burst->data[i];
+ v = (v * v) / osmo_normsqf(v);
+ sb += v;
+ sq += v * v;
+ }
+
+ pb = osmo_normsqf(sb);
+ pq = osmo_normsqf(sq);
+
+ rv = pb < (pq / 2.0f) ? 4 : 2;
+
+ /* Done */
+err:
+ osmo_cxvec_free(burst);
+
+ return rv;
+}
+
/*! }@ */