def test_apply_filter(dtype, benchmark): fb = 40.e9 os = 2 fs = os * fb N = 10**5 mu = 4e-4 theta = np.pi / 5.45 theta2 = np.pi / 4 t_pmd = 75e-12 M = 4 ntaps = 40 snr = 14 sig = signals.SignalQAMGrayCoded(M, N, fb=fb, nmodes=2, dtype=dtype) S = sig.resample(fs, renormalise=True, beta=0.1) S = impairments.change_snr(S, snr) SS = impairments.apply_PMD(S, theta, t_pmd) wxy, err = equalisation.equalise_signal(SS, mu, Ntaps=ntaps, method="mcma", adaptive_step=True) E1 = equalisation.apply_filter(SS, wxy, method="pyx") E2 = equalisation.apply_filter(SS, wxy, method="py") E2 = E1.recreate_from_np_array(E2) E1 = helpers.normalise_and_center(E1) E2 = helpers.normalise_and_center(E2) E1, ph = phaserec.viterbiviterbi(E1, 11) E2, ph = phaserec.viterbiviterbi(E2, 11) E1 = helpers.dump_edges(E1, 20) E2 = helpers.dump_edges(E2, 20) ser1 = E1.cal_ser().mean() ser2 = E2.cal_ser().mean() npt.assert_allclose(0, ser1, atol=3e-5) npt.assert_allclose(0, ser2, atol=3e-5)
def test_pmd_2(self, method, dgd): phi = 6.5 theta = np.pi / phi fb = 40.e9 os = 2 fs = os * fb N = 2**16 snr = 15 beta = 0.1 mu = 0.9e-3 M = 4 ntaps = 7 s = signals.SignalQAMGrayCoded(M, N, nmodes=2, fb=fb) s = s.resample(fs, beta=beta, renormalise=True) s = impairments.apply_PMD(s, theta, dgd) wxy, err = equalisation.equalise_signal(s, mu, Ntaps=ntaps, method=method, adaptive_stepsize=True, avoid_cma_sing=True) sout = equalisation.apply_filter(s, wxy) sout = helpers.normalise_and_center(sout) ser = sout.cal_ser() npt.assert_allclose(ser, 0)
def test_equalisation_prec(dtype, benchmark): fb = 40.e9 os = 2 fs = os * fb N = 10**5 #mu = np.float32(4e-4) mu = 4e-4 theta = np.pi / 5.45 theta2 = np.pi / 4 t_pmd = 75e-12 M = 4 ntaps = 40 snr = 14 sig = signals.SignalQAMGrayCoded(M, N, fb=fb, nmodes=2, dtype=dtype) S = sig.resample(fs, renormalise=True, beta=0.1) S = impairments.apply_phase_noise(S, 100e3) S = impairments.change_snr(S, snr) SS = impairments.apply_PMD(S, theta, t_pmd) wxy, err = benchmark(equalisation.equalise_signal, SS, mu, Ntaps=ntaps, method="mcma", adaptive_stepsize=True) E = equalisation.apply_filter(SS, wxy) E = helpers.normalise_and_center(E) E, ph = phaserec.viterbiviterbi(E, 11) E = helpers.dump_edges(E, 20) ser = E.cal_ser().mean() npt.assert_allclose(0, ser, atol=3e-5)
def test_pmd_phase_fails(self, method, phi, dgd, lw): theta = np.pi / phi fb = 40.e9 os = 2 fs = os * fb N = 2**16 snr = 15 beta = 0.3 mu = 2e-4 M = 4 ntaps = 15 s = signals.SignalQAMGrayCoded(M, N, nmodes=2, fb=fb) s = s.resample(fs, beta=beta, renormalise=True) s = impairments.apply_phase_noise(s, lw) s = impairments.apply_PMD(s, theta, dgd) wxy, err = equalisation.equalise_signal(s, mu, Ntaps=ntaps, method=method, adaptive_stepsize=False) sout = equalisation.apply_filter(s, wxy) sout, ph = phaserec.viterbiviterbi(sout, 11) sout = helpers.normalise_and_center(sout) sout = helpers.dump_edges(sout, 20) ser = sout.cal_ser() npt.assert_allclose(ser, 0)
def test_method(self, dtype, method): fb = 40.e9 os = 2 fs = os * fb N = 2**13 beta = 0.1 mu = 0.2e-2 M = 16 taps = 13 s = signals.SignalQAMGrayCoded(M, N, nmodes=2, fb=fb, dtype=dtype) s = s.resample(fs, beta=beta, renormalise=True) #s = impairments.change_snr(s, 20) #wxy, err = equalisation.equalise_signal(s, mu, Ntaps=taps, method=method, adaptive_stepsize=True) wxy, err = equalisation.equalise_signal(s, mu, Niter=3, Ntaps=taps, method=method, adaptive_stepsize=True) sout = equalisation.apply_filter(s, wxy) ser = sout.cal_ser() #plt.plot(sout[0].real, sout[0].imag, 'r.') #plt.plot(sout[1].real, sout[1].imag, 'b.') #plt.show() npt.assert_allclose(ser, 0, atol=3. / N) assert np.dtype(dtype) is sout.dtype
def test_pol_rot(self, method, phi): phi = np.pi / phi fb = 40.e9 os = 2 fs = os * fb N = 2**16 beta = 0.1 mu = 0.1e-2 M = 4 ntaps = 5 s = signals.SignalQAMGrayCoded(M, N, nmodes=2, fb=fb) s = s.resample(fs, beta=beta, renormalise=True) s = impairments.rotate_field(s, phi) wxy, err = equalisation.equalise_signal(s, mu, Niter=3, Ntaps=ntaps, method=method, adaptive_stepsize=True, avoid_cma_sing=False) sout = equalisation.apply_filter(s, wxy) #plt.plot(sout[0].real, sout[0].imag, '.r') #plt.show() ser = sout.cal_ser() #if ser.mean() > 0.5: #ser = sout[::-1].cal_ser npt.assert_allclose(ser, 0)
def equalize_synchronize_signal(resampled_sig, mu=None, ntaps=None, method=None, adaptive_step=None, avoid_cma_sing=None): #Equalize and synchronize the signal and calculate the bit error rate if mu is None: mu = 2e-3 if ntaps is None: ntaps = 21 if method is None: method = "cma" if adaptive_step is None: adaptive_step = True if avoid_cma_sing is None: avoid_cma_sing = False wxy, err = equalisation.equalise_signal(resampled_sig, mu, Ntaps=ntaps, method=method, adaptive_step=adaptive_step, avoid_cma_sing=avoid_cma_sing) E = equalisation.apply_filter(resampled_sig, wxy) E = helpers.normalise_and_center(E) ber, errs, tx_synced = E.cal_ber( E, verbose=True ) #Synchronize the signal with the data and calculates the bit error rate return E, ber, errs, tx_synced
def test_apply_filter_basic(self): s2 = impairments.simulate_transmission(self.s, self.s.fb, self.s.fs, snr=20, dgd=100e-12) wx, err = equalisation.equalise_signal(s2, 1e-3, Ntaps=11) s3 = equalisation.apply_filter(s2, wx) assert type(s3) is type(self.s)
def test_apply_filter_frames(self, frames, modal_delay): Ntaps = 45 s = signals.SignalWithPilots(64, 2**16, 1024, 32, nframes=4, nmodes=2, fb=24e9) s2 = s.resample(2 * s.fb, beta=0.1, renormalise=True) s3 = impairments.simulate_transmission( s2, 30, modal_delay=[2000, 2000 + modal_delay]) s3.sync2frame(Ntaps=Ntaps - 14 * 2) wx = equalisation.pilot_equaliser(s3, 1e-3, Ntaps, apply=False, foe_comp=False) sout = equalisation.apply_filter(s3, wx, frames=frames) assert sout.shape[-1] == s.frame_len * len(frames) for ber in sout.cal_ber(): assert ber < 1e-3
sig = impairments.apply_PMD(sig, np.pi / 5.6, pmd) sig = impairments.change_snr(sig, snr) sig = impairments.apply_phase_noise(sig, phase_noise) plot_constellation(sig[:, t_conv:t_stop], "Recieved", True, sigdir) filename = sigdir + "/_rep" + str(r) + ".txt" file = open(filename, 'wb') pickle.dump(sig, file) for mu_q in list_mu_q: for ntaps in list_ntaps: mimodir = create_dir_for_mimo_result( sigdir, mu_q, ntaps, "Qampy") taps_qampy, err = equalisation.equalise_signal( sig, mu_q, Ntaps=ntaps, method="cma") sig_qampy = equalisation.apply_filter(sig, taps_qampy) sig_qampy, ph = phaserec.viterbiviterbi(sig_qampy, 11) err_qampy = [] for i_mode in range(2): err_qampy.append( mlab.movavg(abs(err[i_mode]), movavg_taps)) try: ber_qampy = calculate_BER(sig_qampy, range(t_conv, t_stop)) except: ber_qampy = [1, 1] if produce_plots: title = "Qampy_mu" + str(mu_q) + "_taps" + str(ntaps) plot_constellation(sig_qampy[:, t_conv:t_stop],
snr = 5 sig = signals.SignalQAMGrayCoded(M, N, fb=fb, nmodes=2, dtype=np.complex128) S = sig.resample(fs, renormalise=True, beta=0.1) #S = impairments.apply_phase_noise(S, 100e3) S = impairments.change_snr(S, snr) SS = impairments.apply_PMD(S, theta2, t_pmd) wxy_m, err_m = equalisation.equalise_signal(SS, mu, TrSyms=None, Ntaps=ntaps, method="mcma", adaptive_step=True) E = equalisation.apply_filter(SS, wxy) E_m = equalisation.apply_filter(SS, wxy_m) E = helpers.normalise_and_center(E) E_m = helpers.normalise_and_center(E_m) #E, ph = phaserec.viterbiviterbi(E, 11) #E_m, ph = phaserec.viterbiviterbi(E_m, 11) E = helpers.dump_edges(E, 20) E_m = helpers.dump_edges(E_m, 20) # note that because of the noise we get sync failures doing SER #ser = E.cal_ser() #ser_m = E_m.cal_ser() #print(E.cal_gmi()) #print(E_m.cal_gmi()) sys.exit() ser0 = S[:, ::2].cal_ser()
hf = io.create_recvd_data_group(hf, oversampling_dflt=os) meas_table = hf.root.measurements.oscilloscope.signal inp_table = hf.root.input.signal ids = meas_table.cols.id[:] m_arrays = io.get_from_table(meas_table, ids, "data") syms = list(io.get_from_table(inp_table, ids, "symbols")) bits = list(io.get_from_table(inp_table, ids, "bits")) i = 0 for d_array in m_arrays: wx, er = equalisation.equalise_signal(d_array, os, M, Ntaps=ntaps, method=method[0], adaptive_step=astep) signalafter = equalisation.apply_filter(d_array, os, wx) evm_x = modulator.cal_EVM(signalafter[0], syms[ids[i]][0]) evm_y = modulator.cal_EVM(signalafter[1], syms[ids[i]][1]) ser_x, tmp, data_demod_x = modulator.calculate_SER( signalafter[0], symbol_tx=syms[ids[i]][0]) ser_y, tmp, data_demod_y = modulator.calculate_SER( signalafter[1], symbol_tx=syms[ids[i]][1]) ber_x = modulator.cal_BER(signalafter[0], bits[ids[i]][0])[0] ber_y = modulator.cal_BER(signalafter[1], bits[ids[i]][1])[0] io.save_recvd(hf, signalafter, ids[i], wx, symbols=np.vstack([data_demod_x, data_demod_y]), evm=(evm_x, evm_y), ber=(ber_x, ber_y),
snr, PRBSorder=(15, 23), baudrate=fb, samplingrate=fs) t_pmd = 75e-12 SS = impairments.apply_PMD_to_field(S, theta, t_pmd, fs) #pr.enable() wx, err = equalisation.equalise_signal(SS, os, M, Ntaps=ntaps, method="mcma", adaptive_stepsize=True) E = equalisation.apply_filter(SS, os, wx) #E, wx, wy, err = equalisation.FS_MCMA(SS, N-40, ntaps, os, mu, M) E = E[:, 1000:-1000] try: berx = QAM.cal_ber(E[0], bits_tx=bits[0]) except: berx = QAM.cal_ber(E[1], bits_tx=bits[0]) try: bery = QAM.cal_ber(E[1], bits_tx=bits[1]) except: bery = QAM.cal_ber(E[0], bits_tx=bits[1]) print("X BER %f dB" % (10 * np.log10(berx[0]))) print("Y BER %f dB" % (10 * np.log10(bery[0])))
movavg_taps = 1000 resample = False err_Rx = mlab.movavg(abs(calculate_radius_directed_error(sig[1], R2)), movavg_taps) plot_request_Rx = MimoPlotRequest(err_Rx, sig.copy()[1], np.zeros(lb * 2), "Recieved") ## Equalisation taps_QAMPY, err = equalisation.equalise_signal(sig, mu_Qampy, Ntaps=61, method="cma") sig_QAMPY = equalisation.apply_filter(sig, taps_QAMPY) sig_QAMPY, ph = phaserec.viterbiviterbi(sig_QAMPY, 11) if resample: settings = MIMOSettings(lb=lb, mu=mu_Martin, ovsmpl=2, R2=np.sqrt(R2)) sig_Martin, taps_Martin = fd_cma_mimo_Martin(sig.copy(), settings) else: settings = MIMOSettings(lb=lb, mu=mu_Martin, ovsmpl=1, R2=np.sqrt(R2)) sig_Martin, taps_Martin = fd_cma_mimo_Martin(sig.copy(), settings) sig_Martin, ph = phaserec.viterbiviterbi(sig_Martin, 11) err_Martin = calculate_radius_directed_error(sig_Martin[1][0:t_stop], np.sqrt(R2)) err_Martin = mlab.movavg(abs(err_Martin), movavg_taps)
E, wxy, err_both = equalisation.dual_mode_equalisation(SS, os, M, ntaps, Niter=(5, 5), methods=("mcma", "sbd"), adaptive_stepsize=(True, True)) X = signal_quality.norm_to_s0(E[0, :], M) Y = signal_quality.norm_to_s0(E[1, :], M) E = np.vstack([X,Y]) foe = phaserecovery.find_freq_offset(E, fft_size =2 ** 10) E = phaserecovery.comp_freq_offset(E, foe) #Ec = E[:,2e4:-2e4] wx, err_both = equalisation.equalise_signal(E, 1, M, Ntaps=ntaps, Niter=4, method="sbd", adaptive_stepsize=False) Ec = equalisation.apply_filter(E, 1, wx) E = Ec print("X pol phase") Ex, phx = phaserecovery.bps(E[0], 32, QAM.symbols, 8) print("X pol phase done") print("Y pol phase") Ey, phy = phaserecovery.bps(E[1], 32, QAM.symbols, 8) print("Y pol phase done") Ec = np.vstack([Ex,Ey]) evmX = QAM.cal_evm(X[::2]) evmY = QAM.cal_evm(Y[::2]) evmEx = QAM.cal_evm(E[0]) evmEy = QAM.cal_evm(E[1])
ber = np.zeros(snr.shape) evm1 = np.zeros(snr.shape) evm_known = np.zeros(snr.shape) i = 0 for sr in snr: print("SNR = %2f.0 dB" % sr) signal = signals.SignalQAMGrayCoded(M, N, nmodes=1, fb=fb) signal = signal.resample(fnew=fs, beta=beta, renormalise=True) signal_s = impairments.change_snr(signal, sr) #signalx = np.atleast_2d(filtering.rrcos_pulseshaping(signal_s, beta)) wx, er = equalisation.equalise_signal(signal_s, 3e-4, Ntaps=ntaps, method="mcma", adaptive_step=True) signalafter = equalisation.apply_filter(signal_s, wx) signalafter = helpers.normalise_and_center(signalafter) evm1[i] = signal.cal_evm()[0] evm_known[i] = signalafter.cal_evm() # check to see that we can recovery timing delay #signalafter = np.roll(signalafter * 1.j**np.random.randint(0,4), np.random.randint(4, 3000)) ser[i] = signalafter.cal_ser() ber[i] = signalafter.cal_ber() i += 1 ax1.plot(snrf, theory.ber_vs_es_over_n0_qam(10**(snrf / 10), M), color=c[j], label="%d-QAM theory" % M) ax1.plot(snr, ber, color=c[j], marker=s[j], lw=0, label="%d-QAM" % M) ax2.plot(snrf, theory.ser_vs_es_over_n0_qam(10**(snrf / 10), M),