def __init__(self, interp, taps=None, atten=100): gr.hier_block2.__init__(self, "pfb_interpolator_ccf", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self._interp = interp self._taps = taps 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.99 made = False while not made: try: self._taps = optfir.low_pass(self._interp, self._interp, 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.pfb = filter.pfb_interpolator_ccf(self._interp, self._taps) self.connect(self, self.pfb) self.connect(self.pfb, self)
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 #taps = filter.firdes.low_pass_2(M, ifs, fs/2, fs/10, # attenuation_dB=80, # window=filter.firdes.WIN_BLACKMAN_hARRIS) from pfb_interpolator_taps import taps freq = 100 signal = gr.sig_source_c(fs, gr.GR_COS_WAVE, freq, 1) head = gr.head(gr.sizeof_gr_complex, N) pfb = filter.pfb_interpolator_ccf(M, taps) snk = gr.vector_sink_c() self.tb.connect(signal, head, pfb) self.tb.connect(pfb, snk) self.tb.run() Ntest = 50 L = len(snk.data()) t = map(lambda x: float(x)/ifs, xrange(L)) # Create known data as complex sinusoids at freq # of the channel at the interpolated rate. phase = 0.62833 expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \ 1j*math.sin(2.*math.pi*freq*x+phase), t) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4)