• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python filters.MultistageChannelFilter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shinysdr.filters.MultistageChannelFilter的典型用法代码示例。如果您正苦于以下问题:Python MultistageChannelFilter类的具体用法?Python MultistageChannelFilter怎么用?Python MultistageChannelFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MultistageChannelFilter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: SimpleAudioDemodulator

class SimpleAudioDemodulator(Demodulator, SquelchMixin):
    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)
    
    @exported_value(type=BandShape, changes='never')  # TODO not sure if this is the right change policy
    def get_band_shape(self):
        """Implements IDemodulator."""
        return self.band_filter_block.get_shape()
    
    def get_output_type(self):
        """Implements IDemodulator."""
        return self.__signal_type

    def set_rec_freq(self, freq):
        """Implements ITunableDemodulator."""
        self.band_filter_block.set_center_freq(freq)
开发者ID:bitglue,项目名称:shinysdr,代码行数:34,代码来源:basic_demod.py


示例2: ChannelFilterMixin

class ChannelFilterMixin(object):
    """Provides a MultistageChannelFilter block and matching implementations of get_band_shape and ITunableDemodulator.
    
    Does not make any connection automatically.
    """
    
    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)
    
    @exported_value(type=BandShape, changes='never')
    def get_band_shape(self):
        """Implements IDemodulator."""
        return self.channel_filter_block.get_shape()

    def set_rec_freq(self, freq):
        """Implements ITunableDemodulator."""
        self.channel_filter_block.set_center_freq(freq)
开发者ID:kpreid,项目名称:shinysdr,代码行数:27,代码来源:basic_demod.py


示例3: test_explain

 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."""))
开发者ID:Analias,项目名称:shinysdr,代码行数:8,代码来源:test_filters.py


示例4: SimpleAudioDemodulator

class SimpleAudioDemodulator(Demodulator, SquelchMixin):
    implements(ITunableDemodulator)
    
    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.band_filter = band_filter
        self.band_filter_transition = band_filter_transition
        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)

    def get_half_bandwidth(self):
        return self.band_filter

    def get_output_type(self):
        return self.__signal_type

    def set_rec_freq(self, freq):
        '''for ITunableDemodulator'''
        self.band_filter_block.set_center_freq(freq)

    @exported_value()
    def get_band_filter_shape(self):
        return {
            'low': -self.band_filter,
            'high': self.band_filter,
            'width': self.band_filter_transition
        }
开发者ID:croutonage,项目名称:shinysdr,代码行数:43,代码来源:basic_demod.py


示例5: __init__

 def __init__(self, mode='MODE-S', input_rate=0, context=None):
     assert input_rate > 0
     gr.hier_block2.__init__(
         self, 'Mode S/ADS-B/1090 demodulator',
         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 xrange(0, 2 ** 5):
         parser_output.subscribe('type%i_dl' % i, parsed_callback)
开发者ID:bitglue,项目名称:shinysdr,代码行数:55,代码来源:__init__.py


示例6: test_one_filter

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'
开发者ID:thefinn93,项目名称:shinysdr,代码行数:21,代码来源:channel_filter_benchmark.py


示例7: __init__

 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)
开发者ID:kpreid,项目名称:shinysdr,代码行数:12,代码来源:basic_demod.py


示例8: __init__

    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)
开发者ID:bitglue,项目名称:shinysdr,代码行数:20,代码来源:basic_demod.py


示例9: __init__

 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)
开发者ID:bitglue,项目名称:shinysdr,代码行数:70,代码来源:rtl_433.py


示例10: test_setters

 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."""))
开发者ID:Analias,项目名称:shinysdr,代码行数:19,代码来源:test_filters.py


示例11: test_center_freq_interpolating

 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)
开发者ID:Analias,项目名称:shinysdr,代码行数:5,代码来源:test_filters.py


示例12: ModeSDemodulator

class ModeSDemodulator(gr.hier_block2, ExportedState):
    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 xrange(0, 2 ** 5):
            parser_output.subscribe('type%i_dl' % i, parsed_callback)

    def __del__(self):
        self.__msgq_runner.stop()
    
    @exported_value(type=RangeT([(0, 30)], unit=units.dB), changes='this_setter', label='Decode threshold')
    def get_decode_threshold(self):
        return self.__demod.get_threshold()
    
    @setter
    def set_decode_threshold(self, value):
        self.__demod.set_threshold(float(value))
    
    @exported_value(float, changes='continuous', label='Messages/sec decoded')
    def get_message_rate(self):
        return round(self.__message_rate_calc.get(), 1)
    
    def get_output_type(self):
        return no_signal
    
    @exported_value(type=BandShape, changes='never')
    def get_band_shape(self):
        return self.__band_filter.get_shape()
开发者ID:thefinn93,项目名称:shinysdr,代码行数:78,代码来源:__init__.py


示例13: RTL433Demodulator

class RTL433Demodulator(gr.hier_block2, ExportedState):
    __log = Logger()  # TODO: log to context/client
    
    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
        self.__process = the_reactor.spawnProcess(
            RTL433ProcessProtocol(context.output_message, self.__log),
            '/usr/bin/env',
            env=None,  # inherit environment
            # These arguments were last reviewed for rtl_433 18.12-142-g6c3ca9b
            args=[
                b'env', b'rtl_433',
                b'-F', b'json',  # output format
                b'-r', str(demod_rate) + b'sps:iq:cf32:-',  # specify input format and to use stdin
                b'-M', 'newmodel',
            ],
            childFDs={
                0: 'w',
                1: 'r',
                2: 2
            })
        sink = make_sink_to_process_stdin(self.__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)
    
    def _close(self):
        # TODO: This never gets called except in tests. Do this better, like by having an explicit life cycle for demodulators.
        self.__process.loseConnection()
    
    @exported_value(type=BandShape, changes='never')
    def get_band_shape(self):
        """implements IDemodulator"""
        if self.__band_filter:
            return self.__band_filter.get_shape()
        else:
            # TODO Reuse UnselectiveAMDemodulator's approach to this
            return BandShape(stop_low=0, pass_low=0, pass_high=0, stop_high=0, markers={})
    
    def get_output_type(self):
        """implements IDemodulator"""
        return no_signal
开发者ID:kpreid,项目名称:shinysdr,代码行数:90,代码来源:rtl_433.py



注:本文中的shinysdr.filters.MultistageChannelFilter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python math.dB函数代码示例发布时间:2022-05-27
下一篇:
Python bottle.redirect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap