コード例 #1
0
ファイル: qa_welch.py プロジェクト: uy0ll/gr-specest
    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
        ma_len = 1
        window = hamming(fft_len)

        src_data = (1,) * ((ma_len + 1) * fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welch(fft_len, overlap, ma_len, 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

        self.assertAlmostEqual(power_est, 1, 5)
コード例 #2
0
ファイル: qa_welch.py プロジェクト: uy0ll/gr-specest
    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
        ma_len = 8

        src_data = (1,) * ((ma_len/2 + 1) * fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welch(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)