Created
January 25, 2022 20:13
-
-
Save bistromath/75d30dd9691fd18211b306db630d8c4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Embedded Python Blocks: | |
Each time this file is saved, GRC will instantiate the first class it finds | |
to get ports and parameters of your block. The arguments to __init__ will | |
be the parameters. All of them are required to have default values! | |
""" | |
import numpy as np | |
from gnuradio import gr | |
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block | |
"""Embedded Python Block example - a simple multiply const""" | |
def __init__(self, x1=8.1081, x2=1.5413, x3=6.5202, x4=-0.0718, y1=4.6645, y2=2.0965, y3=10.88, y4=-0.003): # only default arguments here | |
"""arguments to this function show up as parameters in GRC""" | |
gr.sync_block.__init__( | |
self, | |
name='Ghorbani amplifier model', # will show up in GRC | |
in_sig=[np.float32, np.float32], | |
out_sig=[np.float32, np.float32] | |
) | |
# if an attribute with the same name as a parameter is found, | |
# a callback is registered (properties work, too). | |
self.x1 = x1 | |
self.x2 = x2 | |
self.x3 = x3 | |
self.x4 = x4 | |
self.y1 = y1 | |
self.y2 = y2 | |
self.y3 = y3 | |
self.y4 = y4 | |
def set_x1(self, x1): | |
self.x1 = x1 | |
def set_x2(self, x2): | |
self.x2 = x2 | |
def set_x3(self, x3): | |
self.x3 = x3 | |
def set_x4(self, x4): | |
self.x4 = x4 | |
def set_y1(self, y1): | |
self.y1 = y1 | |
def set_y2(self, y2): | |
self.y2 = y2 | |
def set_y3(self, y3): | |
self.y3 = y3 | |
def set_y4(self, y4): | |
self.y4 = y4 | |
def work(self, input_items, output_items): | |
"""do the needful""" | |
ampl_in = input_items[0] | |
phase_in = input_items[1] | |
G = (self.x1*np.power(ampl_in, self.x2-1)) / (1 + self.x3*np.power(ampl_in, self.x2)) + self.x4 | |
phi_G = (self.y1*np.power(ampl_in, self.y2 )) / (1 + self.y3*np.power(ampl_in, self.y2)) + self.y4*ampl_in | |
ampl_out = G*ampl_in | |
phase_out = phi_G+phase_in | |
output_items[0][:] = ampl_out | |
output_items[1][:] = phase_out | |
return len(output_items[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment