def __init__(self, fftSize=1024, windowType="blackmanharris", iirAlpha=2.0**-3): gr.hier_block2.__init__( self, "LogMagFFT", gr.io_signature(1, 1, gr.sizeof_gr_complex * fftSize), gr.io_signaturev( 2, 2, [gr.sizeof_float * fftSize, gr.sizeof_gr_complex * fftSize]), ) ################################################## # Parameters ################################################## self.fftSize = fftSize self.iirAlpha = iirAlpha self.windowType = windowType ################################################## # Variables ################################################## self.fftWindow = fftWindow = scipy.signal.get_window( windowType, fftSize) ################################################## # Blocks ################################################## self.singlePoleIIR = filter.single_pole_iir_filter_ff( iirAlpha, fftSize) self.nLog10 = CyberRadio.vector_nlog10_ff(10, fftSize, 0) self.fwdFFT = fft.fft_vcc(fftSize, True, (fftWindow / numpy.sum(fftWindow)), True, 1) self.compToMagSq = blocks.complex_to_mag_squared(fftSize) ################################################## # Connections ################################################## self.connect((self, 0), (self.fwdFFT, 0)) self.connect((self.fwdFFT, 0), (self, 1)) self.connect((self.fwdFFT, 0), (self.compToMagSq, 0)) self.connect((self.compToMagSq, 0), (self.singlePoleIIR, 0)) self.connect((self.singlePoleIIR, 0), (self.nLog10, 0)) self.connect((self.nLog10, 0), (self, 0))
def __init__(self, avgGainList=[ 1.0 / 8, 1.0 / 32, ], dipIndex=-1, doLog10=True, enable=True, fftSize=int(2**17), fftWindowType='flattop', index=1, localInterface="", otherDdcArgs={}, otherTunerArgs={}, outSize=int((40.0 / 51.2) * (2**17)), radioInterface=1, radioParam={ "type": "ndr804-ptt", "host": "ndr308", "port": 8617, "obj": None }, rate=16, rfAtten=0, rfFilter=1, rfFreq=1000, udpPort=11000): numOut = len(avgGainList) + 1 gr.hier_block2.__init__( self, "Local NDR804-PTT Snapshot Source", gr.io_signature(0, 0, 0), gr.io_signaturev(numOut, numOut, [gr.sizeof_float * outSize] * numOut), ) self.message_port_register_hier_in("rfFreq") self.message_port_register_hier_in("clearAvg") self.message_port_register_hier_out("rfFreq") ################################################## # Parameters ################################################## self.avgGainList = avgGainList self.dipIndex = dipIndex self.doLog10 = doLog10 = bool(doLog10) self.enable = enable = bool(enable) self.fftSize = fftSize = int(fftSize) self.fftWindowType = fftWindowType self.index = index self.localInterface = localInterface self.otherDdcArgs = otherDdcArgs self.otherTunerArgs = otherTunerArgs self.outSize = outSize self.radioInterface = radioInterface self.radioParam = radioParam self.rate = rate self.rfAtten = rfAtten self.rfFilter = rfFilter self.rfFreq = rfFreq self.udpPort = udpPort ################################################## # Variables ################################################## self.fftWindow = fftWindow = scipy.signal.get_window( fftWindowType, fftSize) self.windowScale = windowScale = fftWindow.sum() / fftWindow.size ################################################## # Blocks ################################################## self.tunerControl = CyberRadio.generic_tuner_control_block( radioParam, index, True, rfFreq, rfAtten, rfFilter, otherTunerArgs, False) self.snapshotToVector = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fftSize) self.snapshotSource = CyberRadio.snapshot_source_c( '0.0.0.0', udpPort, fftSize, rate) if doLog10: self.log10_direct = CyberRadio.vector_nlog10_ff(10, outSize, 0) self.nullSink_direct = blocks.null_sink(gr.sizeof_float * outSize) else: self.log10_direct = None self.fftBlock = fft.fft_vcc(fftSize, True, (fftWindow / fftWindow.sum()), True, 1) self.extractPacketPayload = CyberRadio.vector_keep_m_in_n( gr.sizeof_gr_complex, outSize, fftSize, (fftSize - outSize) / 2) self.ddcControl = CyberRadio.generic_ddc_control_block( radioParam, index, "", #idString bool(enable), True, 0, 1, 0, index, 0, radioInterface, dipIndex, localInterface, udpPort, otherDdcArgs, False) self.compToMagSq = blocks.complex_to_mag_squared(outSize) self.avgFilterList = [] self.avgNullSinkList = [] self.avgLog10List = [] for i in range(numOut - 1): #cep test self.avgFilterList.append( filter.single_pole_iir_filter_ff(avgGainList[i], outSize) ) self.avgFilterList.append( CyberRadio.vector_single_pole_iir_filter_ff( avgGainList[i], outSize, True)) self.avgNullSinkList.append( blocks.null_sink(gr.sizeof_float * outSize)) if doLog10: self.avgLog10List.append( CyberRadio.vector_nlog10_ff(10, outSize, 0)) ################################################## # Connections ################################################## self.msg_connect((self, 'rfFreq'), (self.tunerControl, 'rfFreq')) self.msg_connect((self.tunerControl, 'rfFreq'), (self, 'rfFreq')) for i in range(numOut - 1): self.connect((self.compToMagSq, 0), (self.avgFilterList[i], 0)) #cep test self.msg_connect((self, 'clearAvg'), (self.avgFilterList[i], 'clear')) if doLog10: self.connect((self.avgFilterList[i], 0), (self.avgLog10List[i], 0)) self.connect((self.avgLog10List[i], 0), (self.avgNullSinkList[i], 0)) self.connect((self.avgLog10List[i], 0), (self, i + 1)) else: self.connect((self.avgFilterList[i], 0), (self.avgNullSinkList[i], 0)) self.connect((self.avgFilterList[i], 0), (self, i + 1)) if doLog10: self.connect((self.compToMagSq, 0), (self.log10_direct, 0)) self.connect((self.log10_direct, 0), (self.nullSink_direct, 0)) self.connect((self.log10_direct, 0), (self, 0)) else: self.connect((self.compToMagSq, 0), (self, 0)) self.connect((self.extractPacketPayload, 0), (self.compToMagSq, 0)) self.connect((self.fftBlock, 0), (self.extractPacketPayload, 0)) self.connect((self.snapshotToVector, 0), (self.fftBlock, 0)) self.connect((self.snapshotSource, 0), (self.snapshotToVector, 0))