Simple GNU Radio embedded python block implementation of this: https://github.com/nootedandrooted/rtl-sdr-close-call-monitor
"""
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
import time
from gnuradio import gr
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block
def __init__(self, center_freq = 433920000, sample_rate = 250000, sql_level = -20): # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.sync_block.__init__(
self,
name='Embedded Python Block', # will show up in GRC
in_sig=[np.complex64],
out_sig=[np.float32]
)
# if an attribute with the same name as a parameter is found,
# a callback is registered (properties work, too).
# self.example_param = example_param
self.center_freq = center_freq
self.sample_rate = sample_rate
self.start_freq = center_freq - sample_rate/2
self.end_freq = center_freq + sample_rate/2
self.sql_level = sql_level
def work(self, input_items, output_items):
samples = input_items[0]
freq_range = np.linspace(self.start_freq, self.end_freq, len(samples), endpoint=False)
spectrum = np.abs(np.fft.fftshift(np.fft.fft(samples)))
peak_index = np.argmax(spectrum)
peak_freq = freq_range[peak_index]
if spectrum[peak_index] > self.sql_level:
output_items[0][:] = peak_freq
else:
output_items[0][:] = 0
return len(output_items[0])
Kommentit
Tämän blogin kommentit tarkistetaan ennen julkaisua.