File: rms_agc.py

package info (click to toggle)
gr-satellites 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,836 kB
  • sloc: python: 29,546; cpp: 5,448; ansic: 1,247; sh: 118; makefile: 24
file content (72 lines) | stat: -rw-r--r-- 2,393 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-

#
# SPDX-License-Identifier: GPL-3.0
#
# GNU Radio Python Flow Graph
# Title: RMS AGC
# Author: Daniel Estevez
# Description: AGC using RMS
# GNU Radio version: 3.8.0.0

from gnuradio import blocks
from gnuradio import gr
from gnuradio.filter import firdes


class rms_agc(gr.hier_block2):
    def __init__(self, alpha=1e-2, reference=0.5):
        gr.hier_block2.__init__(
            self,
            'RMS AGC',
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
        )
        ##################################################
        # Parameters
        ##################################################
        self.alpha = alpha
        self.reference = reference

        ##################################################
        # Blocks
        ##################################################
        self.blocks_rms_xx_0 = blocks.rms_cf(alpha)
        self.blocks_multiply_const_vxx_0 = (
            blocks.multiply_const_ff(1.0/reference))
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_divide_xx_0 = blocks.divide_cc(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_ff(1e-19)

        ##################################################
        # Connections
        ##################################################
        self.connect(
            (self.blocks_add_const_vxx_0, 0),
            (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_divide_xx_0, 0), (self, 0))
        self.connect(
            (self.blocks_float_to_complex_0, 0),
            (self.blocks_divide_xx_0, 1))
        self.connect(
            (self.blocks_multiply_const_vxx_0, 0),
            (self.blocks_add_const_vxx_0, 0))
        self.connect(
            (self.blocks_rms_xx_0, 0),
            (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self, 0), (self.blocks_divide_xx_0, 0))
        self.connect((self, 0), (self.blocks_rms_xx_0, 0))

    def get_alpha(self):
        return self.alpha

    def set_alpha(self, alpha):
        self.alpha = alpha
        self.blocks_rms_xx_0.set_alpha(self.alpha)

    def get_reference(self):
        return self.reference

    def set_reference(self, reference):
        self.reference = reference
        self.blocks_multiply_const_vxx_0.set_k(1.0/self.reference)