Example #1
0
    def test_fff_000(self):
        N = 500         # number of samples to use
        fs = 5000.0     # baseband sampling rate
        rrate = 2.3421  # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(nfilts, nfilts*fs, fs/2, fs/10,
                                        attenuation_dB=80,
                                        window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 121.213
        data = sig_source_f(fs, freq, 1, N)
        signal = blocks.vector_source_f(data)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps, nfilts)
        snk = blocks.vector_sink_f()

        self.tb.connect(signal, pfb, snk)
        self.tb.run() 

        Ntest = 50
        L = len(snk.data())

        # Get group delay and estimate of phase offset from the filter itself.
        delay = pfb.group_delay()
        phase = pfb.phase_offset(freq, fs)
        
        # Create a timeline offset by the filter's group delay
        t = map(lambda x: float(x)/(fs*rrate), xrange(delay, L+delay))

        # Data of the sinusoid at frequency freq with the delay and phase offset.
        expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 2)
    def test_fff_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(nfilts, nfilts*fs, fs/2, fs/10,
                                        attenuation_dB=80,
                                        window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 100
        data = sig_source_f(fs, freq, 1, N)
        signal = blocks.vector_source_f(data)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = blocks.vector_sink_f()

        self.tb.connect(signal, pfb, snk)
        self.tb.run() 

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

        phase = 0.53013
        expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
Example #3
0
    def test_fff_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        rrate = 1.123  # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(
            nfilts,
            nfilts * fs,
            fs / 2,
            fs / 10,
            attenuation_dB=80,
            window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 100
        data = sig_source_f(fs, freq, 1, N)
        signal = blocks.vector_source_f(data)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = blocks.vector_sink_f()

        self.tb.connect(signal, pfb, snk)
        self.tb.run()

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

        phase = 0.53013
        expected_data = map(
            lambda x: math.sin(2. * math.pi * freq * x + phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:],
                                          dst_data[-Ntest:], 3)
    def test02(self):
        # Test real BPSK sync
        excess_bw = 0.35

        sps = 4
        loop_bw = cmath.pi/100.0
        nfilts = 32
        init_phase = nfilts/2
        max_rate_deviation = 0.5
        osps = 1

        ntaps = 11 * int(sps*nfilts)
        taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps,
                                                1.0, excess_bw, ntaps)

        self.test = digital.pfb_clock_sync_fff(sps, loop_bw, taps,
                                               nfilts, init_phase,
                                               max_rate_deviation,
                                               osps)

        data = 10000*[1, -1]
        self.src = blocks.vector_source_f(data, False)

        # pulse shaping interpolation filter
        rrc_taps = filter.firdes.root_raised_cosine(
            nfilts,          # gain
            nfilts,          # sampling rate based on 32 filters in resampler
            1.0,             # symbol rate
            excess_bw,       # excess bandwidth (roll-off factor)
            ntaps)
        self.rrc_filter = filter.pfb_arb_resampler_fff(sps, rrc_taps)

        self.snk = blocks.vector_sink_f()

        self.tb.connect(self.src, self.rrc_filter, self.test, self.snk)
        self.tb.run()

        expected_result = 10000*[1, -1]
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 1000
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp:]
        dst_data = dst_data[len_d - Ncmp:]

        #for e,d in zip(expected_result, dst_data):
        #    print e, d

        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1)
    def test02(self):
        # Test real BPSK sync
        excess_bw = 0.35

        sps = 4
        loop_bw = cmath.pi/100.0
        nfilts = 32
        init_phase = nfilts/2
        max_rate_deviation = 0.5
        osps = 1
        
        ntaps = 11 * int(sps*nfilts)
        taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps,
                                                1.0, excess_bw, ntaps)

        self.test = digital.pfb_clock_sync_fff(sps, loop_bw, taps,
                                               nfilts, init_phase,
                                               max_rate_deviation,
                                               osps)
        
        data = 10000*[1, -1]
        self.src = blocks.vector_source_f(data, False)

        # pulse shaping interpolation filter
        rrc_taps = filter.firdes.root_raised_cosine(
            nfilts,          # gain
            nfilts,          # sampling rate based on 32 filters in resampler
            1.0,             # symbol rate
            excess_bw,       # excess bandwidth (roll-off factor)
            ntaps)
        self.rrc_filter = filter.pfb_arb_resampler_fff(sps, rrc_taps)

        self.snk = blocks.vector_sink_f()

        self.tb.connect(self.src, self.rrc_filter, self.test, self.snk)
        self.tb.run()
        
        expected_result = 10000*[1, -1]
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 1000
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp:]
        dst_data = dst_data[len_d - Ncmp:]

        #for e,d in zip(expected_result, dst_data):
        #    print e, d
        
        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1)
Example #6
0
    def __init__(self):
        gr.top_block.__init__(self)

        input_rate = 200e3  # rate of a broadcast FM station
        audio_rate = 44.1e3  # Rate we send the signal to the speaker

        # resample from the output of the demodulator to the rate of
        # the audio sink.
        resamp_rate = audio_rate / input_rate

        # use a file as a dummy source. Replace this with a real radio
        # receiver to capture signals over-the-air.
        src = blocks.file_source(gr.sizeof_gr_complex, "dummy.dat", True)

        # Set the demodulator using the same deviation as the receiver.
        max_dev = 75e3
        fm_demod_gain = input_rate / (2 * math.pi * max_dev / 8.0)
        fm_demod = analog.quadrature_demod_cf(fm_demod_gain)

        # Create a filter for the resampler and filter the audio
        # signal to 15 kHz. The nfilts is the number of filters in the
        # arbitrary resampler. It logically operates at a rate of
        # nfilts*input_rate, so we make those adjustments when
        # building the filter.
        volume = 0.20
        nfilts = 32
        resamp_taps = firdes.low_pass_2(
            volume * nfilts,  # gain
            nfilts * input_rate,  # sampling rate
            15e3,  # low pass cutoff freq
            1e3,  # width of trans. band
            60,  # stop band attenuaton
            firdes.WIN_KAISER)

        # Build the resampler and filter
        resamp_filter = filter.pfb_arb_resampler_fff(resamp_rate, resamp_taps,
                                                     nfilts)

        # sound card as final sink You may have to add a specific
        # device name as a second argument here, something like
        # "pulse" if using pulse audio or "plughw:0,0".
        audio_sink = audio.sink(int(audio_rate))

        # now wire it all together
        self.connect(src, fm_demod)
        self.connect(fm_demod, resamp_filter)
        self.connect(resamp_filter, (audio_sink, 0))
Example #7
0
    def __init__(self):
        gr.top_block.__init__(self)

        input_rate = 200e3   # rate of a broadcast FM station
        audio_rate = 44.1e3  # Rate we send the signal to the speaker

        # resample from the output of the demodulator to the rate of
        # the audio sink.
        resamp_rate = audio_rate / input_rate

        # use a file as a dummy source. Replace this with a real radio
        # receiver to capture signals over-the-air.
        src = blocks.file_source(gr.sizeof_gr_complex, "dummy.dat", True)

        # Set the demodulator using the same deviation as the receiver.
        max_dev = 75e3
        fm_demod_gain = input_rate/(2*math.pi*max_dev/8.0)
        fm_demod = analog.quadrature_demod_cf(fm_demod_gain)

        # Create a filter for the resampler and filter the audio
        # signal to 15 kHz. The nfilts is the number of filters in the
        # arbitrary resampler. It logically operates at a rate of
        # nfilts*input_rate, so we make those adjustments when
        # building the filter.
        volume = 0.20
        nfilts = 32
        resamp_taps = firdes.low_pass_2(volume*nfilts,      # gain
                                        nfilts*input_rate,  # sampling rate
                                        15e3,               # low pass cutoff freq
                                        1e3,                # width of trans. band
                                        60,                 # stop band attenuaton
                                        firdes.WIN_KAISER)

        # Build the resampler and filter
        resamp_filter = filter.pfb_arb_resampler_fff(resamp_rate,
                                                     resamp_taps, nfilts)

        # sound card as final sink You may have to add a specific
        # device name as a second argument here, something like
        # "pulse" if using pulse audio or "plughw:0,0".
        audio_sink = audio.sink(int(audio_rate))

        # now wire it all together
        self.connect(src, fm_demod)
        self.connect(fm_demod, resamp_filter)
        self.connect(resamp_filter, (audio_sink,0))
    def test_fff_000(self):
        N = 500  # number of samples to use
        fs = 5000.0  # baseband sampling rate
        rrate = 2.3421  # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(
            nfilts,
            nfilts * fs,
            fs / 2,
            fs / 10,
            attenuation_dB=80,
            window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 121.213
        data = sig_source_f(fs, freq, 1, N)
        signal = blocks.vector_source_f(data)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps, nfilts)
        snk = blocks.vector_sink_f()

        self.tb.connect(signal, pfb, snk)
        self.tb.run()

        Ntest = 50
        L = len(snk.data())

        # Get group delay and estimate of phase offset from the filter itself.
        delay = pfb.group_delay()
        phase = pfb.phase_offset(freq, fs)

        # Create a timeline offset by the filter's group delay
        t = [float(x) / (fs * rrate) for x in range(-delay, L - delay)]

        # Data of the sinusoid at frequency freq with the delay and phase
        # offset.
        expected_data = [math.sin(2. * math.pi * freq * x + phase) for x in t]

        dst_data = snk.data()

        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:],
                                          dst_data[-Ntest:], 2)