Ejemplo n.º 1
0
    def test_001(self):
        """ Run test:
        - No overlap
        - Hamming window from Python
        - Constant input signal of amplitude 1

        The given input signal has a known power of 1. Therefore, the integral of the
        PSD estimation result should be pretty close to 1."""
        fft_len = 256
        overlap = 0
        alpha = 0.1
        window = hamming(fft_len)

        src_data = (1,) * (100 * fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welchsp(fft_len, overlap, alpha, False, window)
        sink = blocks.vector_sink_f(fft_len)

        self.tb.connect(src, welch, sink)
        self.tb.run()

        dst_data =  sink.data()
        dst_data = array(dst_data[-fft_len:])
        power_est = sum(dst_data) * 2 * pi / fft_len
        print power_est

        self.assertAlmostEqual(power_est, 1, 3)
Ejemplo n.º 2
0
    def test_001(self):
        """ Run test:
        - No overlap
        - Hamming window from Python
        - Constant input signal of amplitude 1

        The given input signal has a known power of 1. Therefore, the integral of the
        PSD estimation result should be pretty close to 1."""
        fft_len = 256
        overlap = 0
        alpha = 0.1
        window = hamming(fft_len)

        src_data = (1, ) * (100 * fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welchsp(fft_len, overlap, alpha, False, window)
        sink = blocks.vector_sink_f(fft_len)

        self.tb.connect(src, welch, sink)
        self.tb.run()

        dst_data = sink.data()
        dst_data = array(dst_data[-fft_len:])
        power_est = sum(dst_data) * 2 * pi / fft_len
        print(power_est)

        self.assertAlmostEqual(power_est, 1, 3)
Ejemplo n.º 3
0
    def test_default_002(self):
        """ Same test as before, but different parameters (FFT length, moving average and
        the window comes from C++). """
        fft_len = 1024

        src_data = (1,) * (100* fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welchsp(fft_len)
        sink = blocks.vector_sink_f(fft_len)

        self.tb.connect(src, welch, sink)
        self.tb.run()

        dst_data =  sink.data()
        dst_data = array(dst_data[-fft_len:])
        power_est = sum(dst_data) * 2 * pi / fft_len

        self.assertAlmostEqual(power_est, 1, 5)
Ejemplo n.º 4
0
    def test_default_002(self):
        """ Same test as before, but different parameters (FFT length, moving average and
        the window comes from C++). """
        fft_len = 1024

        src_data = (1, ) * (100 * fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welchsp(fft_len)
        sink = blocks.vector_sink_f(fft_len)

        self.tb.connect(src, welch, sink)
        self.tb.run()

        dst_data = sink.data()
        dst_data = array(dst_data[-fft_len:])
        power_est = sum(dst_data) * 2 * pi / fft_len

        self.assertAlmostEqual(power_est, 1, 5)