Hi all, sorry I forgot to put my python script in last email.
I'm using python to build an OOT block to do Maximum-Minimum Eigenvalue detection, and I have followed the steps of the algorithm, but when I connect it to a signal source and number sink, it runs too slow and even no results, and the CPU occupation will come to near 100%. I want to know the outcome of signal source is a vector, but how many samples comes to next blocks every time? cos I want to reshape them as arrays to compute their covariance matrix. Are there any problems in my python script? 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 import scipy.linalg import numpy.linalg import math from TracyWidom import * from gnuradio import gr class MME(gr.sync_block): """ docstring for block MME """ def __init__(self,samples,slots,false,algo): self.samples = samples self.slots = slots self.false = false self.algo = algo gr.sync_block.__init__(self, name="MME", in_sig=[numpy.float32], out_sig=[numpy.float32]) ''' def R(self, x): x0 = x - numpy.mean(x) L = self.slots Ns = len(x0) lbd = numpy.empty(L) for l in xrange(L): if l > 0: xu = x0[:-l] else: xu = x0 lbd[l] = numpy.dot(xu, x0[l:])/(Ns-l) return scipy.linalg.toeplitz(lbd) ''' #compute the eigenvalues def lbd(self, x): #R = self.R(x) R = numpy.cov(x) #compute the received sample covariance matrix lbd = numpy.linalg.eigvalsh(R) return numpy.abs(lbd) #compute the threshold def thr_MME(self,Ns,M,false): x = math.sqrt(Ns)+math.sqrt(M*Ns) y = math.sqrt(Ns)-math.sqrt(M*Ns) f = TracyWidom().cdfinv(1-false) thr1 = x*x/(y*y)*(1+x**(-2/3)/(M*Ns*Ns)**(1/6)*f) return thr1 def work(self, input_items, output_items): in0 = input_items[0] out = output_items[0] Ns = self.samples #number of samples M = self.slots #number of slots false = self.false #probability of false alarm # <+signal processing here+> n = len(in0)/Ns/M in1 = numpy.array(in0) in1 = in1[0:n*Ns*M:1] #slice the array in1 = numpy.reshape(in1,(n*M,Ns)) # >>> x = np.arange(16.0).reshape(4, 4) in2 = numpy.split(in1,n) if(self.algo == 0): #use MME detection for i in range(n): lbd = self.lbd(in2[i]) lbd.sort() out[i] = lbd[-1]/lbd[0] if (out[i] >= self.thr_MME(Ns,M,false)): out[i] = 1 else: out[i] = 0 if(self.algo == 1): #use EME detection for i in range(n): lbd = self.lbd(in2[i]) lbd.sort() out[i] = numpy.sum(lbd**2)/lbd[0] return len(output_items[0])
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio