def notest_debug(self):
     src = blocks.vector_source_c(range(100), False, 1, [])
     separator = inspector_test.signal_separator_c(32000, firdes.WIN_HAMMING, 0.1, 100)
     msg = pmt.make_vector(1, pmt.PMT_NIL)
     flanks = pmt.make_f32vector(2, 0.0)
     pmt.f32vector_set(flanks, 0, 12500)
     pmt.f32vector_set(flanks, 1, 20)
     pmt.vector_set(msg, 0, flanks)
     msg_src = blocks.message_strobe(msg, 100)
Exemplo n.º 2
0
    def test_001_t(self):
        src = blocks.vector_source_c(list(range(10000)), False, 1, [])
        separator = inspector_test.signal_separator_c(
            32000, firdes.WIN_HAMMING, 0.1, 100, False,
            inspector_test.map_float_vector({0.0: [0.0]}))
        vec_sink = blocks.vector_sink_c(1)
        ext = inspector_test.signal_extractor_c(0)
        snk = blocks.vector_sink_c(1)
        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12500)
        pmt.f32vector_set(flanks, 1, 20)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)

        taps = filter.firdes.low_pass(1, 32000, 500, 50, firdes.WIN_HAMMING,
                                      6.76)

        self.tb.connect(src, separator)
        self.tb.connect(src, vec_sink)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))
        self.tb.msg_connect((separator, 'sig_out'), (ext, 'sig_in'))
        self.tb.connect(ext, snk)

        self.tb.start()
        time.sleep(0.3)
        self.tb.stop()
        self.tb.wait()

        data = vec_sink.data()

        sig = numpy.zeros(len(vec_sink.data()), dtype=complex)
        for i in range(len(vec_sink.data())):
            sig[i] = data[i] * numpy.exp(
                -1j * 2 * numpy.pi * 12500 * i * 1 / 32000)

        taps = filter.firdes.low_pass(1, 32000, 900, 90, firdes.WIN_HAMMING,
                                      6.76)
        sig = numpy.convolve(sig, taps, 'full')
        out = numpy.empty([0])
        decim = 32000 / 20 / 100
        j = 0
        for i in range(len(sig) / decim):
            out = numpy.append(out, sig[j])
            j += decim

        data = snk.data()
        for i in range(min(len(out), len(data))):
            self.assertComplexAlmostEqual2(out[i], data[i], abs_eps=0.01)
Exemplo n.º 3
0
    def no_test_sebastian (self):
        src = blocks.vector_source_c(range(100), False, 1, [])
        separator = inspector_test.signal_separator_c(32000, firdes.WIN_HAMMING, 0.1, 100)

        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12490)
        pmt.f32vector_set(flanks, 1, 12510)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)

        self.tb.connect(src, separator)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))

        self.tb.run()
    def test_001_t (self):
        src = blocks.vector_source_c(range(10000), False, 1, [])
        separator = inspector_test.signal_separator_c(32000, firdes.WIN_HAMMING, 0.1, 100, False, inspector_test.map_float_vector({0.0:[0.0]}))
        vec_sink = blocks.vector_sink_c(1)
        ext = inspector_test.signal_extractor_c(0)
        snk = blocks.vector_sink_c(1)
        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12500)
        pmt.f32vector_set(flanks, 1, 20)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)

        taps = filter.firdes.low_pass(1, 32000, 500, 50, firdes.WIN_HAMMING, 6.76)

        self.tb.connect(src, separator)
        self.tb.connect(src, vec_sink)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))
        self.tb.msg_connect((separator, 'sig_out'), (ext, 'sig_in'))
        self.tb.connect(ext, snk)

        self.tb.start()
        time.sleep(0.3)
        self.tb.stop()
        self.tb.wait()

        data = vec_sink.data()

        sig = numpy.zeros(len(vec_sink.data()), dtype=complex)
        for i in range(len(vec_sink.data())):
            sig[i] = data[i]*numpy.exp(-1j*2*numpy.pi*12500*i*1/32000)

        taps = filter.firdes.low_pass(1, 32000, 900, 90, firdes.WIN_HAMMING, 6.76)
        sig = numpy.convolve(sig, taps, 'full')
        out = numpy.empty([0])
        decim = 32000/20/100
        j = 0
        for i in range(len(sig)/decim):
            out = numpy.append(out, sig[j])
            j += decim

        data = snk.data()
        for i in range(min(len(out), len(data))):
            self.assertComplexAlmostEqual2(out[i], data[i], abs_eps=0.01)
Exemplo n.º 5
0
    def test_001_t (self):
        # set up fg
        src = blocks.vector_source_c(range(1024), False, 1, [])
        # pack message
        msg = pmt.make_vector(1, pmt.PMT_NIL)
        flanks = pmt.make_f32vector(2, 0.0)
        pmt.f32vector_set(flanks, 0, 12500)
        pmt.f32vector_set(flanks, 1, 8)
        pmt.vector_set(msg, 0, flanks)

        msg_src = blocks.message_strobe(msg, 100)


        separator = inspector_test.signal_separator_c(1024, firdes.WIN_HAMMING, 0.1, 1)
        extractor = inspector.signal_extractor_c(0)

        taps = firdes.low_pass(1, 1024, 2, 0.1*2, firdes.WIN_HAMMING, 6.76)
        reference = numpy.convolve(range(1024), taps, 'same')
        #xlator = filter.freq_xlating_fir_filter_ccf(160, taps, 12500, 32000)
        stv1 = blocks.stream_to_vector(gr.sizeof_gr_complex, 128)
        #stv2 = blocks.stream_to_vector(gr.sizeof_gr_complex, 128)
        snk1 = blocks.vector_sink_c(128)
        #snk2 = blocks.vector_sink_c(128)
        null1 = blocks.null_sink(gr.sizeof_gr_complex)
        # connect this
        self.tb.connect(src, separator)
        self.tb.msg_connect((msg_src, 'strobe'), (separator, 'map_in'))
        #self.tb.connect(src, xlator)
        #self.tb.connect(xlator, null1)
        self.tb.msg_connect((separator, 'msg_out'), (extractor, 'sig_in'))
        self.tb.connect(extractor, stv1)
        #self.tb.connect(xlator, stv2)
        self.tb.connect(stv1, snk1)
        #self.tb.connect(stv2, snk2)

        self.tb.start()
        time.sleep(0.5)
        self.tb.stop()
        # check data
        data1 = snk1.data()
        #data2 = snk2.data()
        data2 = reference[0::8]

        for i in range(min(len(data2), len(data1))):
            self.assertComplexAlmostEqual(data1[i], data2[i], 4)
    def general_work(self, input_items, output_items):
        in0 = input_items[0]

        # Singular value decomposition of matrix "X"
        [u, _, _] = np.linalg.svd(in0.T)
        us = u[:, 0:self.n]

        # Eigenvalue classification
        #       s = abs(s)
        #       snr_aval = 10 * np.log10((s[0] - s[-1]) / (self.m * s[-1]))
        #       data = np.zeros((self.m, 3))

        #        with open(
        #            "/mnt/d/Users/grigo/Google Drive/Facultad/Balseiro/PI Lucas/git-repository/digital-beamforming/machine_learning/"
        #            + self.file_name,
        #            "a",
        #        ) as fd:
        #            for i in range(self.m):
        #                if i < self.n:
        #                    fd.write(str(s[i]) + ", " + str(snr_aval) + ", 1\n")
        #                else:
        #                    fd.write(str(s[i]) + ", " + str(snr_aval) + ", 0\n")

        for i in range(self.n):
            us_aux = us[:, i].reshape(self.mx, self.my)
            self.u1_x[:, i] = us_aux[0:self.mx - 1, :].reshape(
                (self.mx - 1) * self.my)
            self.u2_x[:, i] = us_aux[1:self.mx, :].reshape(
                (self.mx - 1) * self.my)
            self.u1_y[:, i] = us_aux[:, 0:self.my - 1].reshape(
                (self.my - 1) * self.mx)
            self.u2_y[:, i] = us_aux[:, 1:self.my].reshape(
                (self.my - 1) * self.mx)

        [_, _, vv_x] = np.linalg.svd(np.append(self.u1_x, self.u2_x, axis=1))
        vv_x = vv_x.T

        vv12_x = vv_x[0:self.n, self.n:2 * self.n]
        vv22_x = vv_x[self.n:2 * self.n, self.n:2 * self.n]

        # Calculate the engenvalues of Psi
        psi_x = -vv12_x @ np.linalg.inv(vv22_x)
        [phi_x, _] = np.linalg.eig(psi_x)

        [_, _, vv_y] = np.linalg.svd(np.append(self.u1_y, self.u2_y, axis=1),
                                     full_matrices=False)
        vv_y = vv_y.T

        vv12_y = vv_y[0:self.n, self.n:2 * self.n]
        vv22_y = vv_y[self.n:2 * self.n, self.n:2 * self.n]

        # Calculate the engenvalues of Psi
        psi_y = -vv12_y @ np.linalg.inv(vv22_y)
        [phi_y, _] = np.linalg.eig(psi_y)

        for i in range(self.n):
            arg = (np.angle(phi_x[i])**2 + np.angle(phi_y[i])**2) / (
                (self.k * self.d)**2)
            # if abs(arg) > 1:
            # print("DoA Esprit: Arg in arccos greater than 1 for i=%.2lf" % i)
            # CAMBIAR ESTO Y HACER QUE IF < 1
            # if i == (self.n - 1):
            #    self.consume(0, self.spd)
            #    return 0
            # else:
            # DOA estimation
            if abs(arg) <= 1:
                self.phi = np.arctan2(np.angle(phi_y[i]), np.angle(phi_x[i]))
                self.theta = np.arccos(np.sqrt(arg))
                doa = pmt.make_f32vector(3, 0.0)
                # print("doa=(", theta, ",", phi, ")")
                pmt.f32vector_set(doa, 0, float(self.theta))
                # print("doa_msg=", doa)
                pmt.f32vector_set(doa, 1, float(self.phi))
                pmt.f32vector_set(doa, 2, float(i))
                doa_msg = pmt.cons(pmt.to_pmt("doa_msg"), doa)
                self.message_port_pub(pmt.intern("doa_port"), doa_msg)
        self.consume(0, self.spd)
        return 0
from pmt.pmt_swig import serialize
import zmq
import numpy as np

# %%
_PROTOCOL = "tcp://"
_SERVER = "127.0.0.1"
_PORT = ":5558"
_ADDR = _PROTOCOL + _SERVER + _PORT
# %%
context = zmq.Context()
sock = context.socket(zmq.REP)
rc = sock.bind(_ADDR)
#%%
flanks = pmt.make_f32vector(2, 0.0)
pmt.f32vector_set(flanks, 0, np.radians(15))
pmt.f32vector_set(flanks, 1, np.radians(70))
c = pmt.cons(pmt.to_pmt("doa"), flanks)
#%%
sock.recv()
#%%
sock.send(pmt.serialize_str(c))
# %% De acá para arriba anda
key0 = pmt.intern("doa")
val0 = pmt.from_long(123)
val1 = pmt.from_long(234)
val_list = pmt.list2(val0, val1)
pmt.length(val_list)
# %%
a = pmt.make_dict()
# %%
Exemplo n.º 8
0
    def SNR_in(self,msg):
		# Envia mensaje:
		SNRv=pmt.to_double(msg)

		self.d_SNR=np.float64(SNRv)		
		self.d_grx=np.float64(self.Rxgain)



		# evidencia
		xp1 = self.d_SNR
		xp2 = self.d_FER
		xp3 = 10*np.log10(self.d_pot/ 46);
		xp4 = self.d_grx

		# fusificacion
		u11=1./(1+pl.exp(dp1[0]*(xp1-mp1[0])))
		u12=pl.exp((-0.5*(xp1-mp1[1])**2)/((dp1[1])**2))
		u13=1./(1+pl.exp(dp1[2]*(mp1[2]-xp1)))
		# funciones de pertenencia entrada FER
		u21=1./(1+pl.exp(dp2[0]*(xp2-mp2[0])))
		u22=pl.exp((-0.5*(xp2-mp2[1])**2)/((dp2[1])**2))
		u23=1./(1+pl.exp(dp2[2]*(mp2[2]-xp2)))

		# funciones de pertenencia entrada Potencia
		u31=1./(1+pl.exp(dp3[0]*(xp3-mp3[0])))
		u32=pl.exp((-0.5*(xp3-mp3[1])**2)/((dp3[1])**2))
		u33=1./(1+pl.exp(dp3[2]*(mp3[2]-xp3)))

		# funciones de pertenencia entrada GRx
		u41=1./(1+pl.exp(dp4[0]*(xp4-mp4[0])))
		u42=pl.exp((-0.5*(xp4-mp4[1])**2)/((dp4[1])**2))
		u43=1./(1+pl.exp(dp4[2]*(mp4[2]-xp4)))

		# funciones de pertenencia salida
		# Le pega el universo

		uC1=1./(1+pl.exp(dpy[0]*(y-mpy[0])))
		uC2=pl.exp((-0.5*(y-mpy[1])**2)/((dpy[1])**2))
		uC3=pl.exp((-0.5*(y-mpy[2])**2)/((dpy[2])**2))
		uC4=pl.exp((-0.5*(y-mpy[3])**2)/((dpy[3])**2))
		uC5=1./(1+pl.exp(dpy[4]*(mpy[4]-y)))

		# C?lculo de los antecedentes de las reglas (x1 es Ai Y x2 es Bj) T-Norma m?nimo

		A1=[u11, u31]#1X1X
		Ar1 = min (A1)
		A2= [u11, u21, u32]#112X
		Ar2 = min (A2)
		A3= [u21, u33, u41]#X131
		Ar3 = min (A3)
		A4= [u21, u33, u42]#X132
		Ar4 = min (A4)
		A5= [u21, u33, u43]#X133
		Ar5 = min (A5)
		A6= [u11, u22, u32]#122X
		Ar6 = min (A6)
		A7 =[u11, u22, u33]#123X
		Ar7 = min (A7)
		A8 =[u11, u23, u32]#132X
		Ar8 = min (A8)
		A9 =[u11, u23, u33]#133X
		Ar9 = min (A9)
		A10 =[u12, u21, u31, u41]#2111
		Ar10 = min (A10)
		A11 =[u12,u21,u31,u43]#2113 #CAMBIAR REGLA from 2112
		Ar11 = min (A11)
		A12 =[u12,u21,u33,u42]#2133
		Ar12 = min (A12)
		A13 =[u12,u22,u31,u41]#2211
		Ar13 = min (A13)
		A14 =[u12,u22,u31,u42]#2212
		Ar14 = min (A14)
		A15 =[u12,u22,u32]#222X
		Ar15 = min (A15)
		A16 =[u12,u22,u33,u41]#2231
		Ar16 = min (A16)
		A17 =[u12,u22,u33,u42]#2232
		Ar17= min (A17)
		A18 =[u12,u22,u33,u43]#2233
		Ar18= min (A18)
		A19 =[u12,u23,u31]#231X
		Ar19= min (A19)
		A20 =[u12,u23,u32]#232X
		Ar20= min (A20)
		A21 =[u12,u23,u33]#233X
		Ar21 = min (A21)
		A22 =[u13,u21,u31]#311X
		Ar22 = min (A22)
		A23 =[u13,u21,u41]#31X1
		Ar23 = min (A23)
		A24 =[u13,u21,u42]#31X2
		Ar24 = min (A24)
		A25 =[u13,u21,u43]#31X3
		Ar25 = min (A25)
		A26 =[u13,u22,u41]#32X1
		Ar26 = min (A26)
		A27 =[u13,u22,u42]#32X2
		Ar27 = min (A27)
		A28 =[u13,u22,u43]#32X3
		Ar28 = min (A28)
		A29 =[u13,u23,u41]#33X1
		Ar29 = min (A29)
		A30 =[u13,u23,u33]#333X
		Ar30 = min (A30)

		# C?lculo de la implicaci?n Mamdani para todas las reglas
		for i in range(296):
			r1 = min (Ar1,uC1[i])
			r2 = min (Ar2,uC2[i])
			r3 = min (Ar3,uC3[i])
			r4 = min (Ar4,uC4[i])
			r5 = min (Ar5,uC5[i])
			r6 = min (Ar6,uC3[i])
			r7 = min (Ar7,uC3[i])
			r8 = min (Ar8,uC2[i])
			r9 = min (Ar9,uC3[i])
			r10= min (Ar10,uC3[i])
			r11= min (Ar11,uC4[i])
			r12= min (Ar12,uC4[i])
			r13= min (Ar13,uC2[i])
			r14= min (Ar14,uC2[i])
			r15= min (Ar15,uC3[i])
			r16= min (Ar16,uC3[i])
			r17= min (Ar17,uC3[i])
			r18= min (Ar18,uC4[i])
			r19= min (Ar19,uC1[i])
			r20= min (Ar20,uC2[i])
			r21= min (Ar21,uC3[i])
			r22= min (Ar22,uC3[i])
			r23= min (Ar23,uC3[i])
			r24= min (Ar24,uC4[i])
			r25= min (Ar25,uC5[i])
			r26= min (Ar26,uC3[i])
			r27= min (Ar27,uC4[i])
			r28= min (Ar28,uC5[i])
			r29= min (Ar29,uC3[i])
			r30= min (Ar30,uC3[i])
			f0[i]=max(r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30)
			aux[i]=y[i]*f0[i]
		# Defusificacion centroide discreto.
		aux2=sum(aux)/sum(f0)
		self.threshold = float(aux2)
		send_pmt = pmt.make_f32vector(5, ord(' '))  	# Crea PMT vacio
		pmt.f32vector_set(send_pmt, 0, float(xp1))
		pmt.f32vector_set(send_pmt, 1, float(xp2))
		pmt.f32vector_set(send_pmt, 2, float(xp3))
		pmt.f32vector_set(send_pmt, 3, float(xp4))
		pmt.f32vector_set(send_pmt, 4, float(self.threshold))
		# Envia mensaje:
		self.message_port_pub(pmt.intern('threshold out'), pmt.cons(pmt.PMT_NIL, send_pmt))