Exemplo n.º 1
0
    def test_000(self):
        N = 1000  # number of samples to use
        M = 5  # Number of channels
        fs = 1000  # baseband sampling rate
        ifs = M * fs  # input samp rate to decimator
        channel = 0  # Extract channel 0

        taps = filter.firdes.low_pass_2(
            1,
            ifs,
            fs / 2,
            fs / 10,
            attenuation_dB=80,
            window=filter.firdes.WIN_BLACKMAN_hARRIS)

        signals = list()
        add = blocks.add_cc()
        freqs = [-200, -100, 0, 100, 200]
        for i in xrange(len(freqs)):
            f = freqs[i] + (M / 2 - M + i + 1) * fs
            data = sig_source_c(ifs, f, 1, N)
            signals.append(blocks.vector_source_c(data))
            self.tb.connect(signals[i], (add, i))

        head = blocks.head(gr.sizeof_gr_complex, N)
        s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M)
        pfb = filter.pfb_decimator_ccf(M, taps, channel)
        snk = blocks.vector_sink_c()

        self.tb.connect(add, head, s2ss)
        for i in xrange(M):
            self.tb.connect((s2ss, i), (pfb, i))
        self.tb.connect(pfb, snk)

        self.tb.run()

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x) / fs, xrange(L))

        # Create known data as complex sinusoids for the baseband freq
        # of the extracted channel is due to decimator output order.
        phase = 0
        expected_data = map(lambda x: math.cos(2.*math.pi*freqs[2]*x+phase) + \
                                1j*math.sin(2.*math.pi*freqs[2]*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:],
                                            dst_data[-Ntest:], 4)
Exemplo n.º 2
0
    def __init__(self,
                 decim,
                 taps=None,
                 channel=0,
                 atten=100,
                 use_fft_rotators=True,
                 use_fft_filters=True):
        gr.hier_block2.__init__(self, "pfb_decimator_ccf",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self._decim = decim
        self._channel = channel

        if (taps is not None) and (len(taps) > 0):
            self._taps = taps
        else:
            # Create a filter that covers the full bandwidth of the input signal
            bw = 0.4
            tb = 0.2
            ripple = 0.1
            made = False
            while not made:
                try:
                    self._taps = optfir.low_pass(1, self._decim, bw, bw + tb,
                                                 ripple, atten)
                    made = True
                except RuntimeError:
                    ripple += 0.01
                    made = False
                    print(
                        "Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps."
                        % (ripple))

                    # Build in an exit strategy; if we've come this far, it ain't working.
                    if (ripple >= 1.0):
                        raise RuntimeError(
                            "optfir could not generate an appropriate filter.")

        self.s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, self._decim)
        self.pfb = filter.pfb_decimator_ccf(self._decim, self._taps,
                                            self._channel, use_fft_rotators,
                                            use_fft_filters)

        self.connect(self, self.s2ss)

        for i in xrange(self._decim):
            self.connect((self.s2ss, i), (self.pfb, i))

        self.connect(self.pfb, self)
Exemplo n.º 3
0
    def test_000(self):
        N = 1000  # number of samples to use
        M = 5  # Number of channels
        fs = 1000  # baseband sampling rate
        ifs = M * fs  # input samp rate to decimator
        channel = 0  # Extract channel 0

        taps = filter.firdes.low_pass_2(
            1, ifs, fs / 2, fs / 10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS
        )

        signals = list()
        add = gr.add_cc()
        freqs = [-200, -100, 0, 100, 200]
        for i in xrange(len(freqs)):
            f = freqs[i] + (M / 2 - M + i + 1) * fs
            signals.append(gr.sig_source_c(ifs, gr.GR_SIN_WAVE, f, 1))
            self.tb.connect(signals[i], (add, i))

        head = gr.head(gr.sizeof_gr_complex, N)
        s2ss = gr.stream_to_streams(gr.sizeof_gr_complex, M)
        pfb = filter.pfb_decimator_ccf(M, taps, channel)
        snk = gr.vector_sink_c()

        self.tb.connect(add, head, s2ss)
        for i in xrange(M):
            self.tb.connect((s2ss, i), (pfb, i))
        self.tb.connect(pfb, snk)

        self.tb.run()

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x) / fs, xrange(L))

        # Create known data as complex sinusoids for the baseband freq
        # of the extracted channel is due to decimator output order.
        phase = 0
        expected_data = map(
            lambda x: math.cos(2.0 * math.pi * freqs[2] * x + phase)
            + 1j * math.sin(2.0 * math.pi * freqs[2] * x + phase),
            t,
        )

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4)
Exemplo n.º 4
0
    def __init__(self, decim, taps=None, channel=0, atten=100,
                 use_fft_rotators=True, use_fft_filters=True):
	gr.hier_block2.__init__(self, "pfb_decimator_ccf",
				gr.io_signature(1, 1, gr.sizeof_gr_complex),
				gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self._decim = decim
        self._channel = channel

        if (taps is not None) and (len(taps) > 0):
            self._taps = taps
        else:
            # Create a filter that covers the full bandwidth of the input signal
            bw = 0.4
            tb = 0.2
            ripple = 0.1
            made = False
            while not made:
                try:
                    self._taps = optfir.low_pass(1, self._decim, bw, bw+tb, ripple, atten)
                    made = True
                except RuntimeError:
                    ripple += 0.01
                    made = False
                    print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple))

                    # Build in an exit strategy; if we've come this far, it ain't working.
                    if(ripple >= 1.0):
                        raise RuntimeError("optfir could not generate an appropriate filter.")

        self.s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, self._decim)
        self.pfb = filter.pfb_decimator_ccf(self._decim, self._taps, self._channel,
                                            use_fft_rotators, use_fft_filters)

        self.connect(self, self.s2ss)

        for i in xrange(self._decim):
            self.connect((self.s2ss,i), (self.pfb,i))

        self.connect(self.pfb, self)