def do_gen(content, decision): SER_S = np.empty((tau_range.shape[0], phi_range.shape[0])) SER_U = np.empty((tau_range.shape[0], phi_range.shape[0])) for tau_idx, tau in enumerate(tau_range): print("tau = %.2f" % (tau)) # symbols of (synch"ed, unsynch"ed) sender if content in ("same",): tmp_syms = np.random.randint(16, size=nsyms + 2) send_syms = [tmp_syms, tmp_syms] else: send_syms = np.random.randint(16, size=2 * (nsyms + 2)).reshape(2, nsyms + 2) send_syms_s, send_syms_u = send_syms[0][1:-1], send_syms[1][1:-1] send_chips = pt.map_chips(*send_syms) RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx in range(len(phi_range)): recv_chips = np.empty(2 * RECV_CHIPS_I.shape[0]) recv_chips[::2] = RECV_CHIPS_I[:, phi_idx] recv_chips[1::2] = RECV_CHIPS_Q[:, phi_idx] # slice bits to simulate hard decision decoder if decision in ("hard",): recv_chips = np.sign(recv_chips) recv_syms = pt.detect_syms_corr(recv_chips)[1:-1] SER_S[tau_idx, phi_idx] = sum(recv_syms != send_syms_s) / (1.0 * len(recv_syms)) SER_U[tau_idx, phi_idx] = sum(recv_syms != send_syms_u) / (1.0 * len(recv_syms)) np.savez_compressed("data/ser_Au%.2f_%s_%s_v2.npz" % (Au, content, decision), SER_S=SER_S, SER_U=SER_U, **settings)
def do_gen(content, decision): SER_S, SER_U = None, None for tau in tau_range: print 'tau = %.2f' % (tau) ser_s, ser_u = np.array([]), np.array([]) # symbols of (synch'ed, unsynch'ed) sender if content in ('same', ): tmp_syms = np.random.randint(16, size=nsyms + 2) send_syms = [tmp_syms, tmp_syms] else: send_syms = np.random.randint(16, size=2 * (nsyms + 2)).reshape( 2, nsyms + 2) send_syms_s, send_syms_u = send_syms[0][1:-1], send_syms[1][1:-1] send_chips = pt.map_chips(*send_syms) RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for i in xrange(len(phi_range)): recv_chips = np.ravel(zip(RECV_CHIPS_I[:, i], RECV_CHIPS_Q[:, i])) # slice bits to simulate hard decision decoder if decision in ('hard', ): recv_chips = np.sign(recv_chips) recv_syms = pt.detect_syms_corr(recv_chips)[1:-1] ser_s = np.append( ser_s, sum(recv_syms != send_syms_s) / (1.0 * len(recv_syms))) ser_u = np.append( ser_u, sum(recv_syms != send_syms_u) / (1.0 * len(recv_syms))) if SER_S is None: SER_S = ser_s SER_U = ser_u else: SER_S = np.vstack((SER_S, ser_s)) SER_U = np.vstack((SER_U, ser_u)) np.savez_compressed('data/ser_Au%.2f_%s_%s_v2.npz' % (Au, content, decision), tau_range=tau_range, phi_range=phi_range, As=As, Au=Au, SER_S=SER_S, SER_U=SER_U, nsyms=nsyms, nsteps=nsteps)
def do_gen(content): start_time = time.time() BER_U = np.zeros((tau_range.shape[0], phi_range.shape[0])) BER_S = np.zeros((tau_range.shape[0], phi_range.shape[0])) for tau_idx in range(len(tau_range)): tau = tau_range[tau_idx] print("Step time for tau = %.3f: %.3fs" % (tau, time.time() - start_time)) start_time = time.time() if content in ("same", ): send_chips = np.array( [2 * np.random.randint(2, size=2 * nbits) - 1]).reshape( (2, nbits)) send_chips = np.vstack((send_chips, send_chips)) else: send_chips = np.array( [2 * np.random.randint(2, size=4 * nbits) - 1]).reshape( (4, nbits)) RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx in range(len(phi_range)): recv_chips = np.empty(2 * RECV_CHIPS_I.shape[0]) recv_chips[::2] = np.sign(RECV_CHIPS_I[:, phi_idx]) recv_chips[1::2] = np.sign(RECV_CHIPS_Q[:, phi_idx]) sync_chips = np.empty(2 * send_chips.shape[1]) sync_chips[::2] = send_chips[0] sync_chips[1::2] = send_chips[1] usync_chips = np.empty(2 * send_chips.shape[1]) usync_chips[::2] = send_chips[2] usync_chips[1::2] = send_chips[3] # ignore chips that are only partially affected here (the outermost two chips) BER_U[tau_idx, phi_idx] = np.sum(recv_chips[2:-2] != usync_chips[2:-2]) / ( 1.0 * len(recv_chips[2:-2])) BER_S[tau_idx, phi_idx] = np.sum(recv_chips[2:-2] != sync_chips[2:-2]) / ( 1.0 * len(recv_chips[2:-2])) np.savez_compressed("data/ber_Au%.2f_%s.npz" % (Au, content), BER_S=BER_S, BER_U=BER_U, **settings)
def do_gen(part, content, wide, numthreads): start_time = time.time() tau_range = (tau_range_wide if wide else tau_range_g) Au_range = (Au_range_wide if wide else Au_range_g) tau_range = np.split(tau_range, numthreads)[part] PRR_S = np.zeros((tau_range.shape[0], Au_range.shape[0])) PRR_U = np.zeros((tau_range.shape[0], Au_range.shape[0])) for tau_idx, tau in enumerate(tau_range): if content in ('same',): send_chips = np.array([2*np.random.randint(2, size=2*nbits)-1]).reshape((2, nbits)) send_chips = np.vstack((send_chips, send_chips)) else: send_chips = np.array([2*np.random.randint(2, size=4*nbits)-1]).reshape((4, nbits)) for Au_idx, Au in enumerate(Au_range): ber_u_phi = np.zeros(phi_range.shape[0]) ber_s_phi = np.zeros(phi_range.shape[0]) print('%s: tau=%7.3f, tau_step=(%3i/%3i), Au=%7.3f, Au_step=(%3i/%3i), runtime: %5.2f secs' %\ (sys.argv[0], tau, tau_idx+1, tau_range.shape[0], Au, Au_idx+1, Au_range.shape[0], time.time() - start_time)) start_time = time.time() RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx, phi in enumerate(phi_range): recv_chips = np.zeros(2*RECV_CHIPS_I.shape[0]) recv_chips[::2] = np.sign(RECV_CHIPS_I[:,phi_idx]) recv_chips[1::2] = np.sign(RECV_CHIPS_Q[:,phi_idx]) usync_chips = np.zeros(2*send_chips.shape[1]) usync_chips[::2] = send_chips[2] usync_chips[1::2] = send_chips[3] sync_chips = np.zeros(2*send_chips.shape[1]) sync_chips[::2] = send_chips[0] sync_chips[1::2] = send_chips[1] # ignore chips that are only partially affected here ber_s_phi[phi_idx] = np.sum(recv_chips[2:-2] != sync_chips[2:-2]) / (1.0*len(recv_chips[2:-2])) ber_u_phi[phi_idx] = np.sum(recv_chips[2:-2] != usync_chips[2:-2]) / (1.0*len(recv_chips[2:-2])) PRR_S[tau_idx, Au_idx] = np.mean((1-ber_s_phi)**pktlen) PRR_U[tau_idx, Au_idx] = np.mean((1-ber_u_phi)**pktlen) np.savez_compressed('data/prr_AsAu_%s%s_part%i.npz'%(content, wide, part), PRR_S=PRR_S, PRR_U=PRR_U, tau_range=tau_range, As=As, Au_range=Au_range, phi_range=phi_range, pktlen=pktlen, nsteps=nsteps, nbits=nbits)
def do_gen(content, decision): SER_S = np.empty((tau_range.shape[0], phi_range.shape[0])) SER_U = np.empty((tau_range.shape[0], phi_range.shape[0])) for tau_idx, tau in enumerate(tau_range): print("tau = %.2f" % (tau)) # symbols of (synch"ed, unsynch"ed) sender if content in ("same", ): tmp_syms = np.random.randint(16, size=nsyms + 2) send_syms = [tmp_syms, tmp_syms] else: send_syms = np.random.randint(16, size=2 * (nsyms + 2)).reshape( 2, nsyms + 2) send_syms_s, send_syms_u = send_syms[0][1:-1], send_syms[1][1:-1] send_chips = pt.map_chips(*send_syms) RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx in range(len(phi_range)): recv_chips = np.empty(2 * RECV_CHIPS_I.shape[0]) recv_chips[::2] = RECV_CHIPS_I[:, phi_idx] recv_chips[1::2] = RECV_CHIPS_Q[:, phi_idx] # slice bits to simulate hard decision decoder if decision in ("hard", ): recv_chips = np.sign(recv_chips) recv_syms = pt.detect_syms_corr(recv_chips)[1:-1] SER_S[tau_idx, phi_idx] = sum(recv_syms != send_syms_s) / (1.0 * len(recv_syms)) SER_U[tau_idx, phi_idx] = sum(recv_syms != send_syms_u) / (1.0 * len(recv_syms)) np.savez_compressed("data/ser_Au%.2f_%s_%s_v2.npz" % (Au, content, decision), SER_S=SER_S, SER_U=SER_U, **settings)
def do_gen(content): start_time = time.time() BER_U = np.zeros((tau_range.shape[0], phi_range.shape[0])) BER_S = np.zeros((tau_range.shape[0], phi_range.shape[0])) for tau_idx in range(len(tau_range)): tau = tau_range[tau_idx] print("Step time for tau = %.3f: %.3fs"% (tau, time.time() - start_time)) start_time = time.time() if content in ("same", ): send_chips = np.array([2*np.random.randint(2, size=2*nbits)-1]).reshape((2, nbits)) send_chips = np.vstack((send_chips, send_chips)) else: send_chips = np.array([2*np.random.randint(2, size=4*nbits)-1]).reshape((4, nbits)) RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx in range(len(phi_range)): recv_chips = np.empty(2*RECV_CHIPS_I.shape[0]) recv_chips[ ::2] = np.sign(RECV_CHIPS_I[:,phi_idx]) recv_chips[1::2] = np.sign(RECV_CHIPS_Q[:,phi_idx]) sync_chips = np.empty(2*send_chips.shape[1]) sync_chips[ ::2] = send_chips[0] sync_chips[1::2] = send_chips[1] usync_chips = np.empty(2*send_chips.shape[1]) usync_chips[ ::2] = send_chips[2] usync_chips[1::2] = send_chips[3] # ignore chips that are only partially affected here (the outermost two chips) BER_U[tau_idx, phi_idx] = np.sum(recv_chips[2:-2] != usync_chips[2:-2]) / (1.0*len(recv_chips[2:-2])) BER_S[tau_idx, phi_idx] = np.sum(recv_chips[2:-2] != sync_chips[2:-2]) / (1.0*len(recv_chips[2:-2])) np.savez_compressed("data/ber_Au%.2f_%s.npz"%(Au, content), BER_S=BER_S, BER_U=BER_U, **settings)
def do_gen(part, content, decision, wide, numthreads): tau_range = (tau_range_wide if wide else tau_range_norm) Au_range = (Au_range_wide if wide else Au_range_norm) Au_range_dB = (Au_range_wide_dB if wide else Au_range_norm_dB) start_time = time.time() tau_range = np.split(tau_range, numthreads)[part] PRR_S = np.zeros((tau_range.shape[0], Au_range.shape[0])) PRR_U = np.zeros((tau_range.shape[0], Au_range.shape[0])) SER_S_PHI = np.zeros((tau_range.shape[0], phi_range.shape[0])) SER_U_PHI = np.zeros((tau_range.shape[0], phi_range.shape[0])) for tau_idx, tau in enumerate(tau_range): # symbols of (synch'ed, unsynch'ed) sender if content in ('same', ): tmp_syms = np.random.randint(16, size=nsyms + 2) send_syms = np.vstack((tmp_syms, tmp_syms)) else: send_syms = np.random.randint(16, size=2 * (nsyms + 2)).reshape( 2, nsyms + 2) send_syms_s, send_syms_u = send_syms[0][1:-1], send_syms[1][1:-1] send_chips = pt.map_chips(*send_syms) #RECV_CHIPS_I_A = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au_range) #RECV_CHIPS_Q_A = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au_range) for Au_idx, Au in enumerate(Au_range): print('%s: tau=%7.3f, tau_step=(%3i/%3i), Au=%7.3f, Au_step=(%3i/%3i), runtime: %5.2f secs' %\ (sys.argv[0], tau, tau_idx+1, tau_range.shape[0], Au, Au_idx+1, Au_range.shape[0], time.time() - start_time)) start_time = time.time() RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx, phi in enumerate(phi_range): # Interleave the I and Q phase (this is faster than np.ravel) recv_chips = np.zeros(2 * RECV_CHIPS_I.shape[0]) recv_chips[::2] = RECV_CHIPS_I[:, phi_idx] recv_chips[1::2] = RECV_CHIPS_Q[:, phi_idx] if decision in ('hard', ): recv_chips = np.sign(recv_chips) recv_syms = pt.detect_syms_corr(recv_chips)[1:-1] SER_S_PHI[tau_idx, phi_idx] = np.sum( recv_syms != send_syms_s) / (1.0 * len(recv_syms)) SER_U_PHI[tau_idx, phi_idx] = np.sum( recv_syms != send_syms_u) / (1.0 * len(recv_syms)) PRR_S[tau_idx, Au_idx] = np.mean( (1.0 - SER_S_PHI[tau_idx, :])**pktlen) PRR_U[tau_idx, Au_idx] = np.mean( (1.0 - SER_U_PHI[tau_idx, :])**pktlen) np.savez_compressed('data/prr_AsAu_%s_%s%s_part%i.npz' % (content, decision, wide, part), PRR_S=PRR_S, PRR_U=PRR_U, SER_S_PHI=SER_S_PHI, SER_U_PHI=SER_U_PHI, tau_range=tau_range, nsteps=nsteps, nsyms=nsyms, As=As, Au_range=Au_range, phi_range=phi_range, Au_range_dB=Au_range_dB)
def do_gen(part, content, decision, wide, numthreads): if wide == "_uwide": tau_range = tau_range_uwide Au_range = Au_range_uwide elif wide == "_wide": tau_range = tau_range_wide Au_range = Au_range_wide else: tau_range = tau_range_norm Au_range = Au_range_norm start_time = time.time() tau_range = np.split(tau_range, numthreads)[part] PRR_S = np.zeros((tau_range.shape[0], Au_range.shape[0])) PRR_U = np.zeros((tau_range.shape[0], Au_range.shape[0])) SER_S_PHI = np.zeros((tau_range.shape[0], phi_range.shape[0])) SER_U_PHI = np.zeros((tau_range.shape[0], phi_range.shape[0])) for tau_idx, tau in enumerate(tau_range): # symbols of (synch"ed, unsynch"ed) sender if content in ("same",): tmp_syms= np.random.randint(16, size=nsyms+2) send_syms = np.vstack((tmp_syms, tmp_syms)) else: send_syms = np.random.randint(16, size=2*(nsyms+2)).reshape(2, nsyms+2) send_syms_s, send_syms_u = send_syms[0][1:-1], send_syms[1][1:-1] send_chips = pt.map_chips(*send_syms) #RECV_CHIPS_I_A = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au_range) #RECV_CHIPS_Q_A = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au_range) for Au_idx, Au in enumerate(Au_range): print("%s: tau=%7.3f, tau_step=(%3i/%3i), Au=%7.3f, Au_step=(%3i/%3i), runtime: %5.2f secs" %\ (sys.argv[0], tau, tau_idx+1, tau_range.shape[0], Au, Au_idx+1, Au_range.shape[0], time.time() - start_time)) start_time = time.time() RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx, phi in enumerate(phi_range): # Interleave the I and Q phase (this is faster than np.ravel) recv_chips = np.zeros(2*RECV_CHIPS_I.shape[0]) recv_chips[ ::2] = RECV_CHIPS_I[:,phi_idx] recv_chips[1::2] = RECV_CHIPS_Q[:,phi_idx] if decision in ("hard",): recv_chips = np.sign(recv_chips) recv_syms = pt.detect_syms_corr(recv_chips)[1:-1] SER_S_PHI[tau_idx, phi_idx] = np.sum(recv_syms != send_syms_s) / (1.0*len(recv_syms)) SER_U_PHI[tau_idx, phi_idx] = np.sum(recv_syms != send_syms_u) / (1.0*len(recv_syms)) PRR_S[tau_idx, Au_idx] = np.mean((1.0-SER_S_PHI[tau_idx,:])**pktlen) PRR_U[tau_idx, Au_idx] = np.mean((1.0-SER_U_PHI[tau_idx,:])**pktlen) np.savez_compressed("data/prr_AsAu_%s_%s%s_part%i.npz"%(content, decision, wide, part), PRR_S=PRR_S, PRR_U=PRR_U, **settings)
def do_gen(part, content, wide, numthreads): start_time = time.time() tau_range = (tau_range_wide if wide else tau_range_g) Au_range = (Au_range_wide if wide else Au_range_g) tau_range = np.split(tau_range, numthreads)[part] PRR_S = np.zeros((tau_range.shape[0], Au_range.shape[0])) PRR_U = np.zeros((tau_range.shape[0], Au_range.shape[0])) for tau_idx, tau in enumerate(tau_range): if content in ('same', ): send_chips = np.array( [2 * np.random.randint(2, size=2 * nbits) - 1]).reshape( (2, nbits)) send_chips = np.vstack((send_chips, send_chips)) else: send_chips = np.array( [2 * np.random.randint(2, size=4 * nbits) - 1]).reshape( (4, nbits)) for Au_idx, Au in enumerate(Au_range): ber_u_phi = np.zeros(phi_range.shape[0]) ber_s_phi = np.zeros(phi_range.shape[0]) print('%s: tau=%7.3f, tau_step=(%3i/%3i), Au=%7.3f, Au_step=(%3i/%3i), runtime: %5.2f secs' %\ (sys.argv[0], tau, tau_idx+1, tau_range.shape[0], Au, Au_idx+1, Au_range.shape[0], time.time() - start_time)) start_time = time.time() RECV_CHIPS_I = pt.detect_i(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) RECV_CHIPS_Q = pt.detect_q(send_chips[:2], send_chips[2:], phi_range, tau, As, Au) for phi_idx, phi in enumerate(phi_range): recv_chips = np.zeros(2 * RECV_CHIPS_I.shape[0]) recv_chips[::2] = np.sign(RECV_CHIPS_I[:, phi_idx]) recv_chips[1::2] = np.sign(RECV_CHIPS_Q[:, phi_idx]) usync_chips = np.zeros(2 * send_chips.shape[1]) usync_chips[::2] = send_chips[2] usync_chips[1::2] = send_chips[3] sync_chips = np.zeros(2 * send_chips.shape[1]) sync_chips[::2] = send_chips[0] sync_chips[1::2] = send_chips[1] # ignore chips that are only partially affected here ber_s_phi[phi_idx] = np.sum( recv_chips[2:-2] != sync_chips[2:-2]) / ( 1.0 * len(recv_chips[2:-2])) ber_u_phi[phi_idx] = np.sum( recv_chips[2:-2] != usync_chips[2:-2]) / ( 1.0 * len(recv_chips[2:-2])) PRR_S[tau_idx, Au_idx] = np.mean((1 - ber_s_phi)**pktlen) PRR_U[tau_idx, Au_idx] = np.mean((1 - ber_u_phi)**pktlen) np.savez_compressed('data/prr_AsAu_%s%s_part%i.npz' % (content, wide, part), PRR_S=PRR_S, PRR_U=PRR_U, tau_range=tau_range, As=As, Au_range=Au_range, phi_range=phi_range, pktlen=pktlen, nsteps=nsteps, nbits=nbits)