def load_8QAM(N): SNR = 40 phase_noise = 0e3 ovsmpl = 2 nmodes = 2 #sequence,sig= load.load_harder_capture(N) #sequence = sequence[:nmodes,:N] #while sequence.shape[1] < N: # sequence = np.append(sequence,sequence,axis = 1) #sequence = sequence[:,:N] sig = signals.SignalQAMGrayCoded(4, N, fb=25e9, nmodes=nmodes) #sig[:,:] = sequence sequence = sig.copy() if ovsmpl > 1: sig = sig.resample(ovsmpl * sig.fb, beta=1) sig = impairments.change_snr(sig, SNR) sig = impairments.apply_phase_noise(sig, phase_noise) matrix = imp.build_mixing_matrix(nmodes, 0.2, 0.2) #sig = imp.apply_mltichnl_delayed_matrix_impairment(sig,0,matrix) return sequence, sig
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_select_angles_benchmark(dtype, method, benchmark, M): benchmark.group = "select_angle" from qampy.core.dsp_cython import bps if method == "pyx": from qampy.core.dsp_cython import select_angles elif method == "pyt": from qampy.core.pythran_dsp import select_angles fb = 40.e9 N = 2**17 NL = 40 sig = signals.SignalQAMGrayCoded(M, N, fb=fb, nmodes=1, dtype=dtype) sig = impairments.apply_phase_noise(sig, 40e3) if dtype is np.dtype(np.complex64): fdtype = np.float32 else: fdtype = np.float64 angles = np.linspace(-np.pi / 4, np.pi / 4, M, endpoint=False, dtype=fdtype).reshape(1, -1) idx = bps(sig[0], angles, sig.coded_symbols, NL) ph = np.array(benchmark(select_angles, angles, idx)).reshape(1, -1) ph[:, NL:-NL] = np.unwrap(ph[:, NL:-NL] * 4) / 4 sigo = sig * np.exp(1j * ph).astype(sig.dtype) sigo = helpers.dump_edges(sigo, 100) ser = sigo.cal_ser() npt.assert_allclose(0, ser, atol=3e-5)
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(self, method1, method2, lw): theta = np.pi / 4.5 dgd = 100e-12 fb = 40.e9 os = 2 fs = os * fb N = 2**16 snr = 15 beta = 0.9 mu1 = 2e-3 if method2 == "mddma": mu2 = 1.0e-3 else: mu2 = 2e-3 M = 32 ntaps = 21 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) sout, wxy, err = equalisation.dual_mode_equalisation( s, (mu1, mu2), Ntaps=ntaps, methods=(method1, method2), adaptive_stepsize=(True, True)) sout, ph = phaserec.bps(sout, M, 21) sout = helpers.normalise_and_center(sout) sout = helpers.dump_edges(sout, 50) ser = sout.cal_ser() if ser.mean() > 0.4: ser = sout[::-1].cal_ser() npt.assert_allclose(ser, 0, atol=1.01 * 3 / N) # Three wrong symbols is ok
def build_and_impair_signal(set, sigdir): nmodes = set['nmodes'] N = set['N'] t_conv = N - 50000 t_stop = N - 1000 sig = signals.SignalQAMGrayCoded(4, N, fb=25e9, nmodes=nmodes) sig_Martin = sig.copy() trainingSyms = sig.copy() ovsmpl = set['ovsmpl'] if ovsmpl > 1: sig = sig.resample(ovsmpl * sig.fb, beta=0.1, renormalise=True) if set['impulse_impaired']: sig = apply_impulse_response_impairment(sig) matrix = build_mixing_matrix(nmodes, set['mixing'], set['loss']) sig = apply_mltichnl_delayed_matrix_impairment(sig, set['delay'], matrix) if set['pmd'] > 0: for i_dmode in range(int(nmodes / 2)): sig[i_dmode * 2:i_dmode * 2 + 2] = impairments.apply_PMD( sig[i_dmode * 2:i_dmode * 2 + 2], np.pi / 5.6, set['pmd']) sig = impairments.change_snr(sig, set['snr']) sig = impairments.apply_phase_noise(sig, set['phase_noise']) plot_constellation(sig[:, t_conv:t_stop], "Recieved", True, sigdir) return sig, sig_Martin, trainingSyms
def test_cpe(self,lw): snr = 37 ntaps = 17 sig = signals.SignalWithPilots(64, 2**16, 1024, 32, nframes=3, nmodes=2, fb=24e9) sig2 = sig.resample(2*sig.fb, beta=0.01, renormalise=True) sig2 = impairments.apply_phase_noise(sig2, 100e3) sig3 = impairments.change_snr(sig2, snr) sig4 = sig3[:, 20000:] sig4.sync2frame(corr_coarse_foe=False) s1, s2 = equalisation.pilot_equalizer(sig4, [1e-3, 1e-3], ntaps, True, adaptive_stepsize=True, foe_comp=False) d, ph = phaserec.pilot_cpe(s2, nframes=1) assert np.mean(d.cal_ber()) < 1e-5
def test_phaserec_bps_2stage(lw, M): fb = 40.e9 os = 1 fs = os * fb N = 2**17 snr = 30 shiftN = np.random.randint(-N / 2, N / 2, 1) s = signals.SignalQAMGrayCoded(M, N, fb=fb) s = s.resample(fs, beta=0.1, renormalise=True) s = impairments.change_snr(s, snr) s = np.roll(s, shiftN, axis=1) pp = impairments.apply_phase_noise(s, lw) recoverd, ph1 = phaserec.bps_twostage(pp, max(4, M // 2), 14, method='pyt') recoverd = helpers.dump_edges(recoverd, 20) ser = recoverd.cal_ser() npt.assert_allclose(ser, 0)
def test_apply_phase_noise(self): s2 = impairments.apply_phase_noise(self.s, 1e-3) assert type(self.s) is type(s2)
def test_apply_phase_noise(self, dtype): s = signals.ResampledQAM(16, 2**14, fs=2, nmodes=2, dtype=dtype) s2 = impairments.apply_phase_noise(s, 1e-3) assert np.dtype(dtype) is s2.dtype
def test_apply_phase_noise_attr(self, attr): s2 = impairments.apply_phase_noise(self.s, 1e-3) assert getattr(self.s, attr) is getattr(s2, attr)
if ovsmpl > 1: sig = sig.resample(2 * sig.fb, beta=0.1, renormalise=True) if apply_impulse: sig = apply_impulse_response_impairment(sig) if apply_matrix: if delay_after_matrix: sig[:, :] = apply_2chnl_delayed_matrix_impairment( sig, 1e-9, 25e9) else: sig[:, :] = apply_2chnl_delayed_after_mix_matrix_impairment( sig, 1e-9, 25e9) 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)
fb = 40.e9 os = 1 fs = os*fb N = 3*10**5 M = 64 snr = 30 lw_LO = np.linspace(10e1, 1000e1, 4) #lw_LO = [100e3] sers = [] for lw in lw_LO: shiftN = np.random.randint(-N/2, N/2, 1) s = signals.SignalQAMGrayCoded(M, N, fb=fb) s = s.resample(fs, beta=0.1, renormaise=True) s = impairments.change_snr(s, snr) s = np.roll(s, shiftN, axis=1) pp = impairments.apply_phase_noise(s, lw) recoverd, ph1 = phaserec.bps_twostage(pp, 28, s.coded_symbols, 14, method='pyx') recoverd_2, ph2 = phaserec.bps(pp, 64, s.coded_symbols, 14, method='pyx') recoverd = helpers.dump_edges(recoverd, 20) recoverd_2 = helpers.dump_edges(recoverd_2, 20) ser = recoverd.cal_ser() ser2 = recoverd_2.cal_ser() print("1 stage pyx ser=%g"%ser) print("2 stage pyx ser=%g"%ser2)
import matplotlib.pylab as plt ntaps = 17 snr = 30 dgd = 100e-12 theta = 3.7 sig = signals.SignalWithPilots(64, 2**16, 1024, 32, nframes=3, nmodes=2, fb=24e9) #sig2 = impairments.change_snr(sig, snr) #sig3 = sig2.resample(2*sig2.fb, beta=0.01, renormalise=True) sig2 = sig.resample(2 * sig.fb, beta=0.01, renormalise=True) sig2 = impairments.apply_phase_noise(sig2, 100e3) sig3 = impairments.change_snr(sig2, snr) sig3 = core.impairments.rotate_field(sig3, np.pi / 0.1) #sig4 = sig3[::-1, 20000:] #sig4[0,:] = sig3[1,20000:] #sig4[1,:] = sig3[0,20000:] sig4 = sig3[:, 20000:] #sig4 = impairments.apply_PMD(sig4, theta, dgd) #sig4 = impairments.apply_PMD(sig4, theta, dgd) #sig4[0,:] = sig3[1, 20000:] #sig4[1,:] = sig3[0, 20000:] sig4.sync2frame(Ntaps=ntaps) wx, s1 = equalisation.pilot_equaliser(sig4, [1e-3, 1e-3], ntaps, True,
if PLOT_PICTURES: plot_constellation( sig, "Signal constellation after pulseshaping, AGWN\n and PMD," + r"$\theta=\pi/{:d}$, $\Delta\tau ={:d}ps$".format( int((THETA / np.pi)**-1), int(TDGD * 1e12)), "sig_agwn_pmd") plot_time( sig, "X-polarization over time after pulseshaping,\n AGWN and PMD," + r"$\theta=\pi/{:d}$, $\Delta\tau ={:d}ps$".format( int((THETA / np.pi)**-1), int(TDGD * 1e12)), "sig_agwn_pmd_time") if USE_PHASE_NOISE: sig = impairments.apply_phase_noise(sig, LINEWIDTH) if PLOT_PICTURES: plot_constellation( sig, "Signal constellation after pulseshaping, AGWN\n PMD and phase noise, linewidth of laser = {:d}MHz" .format(int(LINEWIDTH / 1e6)), "sig_agwn_pmd_phase") plot_time( sig, "Signal constellation after pulseshaping, AGWN\n PMD and phase noise, linewidth of laser = {:d}MHz" .format(int(LINEWIDTH / 1e6)), "sig_agwn_pmd_phase_time") if USE_FREQ_OFFSET: sig = impairments.add_carrier_offset(sig, FREQ_OFFSET) if PLOT_PICTURES: plot_constellation( sig,
fb = 40.e9 os = 2 fs = os * fb N = 4 * 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=np.complex64) 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 = equalisation.equalise_signal(SS, mu, Ntaps=ntaps, TrSyms=None, method="mcma", adaptive_step=True) wxy_m, err_m = equalisation.equalise_signal(SS, mu, TrSyms=None, Ntaps=ntaps, method="mcma", adaptive_step=True)