From b7323c09566416187bad7728c547c336ffa49253 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Fri, 14 Oct 2022 15:39:20 -0400 Subject: [PATCH] blocks: Allow for floating point error in moving average test Signed-off-by: Clayton Smith --- gr-blocks/python/blocks/qa_moving_average.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gr-blocks/python/blocks/qa_moving_average.py b/gr-blocks/python/blocks/qa_moving_average.py index 8f4169d05cf..6aa3ba3df35 100644 --- a/gr-blocks/python/blocks/qa_moving_average.py +++ b/gr-blocks/python/blocks/qa_moving_average.py @@ -147,7 +147,7 @@ def test_vector_complex(self): ref_data = ref_dst.data() # make sure result is close to zero - self.assertEqual(dut_data, ref_data) + self.assertListAlmostEqual(dut_data, ref_data, tol=3) def test_complex_scalar(self): tb = self.tb From e3e7b41a1f014ca39ec5d244eed01e1caa7cc4cb Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Fri, 14 Oct 2022 15:52:54 -0400 Subject: [PATCH] fft: Increase tolerance in qa_window test Signed-off-by: Clayton Smith --- gr-fft/python/fft/qa_window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gr-fft/python/fft/qa_window.py b/gr-fft/python/fft/qa_window.py index 93ab1a9f93f..ec4877f7867 100644 --- a/gr-fft/python/fft/qa_window.py +++ b/gr-fft/python/fft/qa_window.py @@ -35,7 +35,7 @@ def test_normwin(self): 21, normalize=True) power = numpy.sum([x * x for x in win]) / len(win) - self.assertAlmostEqual(power, 1.0) + self.assertAlmostEqual(power, 1.0, places=6) if __name__ == '__main__': From 05b3b5e4689e6c061268c6df1773f10b021125e6 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Fri, 14 Oct 2022 17:29:30 -0400 Subject: [PATCH 1/2] digital: Account for floating point error in loop conditions Signed-off-by: Clayton Smith --- gr-digital/lib/constellation.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gr-digital/lib/constellation.cc b/gr-digital/lib/constellation.cc index 609b4546b83..4235d17f202 100644 --- a/gr-digital/lib/constellation.cc +++ b/gr-digital/lib/constellation.cc @@ -245,9 +245,9 @@ void constellation::gen_soft_dec_lut(int precision, float npwr) float maxd = 1.0f; float step = (2.0f * maxd) / (d_lut_scale - 1); float y = -maxd; - while (y < maxd + step) { + while (y < maxd + (step / 2)) { float x = -maxd; - while (x < maxd + step) { + while (x < maxd + (step / 2)) { gr_complex pt = gr_complex(x, y); d_soft_dec_lut.push_back(calc_soft_dec(pt, npwr)); x += step; From 830349bb36706aaf872a8a911ead631c9788c2ac Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Fri, 14 Oct 2022 17:31:33 -0400 Subject: [PATCH 2/2] digital: Fix slicer implementation in qa_constellation Signed-off-by: Clayton Smith --- gr-digital/python/digital/qa_constellation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gr-digital/python/digital/qa_constellation.py b/gr-digital/python/digital/qa_constellation.py index 7345f782a2c..1ad86a8d263 100644 --- a/gr-digital/python/digital/qa_constellation.py +++ b/gr-digital/python/digital/qa_constellation.py @@ -117,10 +117,10 @@ def threed_constell(): def slicer(x): ret = [] for xi in x: - if(xi < 0): + if xi < 0: ret.append(0.0) - else: - ret.append(1.0) + else: + ret.append(1.0) return ret From 7c24638f9924cdedeb9b2c9c430b3eb63585de3b Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sat, 15 Oct 2022 10:44:37 -0400 Subject: [PATCH] fec: Fix LDPC output size calculation Signed-off-by: Clayton Smith --- gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc | 2 +- gr-fec/lib/ldpc_par_mtrx_encoder_impl.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc b/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc index a76bd76bae2..56a7aeab4c5 100644 --- a/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc +++ b/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc @@ -55,7 +55,7 @@ bool ldpc_gen_mtrx_encoder_impl::set_frame_size(unsigned int frame_size) d_frame_size = frame_size; - d_output_size = static_cast(d_rate * d_frame_size); + d_output_size = static_cast(round(d_rate * d_frame_size)); return ret; } diff --git a/gr-fec/lib/ldpc_par_mtrx_encoder_impl.cc b/gr-fec/lib/ldpc_par_mtrx_encoder_impl.cc index f9aaa1b65b4..1475aba70d4 100644 --- a/gr-fec/lib/ldpc_par_mtrx_encoder_impl.cc +++ b/gr-fec/lib/ldpc_par_mtrx_encoder_impl.cc @@ -75,7 +75,7 @@ bool ldpc_par_mtrx_encoder_impl::set_frame_size(unsigned int frame_size) d_frame_size = frame_size; - d_output_size = static_cast(d_rate * d_frame_size); + d_output_size = static_cast(round(d_rate * d_frame_size)); return ret; } From 543983116771cee5653514f3cd2f260551edc89d Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 16 Oct 2022 08:22:48 -0400 Subject: [PATCH] analog: Use realistic signals for CTCSS squelch tests Signed-off-by: Clayton Smith --- gr-analog/python/analog/qa_ctcss_squelch.py | 62 +++++++++++++++------ 1 file changed, 45 insertions(+), 17 deletions(-) From 543983116771cee5653514f3cd2f260551edc89d Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 16 Oct 2022 08:22:48 -0400 Subject: [PATCH] analog: Use realistic signals for CTCSS squelch tests Signed-off-by: Clayton Smith --- gr-analog/python/analog/qa_ctcss_squelch.py | 62 +++++++++++++++------ 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/gr-analog/python/analog/qa_ctcss_squelch.py b/gr-analog/python/analog/qa_ctcss_squelch.py index 6151641aa3c..195e19ab9a3 100644 --- a/gr-analog/python/analog/qa_ctcss_squelch.py +++ b/gr-analog/python/analog/qa_ctcss_squelch.py @@ -9,6 +9,8 @@ # +import math +import random from gnuradio import gr, gr_unittest, analog, blocks @@ -46,16 +48,24 @@ def test_ctcss_squelch_001(self): def test_ctcss_squelch_002(self): # Test runtime, gate=True - rate = 1 + rate = 8000 freq = 100 - level = 0.0 - length = 1 - ramp = 1 + other_freq = 103.5 + level = 0.01 + length = 0 + ramp = 0 gate = True - src_data = [float(x) / 10.0 for x in range(1, 40)] - expected_result = src_data - expected_result[0] = 0 + random.seed(1) + src_data = [0.5 * math.sin(2 * math.pi * 1000 * x / rate) + random.gauss(0, 0.1) for x in range(rate)] + + # First half-second has incorrect CTCSS tone + for x in range(0, int(rate * 0.500)): + src_data[x] += 0.15 * math.sin(2 * math.pi * other_freq * x / rate) + + # Second half-second has correct CTCSS tone + for x in range(int(rate * 0.500), rate): + src_data[x] += 0.15 * math.sin(2 * math.pi * freq * x / rate) src = blocks.vector_source_f(src_data) op = analog.ctcss_squelch_ff(rate, freq, level, @@ -67,18 +77,34 @@ def test_ctcss_squelch_002(self): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + + # Squelch should open ~100 ms after the correct CTCSS tone appears + # so ~400 ms of audio should make it past the gate + self.assertGreater(len(result_data), rate * 0.390) + self.assertLess(len(result_data), rate * 0.410) + self.assertFloatTuplesAlmostEqual(src_data[-len(result_data):], result_data, 6) def test_ctcss_squelch_003(self): # Test runtime, gate=False - rate = 1 + rate = 8000 freq = 100 - level = 0.5 - length = 1 - ramp = 1 + other_freq = 103.5 + level = 0.01 + length = 0 + ramp = 0 gate = False - src_data = [float(x) / 10.0 for x in range(1, 40)] + random.seed(1) + src_data = [0.5 * math.sin(2 * math.pi * 1000 * x / rate) + random.gauss(0, 0.1) for x in range(rate)] + + # First half-second has incorrect CTCSS tone + for x in range(0, rate // 2): + src_data[x] += 0.15 * math.sin(2 * math.pi * other_freq * x / rate) + + # Second half-second has correct CTCSS tone + for x in range(rate // 2, rate): + src_data[x] += 0.15 * math.sin(2 * math.pi * freq * x / rate) + src = blocks.vector_source_f(src_data) op = analog.ctcss_squelch_ff(rate, freq, level, length, ramp, gate) @@ -88,11 +114,13 @@ def test_ctcss_squelch_003(self): self.tb.connect(op, dst) self.tb.run() - expected_result = src_data - expected_result[0:5] = [0, 0, 0, 0, 0] - result_data = dst.data() - self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + + # Squelch should open ~100 ms after the correct CTCSS tone appears + min_zero_samples = int(rate * 0.590) + self.assertFloatTuplesAlmostEqual([0] * min_zero_samples, result_data[:min_zero_samples], 6) + max_zero_samples = int(rate * 0.610) + self.assertFloatTuplesAlmostEqual(src_data[max_zero_samples:], result_data[max_zero_samples:], 6) if __name__ == '__main__':