text
stringlengths 1
93.6k
|
|---|
for i in inputs:
|
print ('Block', self, ' Input', i)
|
for i in outputs:
|
print ('Block', self, ' Output', i)
|
print (self, len(args), len(inputs), inputs)
|
if len(args) < len(inputs):
|
raise ValueError('Not enough arguments for input')
|
args = list(args)
|
for i, input in enumerate(inputs):
|
input.index = i
|
source = args.pop(0)
|
if isinstance(source, Block):
|
source = source.output
|
print ('Assign output', self, source)
|
input.source = source
|
for i, output in enumerate(outputs):
|
output.index = i
|
input_types = [x.type for x in inputs]
|
output_types = [x.type for x in outputs]
|
name = self.__class__.__name__
|
if hasattr(self, 'general_work'):
|
self.gr_block = gr.basic_block(name, input_types, output_types)
|
self.gr_block.general_work = self.general_work
|
self.init(*args, **kwargs)
|
assert hasattr(self, 'gr_block')
|
class InOutBlock(Block):
|
"A base class for the default case of a block with input and one output"
|
input = Input()
|
output = Output(input)
|
class BandPass(InOutBlock):
|
def init(self, lo, hi):
|
nyquist = self.input.sample_rate / 2.0
|
Wp = [lo / nyquist, hi / nyquist]
|
#Ws = [(lo - 1) / nyquist, (hi+1) / nyquist]
|
#b, a = scipy.signal.iirdesign(Wp, Ws, 0.1, 60.0)
|
b, a = scipy.signal.iirfilter(6, Wp, btype='bandpass',
|
ftype='ellip', rp=0.1, rs=60.0)
|
#self.gr_block = filter.iir_filter_ffd(a, b, oldstyle=False)
|
self.gr_block = filter.iir_filter_ffd(b, a, oldstyle=False)
|
class NotchFilter(InOutBlock):
|
def init(self, freq=50.0, mod=0.9):
|
theta = 2 * np.pi * 50 / self.input.sample_rate
|
zero = np.exp(np.array([1j, -1j]) * theta)
|
pole = mod * zero
|
a, b = np.poly(pole), np.poly(zero)
|
#notch_ab = numpy.poly(zero), numpy.poly(pole)
|
#notch_ab = scipy.signal.iirfilter(32, [30.0 / 125], btype='low')
|
self.gr_block = filter.iir_filter_ffd(b, a, oldstyle=False)
|
class RMS(InOutBlock):
|
def init(self, alpha=0.01):
|
self.gr_block = blocks.rms_ff(alpha)
|
class DCBlock(InOutBlock):
|
def init(self, taps=16):
|
self.gr_block = filter.dc_blocker_ff(16, long_form=False)
|
class ExponentialAverage(InOutBlock):
|
def init(self, lookback = 1.0):
|
samples = length * self.input.sample_rate
|
scale = 1.0 / samples
|
self.gr_block = blocks.moving_average_ff(int(samples), scale)
|
def general_work(self, input_items, output_items):
|
print ('BarSpectrogram work', len(input_items[0]), output_items, input_items[0][0])
|
self.gr_block.consume_each(1)
|
self.gr_block.produce_each(1)
|
output_items[0][0] = result
|
self.buffer = input_items[0][-len(self.win):]
|
return 0
|
class Oscilloscope(Block):
|
input = Input()
|
def init(self, history=512, autoscale=True):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.