Hi all, I'm building a new block by python to do sequential energy detector. In my python block file, I want to divide my input into different part with same length(number). And add the samples in each part.The python file is attached. But when I use my block, it always print as follows: pn[i] += d IndexError: list index out of range Evey suggestion will be appreciated. Thanks in advance. Yan This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system, you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2016 <+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 from gnuradio import gr class seq_ed(gr.sync_block): """ docstring for block seq_ed """ def __init__(self,number,slots,beta,alpha,noise): self.number=number self.slots=slots self.beta=beta self.alpha=alpha self.noise=noise gr.sync_block.__init__(self, name="seq_ed", in_sig=[numpy.float32], out_sig=[numpy.float32]) #def get_sequential_energy(self, sample): def work(self, input_items, output_items): in0 = input_items[0] out = output_items[0] for i in range(0,len(in0)/self.number): pn = [] m = i*self.number for d in in0[m: m + self.number]: pn[i] += d if pn[i] >= self.alpha: out[i] = 1 elif pn[i] <= self.beta: out[i] = 0 else: if pn[i] >= self.noise: out[i] = 1 else: out[i] = 0 return len(output_items[0])
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio