예제 #1
0
    def __init__(self,
                 input_rate,
                 output_rate=12000,
                 output_frequency=1500,
                 transition_width=100,
                 width=800):
        """Make a new WSPRFilter.

        input_rate: the incomming sample rate

        output_rate: output sample rate

        output_frequency: 0Hz in the complex input will be centered on this
        frequency in the real output

        width, transition_width: passband and transition band widths.
        """

        gr.hier_block2.__init__(self,
                                type(self).__name__,
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_float))

        self.connect(
            self,
            MultistageChannelFilter(input_rate=input_rate,
                                    output_rate=output_rate,
                                    cutoff_freq=width / 2,
                                    transition_width=transition_width),
            blocks.rotator_cc(2 * pi * output_frequency / output_rate),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(reference=dB(-10),
                           attack_rate=8e-1,
                           decay_rate=8e-1), self)
예제 #2
0
    def __init__(self,
                 demod_rate=0,
                 audio_rate=0,
                 band_filter=None,
                 band_filter_transition=None,
                 stereo=False,
                 **kwargs):
        assert audio_rate > 0

        self.__signal_type = SignalType(kind='STEREO' if stereo else 'MONO',
                                        sample_rate=audio_rate)

        Demodulator.__init__(self, **kwargs)
        SquelchMixin.__init__(self, demod_rate)

        self.demod_rate = demod_rate
        self.audio_rate = audio_rate

        input_rate = self.input_rate

        self.band_filter_block = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=band_filter,
            transition_width=band_filter_transition)
예제 #3
0
 def test_odd_interpolating(self):
     """Output rate higher than input rate and not a multiple"""
     # TODO: Test filter functionality more
     f = MultistageChannelFilter(input_rate=8000, output_rate=21234, cutoff_freq=8000, transition_width=5000)
     self.__run(f, 4000, 21234 / 8000, """\
         2 stages from 8000 to 21234
           freq xlation only using   1 taps (8000) in freq_xlating_fir_filter_ccc_sptr
           rational_resampler by 10617/4000 (stage rates 21234/8000) using 350361 taps (7439565474) in rational_resampler_base_ccf_sptr""")
예제 #4
0
 def test_interpolating(self):
     """Output rate higher than input rate"""
     # TODO: Test filter functionality more
     f = MultistageChannelFilter(input_rate=8000, output_rate=20000, cutoff_freq=8000, transition_width=5000)
     self.__run(f, 4000, 20000 / 8000, """\
         2 stages from 8000 to 20000
           freq xlation only using   1 taps (8000) in freq_xlating_fir_filter_ccc_sptr
           rational_resampler by 5/2 (stage rates 20000/8000) using 165 taps (3300000) in rational_resampler_base_ccf_sptr""")
예제 #5
0
 def test_explain(self):
     # this test was written before __run checke everything; kept around for just another example
     f = MultistageChannelFilter(input_rate=10000, output_rate=1000, cutoff_freq=500, transition_width=100)
     self.assertEqual(f.explain(), textwrap.dedent("""\
         2 stages from 10000 to 1000
           freq xlate and decimate by 5 using  43 taps (86000) in freq_xlating_fir_filter_ccc_sptr
           final filter and decimate by 2 using  49 taps (49000) in fft_filter_ccc_sptr
           No final resampler stage."""))
예제 #6
0
 def test_center_freq_interpolating(self):
     f = MultistageChannelFilter(input_rate=1000,
                                 output_rate=10000,
                                 cutoff_freq=400,
                                 transition_width=200,
                                 center_freq=1)
     self.assertEqual(f.get_center_freq(), 1)
     f.set_center_freq(2)
     self.assertEqual(f.get_center_freq(), 2)
예제 #7
0
    def __init__(self, mode='MODE-S', input_rate=0, context=None):
        assert input_rate > 0
        gr.hier_block2.__init__(
            self,
            type(self).__name__, gr.io_signature(1, 1,
                                                 gr.sizeof_gr_complex * 1),
            gr.io_signature(0, 0, 0))

        demod_rate = 2000000
        transition_width = 500000

        hex_msg_queue = gr.msg_queue(100)

        self.__band_filter = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=demod_rate / 2,
            transition_width=transition_width)  # TODO optimize filter band
        self.__demod = air_modes.rx_path(
            rate=demod_rate,
            threshold=7.0,  # default used in air-modes code but not exposed
            queue=hex_msg_queue,
            use_pmf=False,
            use_dcblock=True)
        self.connect(self, self.__band_filter, self.__demod)

        self.__messages_seen = 0
        self.__message_rate_calc = LazyRateCalculator(
            lambda: self.__messages_seen, min_interval=2)

        # Parsing
        # TODO: These bits are mimicking gr-air-modes toplevel code. Figure out if we can have less glue.
        # Note: gr pubsub is synchronous -- subscribers are called on the publisher's thread
        parser_output = gr.pubsub.pubsub()
        parser = air_modes.make_parser(parser_output)
        cpr_decoder = air_modes.cpr_decoder(
            my_location=None)  # TODO: get position info from device
        air_modes.output_print(cpr_decoder, parser_output)

        def msq_runner_callback(msg):  # called on msgq_runner's thread
            # pylint: disable=broad-except
            try:
                reactor.callFromThread(parser, msg.to_string())
            except Exception:
                print(traceback.format_exc())

        self.__msgq_runner = gru.msgq_runner(hex_msg_queue,
                                             msq_runner_callback)

        def parsed_callback(msg):
            timestamp = time.time()
            self.__messages_seen += 1
            context.output_message(
                ModeSMessageWrapper(msg, cpr_decoder, timestamp))

        for i in six.moves.range(0, 2**5):
            parser_output.subscribe('type%i_dl' % i, parsed_callback)
예제 #8
0
파일: __init__.py 프로젝트: tashby/shinysdr
    def __make_channel_filter(self):
        '''Return the channel filter.

        rtty_demod_cb includes filters, so here we just need a broad, cheap filter to
        decimate.
        '''
        return MultistageChannelFilter(input_rate=self.__input_rate,
                                       output_rate=self.__demod_rate,
                                       cutoff_freq=self.__spacing * 5,
                                       transition_width=self.__spacing * 5)
예제 #9
0
    def __make_channel_filter(self):
        '''Return the channel filter.

        psk31_demodulator_cbc includes filters, so this filter will be wide to
        assure the passband has no group delay and make it easier to listen to.

        Output has frequencies from -250 to +250.
        '''
        return MultistageChannelFilter(input_rate=self.__input_rate,
                                       output_rate=self.__demod_rate,
                                       cutoff_freq=250 - 25,
                                       transition_width=25)
예제 #10
0
 def test_float_rates(self):
     # Either float or int rates should be accepted
     f = MultistageChannelFilter(input_rate=32000000.0, output_rate=16000.0, cutoff_freq=3000, transition_width=1200)
     self.__run(f, 400000, 16000 / 32000000, """\
         7 stages from 32000000 to 16000
           freq xlate and decimate by 5 using  25 taps (160000000) in freq_xlating_fir_filter_ccc_sptr
           decimate by 5 using  25 taps (32000000) in fft_filter_ccc_sptr
           decimate by 5 using  25 taps (6400000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (1408000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (704000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (352000) in fft_filter_ccc_sptr
           final filter and decimate by 2 using  65 taps (1040000) in fft_filter_ccc_sptr
           No final resampler stage.""")
예제 #11
0
 def test_basic(self):
     # TODO: Test filter functionality more
     f = MultistageChannelFilter(input_rate=32000000, output_rate=16000, cutoff_freq=3000, transition_width=1200)
     self.__run(f, 400000, 16000 / 32000000, """\
         7 stages from 32000000 to 16000
           freq xlate and decimate by 5 using  25 taps (160000000) in freq_xlating_fir_filter_ccc_sptr
           decimate by 5 using  25 taps (32000000) in fft_filter_ccc_sptr
           decimate by 5 using  25 taps (6400000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (1408000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (704000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (352000) in fft_filter_ccc_sptr
           final filter and decimate by 2 using  65 taps (1040000) in fft_filter_ccc_sptr
           No final resampler stage.""")
예제 #12
0
 def test_decimating(self):
     """Sample problematic decimation case"""
     # TODO: Test filter functionality more
     f = MultistageChannelFilter(input_rate=8000000, output_rate=48000, cutoff_freq=10000, transition_width=5000)
     self.__run(f, 400000, 48000 / 8000000, """\
         8 stages from 8000000 to 48000
           freq xlate and decimate by 2 using   9 taps (36000000) in freq_xlating_fir_filter_ccc_sptr
           decimate by 2 using   9 taps (18000000) in fir_filter_ccc_sptr
           decimate by 2 using   9 taps (9000000) in fir_filter_ccc_sptr
           decimate by 2 using   9 taps (4500000) in fir_filter_ccc_sptr
           decimate by 2 using  11 taps (2750000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (1375000) in fft_filter_ccc_sptr
           final filter and decimate by 2 using  61 taps (3812500) in fft_filter_ccc_sptr
           rational_resampler by 96/125 (stage rates 48000/62500) using 4128 taps (198144000) in rational_resampler_base_ccf_sptr""")
예제 #13
0
    def __init__(self,
                 input_rate=0,
                 demod_rate=0,
                 cutoff_freq=0,
                 transition_width=0):
        # mandatory keyword arguments
        assert input_rate > 0
        assert demod_rate > 0
        assert cutoff_freq > 0
        assert transition_width > 0

        self.channel_filter_block = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=cutoff_freq,
            transition_width=transition_width)
예제 #14
0
    def __init__(self, mode,
            input_rate=0,
            context=None):
        assert input_rate > 0
        gr.hier_block2.__init__(
            self, 'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )
        self.__text = u''
        
        baud = _DEFAULT_BAUD  # TODO param
        self.baud = baud

        demod_rate = 6000  # TODO optimize this value
        self.samp_rate = demod_rate  # TODO rename
        
        self.__channel_filter = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=self.__filter_high,
            transition_width=self.__transition)  # TODO optimize filter band
        self.__sharp_filter = grfilter.fir_filter_ccc(
            1,
            firdes.complex_band_pass(1.0, demod_rate,
                self.__filter_low,
                self.__filter_high,
                self.__transition,
                firdes.WIN_HAMMING))
        self.fsk_demod = RTTYFSKDemodulator(input_rate=demod_rate, baud=baud)
        self.__real = blocks.complex_to_real(vlen=1)
        self.__char_queue = gr.msg_queue(limit=100)
        self.char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        self.connect(
            self,
            self.__channel_filter,
            self.__sharp_filter,
            self.fsk_demod,
            rtty.rtty_decode_ff(rate=demod_rate, baud=baud, polarity=False),
            self.char_sink)
        
        self.connect(
            self.__sharp_filter,
            self.__real,
            self)
예제 #15
0
 def test_setters(self):
     # TODO: Test filter functionality; this only tests that the operations work
     filt = MultistageChannelFilter(input_rate=32000000, output_rate=16000, cutoff_freq=3000, transition_width=1200)
     filt.set_cutoff_freq(2900)
     filt.set_transition_width(1000)
     filt.set_center_freq(10000)
     self.assertEqual(2900, filt.get_cutoff_freq())
     self.assertEqual(1000, filt.get_transition_width())
     self.assertEqual(10000, filt.get_center_freq())
     self.assertEqual(filt.explain(), textwrap.dedent("""\
         7 stages from 32000000 to 16000
           freq xlate and decimate by 5 using  25 taps (160000000) in freq_xlating_fir_filter_ccc_sptr
           decimate by 5 using  25 taps (32000000) in fft_filter_ccc_sptr
           decimate by 5 using  25 taps (6400000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (1408000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (704000) in fft_filter_ccc_sptr
           decimate by 2 using  11 taps (352000) in fft_filter_ccc_sptr
           final filter and decimate by 2 using  77 taps (1232000) in fft_filter_ccc_sptr
           No final resampler stage."""))
예제 #16
0
def test_one_filter(**kwargs):
    print '------ %s -------' % (kwargs, )
    f = MultistageChannelFilter(**kwargs)

    size = 10000000

    top = gr.top_block()
    top.connect(blocks.vector_source_c([5] * size), f,
                blocks.null_sink(gr.sizeof_gr_complex))

    print f.explain()

    t0 = time.clock()
    top.start()
    top.wait()
    top.stop()
    t1 = time.clock()

    print size, 'samples processed in', t1 - t0, 'CPU-seconds'
예제 #17
0
    def __init__(self, mode, input_rate, context):
        channels = 2
        audio_rate = 10000
        
        gr.hier_block2.__init__(
            self, str('%s demodulator' % (mode,)),
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(1, 1, gr.sizeof_float * channels))

        self.__input_rate = input_rate
        self.__rec_freq_input = 0.0
        self.__signal_type = SignalType(kind='STEREO', sample_rate=audio_rate)

        # Using agc2 rather than feedforward AGC for efficiency, because this runs at the RF rate rather than the audio rate.
        agc_block = analog.agc2_cc(reference=dB(-8))
        agc_block.set_attack_rate(8e-3)
        agc_block.set_decay_rate(8e-3)
        agc_block.set_max_gain(dB(40))
        
        self.connect(
            self,
            agc_block)
        
        channel_joiner = blocks.streams_to_vector(gr.sizeof_float, channels)
        self.connect(channel_joiner, self)
        
        for channel in six.moves.range(0, channels):
            self.connect(
                agc_block,
                grfilter.fir_filter_ccc(1, design_sawtooth_filter(decreasing=channel == 0)),
                blocks.complex_to_mag(1),
                blocks.float_to_complex(),  # So we can use the complex-input band filter. TODO eliminate this for efficiency
                MultistageChannelFilter(
                    input_rate=input_rate,
                    output_rate=audio_rate,
                    cutoff_freq=5000,
                    transition_width=5000),
                blocks.complex_to_real(),
                # assuming below 40Hz is not of interest
                grfilter.dc_blocker_ff(audio_rate // 40, False),
                (channel_joiner, channel))
예제 #18
0
    def __init__(self, mode='433', input_rate=0, context=None):
        assert input_rate > 0
        assert context is not None
        gr.hier_block2.__init__(self,
                                type(self).__name__,
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))

        # The input bandwidth chosen is not primarily determined by the bandwidth of the input signals, but by the frequency error of the transmitters. Therefore it is not too critical, and we can choose the exact rate to make the filtering easy.
        if input_rate <= upper_preferred_demod_rate:
            # Skip having a filter at all.
            self.__band_filter = None
            demod_rate = input_rate
        else:
            # TODO: This gunk is very similar to the stuff that MultistageChannelFilter does. See if we can share some code.
            lower_rate = input_rate
            lower_rate_prev = None
            while lower_rate > upper_preferred_demod_rate and lower_rate != lower_rate_prev:
                lower_rate_prev = lower_rate
                if lower_rate % 5 == 0 and lower_rate > upper_preferred_demod_rate * 3:
                    lower_rate /= 5
                elif lower_rate % 2 == 0:
                    lower_rate /= 2
                else:
                    # non-integer ratio
                    lower_rate = upper_preferred_demod_rate
                    break
            demod_rate = lower_rate

            self.__band_filter = MultistageChannelFilter(
                input_rate=input_rate,
                output_rate=demod_rate,
                cutoff_freq=demod_rate * 0.4,
                transition_width=demod_rate * 0.2)

        # Subprocess
        # using /usr/bin/env because twisted spawnProcess doesn't support path search
        # pylint: disable=no-member
        process = the_reactor.spawnProcess(
            RTL433ProcessProtocol(context.output_message),
            '/usr/bin/env',
            env=None,  # inherit environment
            args=[
                'env',
                'rtl_433',
                '-F',
                'json',
                '-r',
                '-',  # read from stdin
                '-m',
                '3',  # complex float input
                '-s',
                str(demod_rate),
            ],
            childFDs={
                0: 'w',
                1: 'r',
                2: 2
            })
        sink = make_sink_to_process_stdin(process,
                                          itemsize=gr.sizeof_gr_complex)

        agc = analog.agc2_cc(reference=dB(-4))
        agc.set_attack_rate(200 / demod_rate)
        agc.set_decay_rate(200 / demod_rate)

        if self.__band_filter:
            self.connect(self, self.__band_filter, agc)
        else:
            self.connect(self, agc)
        self.connect(agc, sink)