import numpy as np
from gnuradio import gr
class my_snr(gr.decim_block): # decimation = fft_size
"""SNR calculation by George SV1BDS"""
def __init__(self, fft_size = 1024 ): # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.decim_block.__init__(
self,
name='SNR', # will show up in GRC
in_sig=[np.complex64],
out_sig=[np.float32],
decim = fft_size
)
self.set_relative_rate(1.0/fft_size)
self.fft_size = fft_size
def work(self, input_items, output_items):
"""SNR routine"""
a = np.asarray(input_items[0][:])
f = np.fft.fft(a)
x = 10*np.log10(np.real(f*np.conj(f)))
output_items[0][:] = np.amax(x)-np.mean(x)
return 1
Is it of general interest to include it in GNURadio ?
Best regards