#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2017 <+YOU OR YOUR COMPANY+>. # # This is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # import numpy as np from gnuradio import gr import code class vector_cutter(gr.sync_block): """ docstring for block vector_cutter """ def __init__(self, insize=2048,outsize=1024,cutpoint=512,pad_out=False,zero_len=0): if pad_out: gr.sync_block.__init__(self, name="vector_cutter", in_sig=[(np.complex64,insize)], out_sig=[(np.complex64,outsize),(np.complex64,insize)]) else: gr.sync_block.__init__(self, name="vector_cutter", in_sig=[(np.complex64,insize)], out_sig=[(np.complex64,outsize)]) self.cutpoint=0 self.set_cutpoint(cutpoint) self.insize=insize self.outsize=outsize #print(pad_out) self.pad_out=pad_out self.zero_len=zero_len self.mask=np.concatenate((np.zeros(zero_len),np.ones(outsize-zero_len*2),np.zeros(zero_len))) def set_zero_len(self,zero_len=None): if zero_len is not None: if isinstance(zero_len, float) or isinstance(zero_len, int): self.zero_len=zero_len else: self.zero_len = int(zero_len) self.mask=np.concatenate((np.zeros(self.zero_len),np.ones(self.outsize-self.zero_len*2),np.zeros(self.zero_len))) def set_cutpoint(self, cutpoint=None): #print("cutpoint set to %i"%cutpoint) if cutpoint is not None and cutpoint>=0: self.cutpoint = int(cutpoint) #if isinstance(cutpoint, float) or isinstance(cutpoint, int): #self.cutpoint=cutpoint #else: #self.cutpoint = int(cutpoint) def work(self, input_items, output_items): in0 = input_items[0] out = output_items[0] if self.pad_out: out_padded = output_items[1] # <+signal processing here+> #out[:] = in0[512:1536] cutpoint=self.cutpoint attenuation=1e-2#40db (power) for i,in_vec in enumerate(in0): if 0<=cutpoint