Esempio n. 1
0
def test_equalisation_prec(dtype, method, benchmark, backend):
    benchmark.group = "equalisation " + method
    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)
    if backend == "pth":
        method = method + "_pth"
    wxy, err = benchmark(
        equalisation.equalise_signal,
        SS,
        mu,
        Ntaps=ntaps,
        method=method,
        adaptive_stepsize=True,
    )
Esempio n. 2
0
 def testquantize(self, dt):
     s = signals.SignalQAMGrayCoded(32, 2**10, dtype=dt)
     s2 = impairments.change_snr(s, 30)
     sn = s2.make_decision()
     assert np.dtype(dt) is sn.dtype
     assert np.dtype(dt) is sn.symbols.dtype
     assert np.dtype(dt) is s.coded_symbols.dtype
Esempio n. 3
0
 def test_dual_mode_64qam(self):
     sig = signals.SignalQAMGrayCoded(64, 10**5, nmodes=2)
     sig = impairments.change_snr(sig, 30)
     sig = sig.resample(sig.fb*2, beta=0.1)
     E, wx, e = equalisation.dual_mode_equalisation(sig, (1e-3, 1e-3), 19, adaptive_stepsize=(True, True))
     ser = np.mean(E.cal_ser())
     assert ser < 1e-5
Esempio n. 4
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)
Esempio n. 5
0
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
Esempio n. 6
0
 def test_recovery_with_pmd(self, theta, dgd):
     snr = 30.
     ntaps = 41
     sig = signals.SignalWithPilots(64,
                                    2**16,
                                    1024,
                                    32,
                                    nframes=3,
                                    nmodes=2,
                                    fb=24e9)
     sig2 = sig.resample(2 * sig.fb, beta=0.1, renormalise=True)
     sig3 = impairments.change_snr(sig2, snr)
     sig3 = impairments.apply_PMD(sig3, theta * np.pi, dgd)
     sig4 = sig3[:, 20000:]
     sig4.sync2frame(corr_coarse_foe=False)
     s1, s2 = equalisation.pilot_equaliser(sig4, [5e-3, 5e-3],
                                           ntaps,
                                           True,
                                           adaptive_stepsize=True,
                                           foe_comp=False)
     ph = phaserec.find_pilot_const_phase(
         s2.extract_pilots()[:, :s2._pilot_seq_len], s2.pilot_seq)
     s2 = phaserec.correct_pilot_const_phase(s2, ph)
     ser = s2.cal_ser(synced=False)
     snr_m = s2.est_snr(synced=False)
     snr_db = 10 * np.log10(np.mean(snr_m))
     assert np.mean(ser) < 1e-4
Esempio n. 7
0
 def test_vstheory_ber(self, M, snr, synced):
     s = signals.SignalQAMGrayCoded(M, 2 ** 16)
     off = {4: 6, 16: 13, 64: 18, 128: 20}
     ss = impairments.change_snr(s, snr+off[M])
     ber = ss.cal_ber(synced=synced)
     ber_t = theory.ber_vs_es_over_n0_qam(10**((snr+off[M])/10), M)
     npt.assert_allclose(ber, ber_t, rtol=0.15)
Esempio n. 8
0
 def test_vstheory_evm(self, M, snr, synced):
     s = signals.SignalQAMGrayCoded(M, 2 ** 16)
     off = {4: 6, 16: 13, 64: 18, 128: 20}
     snr = snr+off[M]
     ss = impairments.change_snr(s, snr)
     evm = helpers.lin2dB(ss.cal_evm(synced=synced)**2)
     npt.assert_allclose(snr, -evm, rtol=0.01)
Esempio n. 9
0
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
Esempio n. 10
0
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)
Esempio n. 11
0
def test_apply_filter_benchmark(dtype, method, benchmark):
    benchmark.group = "apply filter " + str(dtype)
    fb = 40.e9
    os = 2
    fs = os * fb
    N = 2**17
    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)
    SS = 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 = benchmark(equalisation.apply_filter, SS, wxy, method)
    E1 = helpers.normalise_and_center(E1)
    ser = E1.cal_ser()
    npt.assert_allclose(0, ser, atol=3e-5)
Esempio n. 12
0
 def test_sync_reorder_modes(self, Nmodes, M):
     sig = signals.SignalQAMGrayCoded(M, 2**16, nmodes=Nmodes)
     sig = impairments.change_snr(sig, M + 10)
     idx = np.arange(Nmodes)
     np.random.shuffle(idx)
     s2 = sig[idx, :]
     ser = s2.cal_ser()
     npt.assert_array_almost_equal(ser, 0)
Esempio n. 13
0
 def test_real_valued_single_mode(self, method):
     s = signals.SignalQAMGrayCoded(4, 10**5, nmodes=1, fb=25e9)
     s2 = s.resample(s.fb*2, beta=0.1)
     s2 = impairments.sim_mod_response(s*0.2, dcbias=1.1)
     s3 = helpers.normalise_and_center(s2)
     s4 = impairments.change_snr(s3, 15)
     s5, wx, err = equalisation.equalise_signal(s4, 1e-3, Ntaps=17, method=method, adaptive_stepsize=True, apply=True)
     assert s5.cal_ser() < 1e5
 def test_sync_frame(self, ntaps, shift):
     s = signals.SignalWithPilots(128, 2**16, 1024, 32, nframes=3)
     s = s.resample(2*s.fs, beta=0.1)
     s = impairments.change_snr(s, 30)
     s = np.roll(s, shift, axis=-1)
     s.sync2frame(Ntaps=ntaps, adaptive_stepsize=True, mu=1e-2, method="cma", Niter=10)
     shf = shift-ntaps//2
     npt.assert_equal(s.shiftfctrs[0], shf - shf%2)
Esempio n. 15
0
 def test_nmodes(self, nmodes, snr_nmodes, fast):
     snr = 12.
     s = signals.SignalQAMGrayCoded(4, 10**3, nmodes=nmodes)
     s2 = impairments.change_snr(s, snr)
     if snr_nmodes:
         mi = s2.cal_mi(snr=np.ones(nmodes) * snr, fast=fast)
     else:
         mi = s2.cal_mi(snr=snr, fast=fast)
     assert mi.size == nmodes
Esempio n. 16
0
 def test_vstheory_ber(self, M, snr, os):
     s = signals.SignalQAMGrayCoded(M, 2 ** 16)
     off = {4: 6, 16: 13, 64: 18, 128: 20}
     s = s.resample(os, beta=0.1, renormalise=True)
     ss = impairments.change_snr(s, snr+off[M])
     ss = ss.resample(1, beta=0.1, renormalise=True)
     ber = ss.cal_ber()
     ber_t = theory.ber_vs_es_over_n0_qam(10**((snr+off[M])/10), M)
     npt.assert_allclose(ber, ber_t, rtol=0.18)
Esempio n. 17
0
 def test_vstheory_evm(self, M, snr, os):
     s = signals.SignalQAMGrayCoded(M, 2 ** 16)
     off = {4: 6, 16: 13, 64: 18, 128: 20}
     snr = snr+off[M]
     s = s.resample(os, beta=0.1, renormalise=True)
     ss = impairments.change_snr(s, snr)
     ss = ss.resample(1, beta=0.1, renormalise=True)
     evm = helpers.lin2dB(ss.cal_evm() ** 2)
     npt.assert_allclose(snr, -evm, rtol=0.1)
Esempio n. 18
0
 def test_verbose_ber_syms(self, M):
     s = signals.SignalQAMGrayCoded(M, 2**12)
     snr = 30
     s = impairments.change_snr(s, snr)
     d = abs(np.unique(np.diff(s.coded_symbols.real)))
     dmin = d[np.where(d>0)].min()
     s2 = _flip_symbols(s, [100], dmin)
     ser, errs, syms = s2.cal_ber(synced=True, verbose=True)
     assert syms.shape == s2.bits.shape
 def test_sync_frame_equalise(self, ntaps, shift):
     s = signals.SignalWithPilots(128, 2**16, 512, 32, nframes=3, nmodes=1)
     s = s.resample(2*s.fs, beta=0.1)
     s = impairments.change_snr(s, 40)
     s = np.roll(s, shift, axis=-1)
     wx1, ret = s.sync2frame(Ntaps=ntaps, returntaps=True, adaptive_stepsize=True, mu=1e-2, method="cma", Niter=10)
     ss = np.roll(s, -s.shiftfctrs[0], axis=-1)
     so = core.equalisation.apply_filter(ss, ss.os, wx1)
     npt.assert_array_equal(np.sign(so[0,:512].imag), np.sign(s.pilot_seq[0].imag))
     npt.assert_array_equal(np.sign(so[0,:512].real), np.sign(s.pilot_seq[0].real))
Esempio n. 20
0
 def test_verbose_ser(self, M):
     s = signals.SignalQAMGrayCoded(M, 2**12)
     snr = 30
     s = impairments.change_snr(s, snr)
     d = abs(np.unique(np.diff(s.coded_symbols.real)))
     dmin = d[np.where(d>0)].min()
     s2 = _flip_symbols(s, [100], dmin)
     ser, errs, syms = s2.cal_ser(synced=True, verbose=True)
     assert errs[0,100] != 0
     assert np.count_nonzero(errs) == 1
Esempio n. 21
0
 def test_nframes_calculation(self, nmodes, method, frames):
     ss = signals.SignalWithPilots(64,
                                   2**16,
                                   1024,
                                   32,
                                   nframes=3,
                                   nmodes=nmodes)
     s2 = impairments.change_snr(ss, 20)
     m = getattr(s2, method)(frames=frames)
     print(m)
Esempio n. 22
0
 def test_selected_modes(self, modes, sigmodes):
     sig = signals.SignalQAMGrayCoded(4, 2**15, nmodes=sigmodes)
     sig = impairments.change_snr(sig, 15)
     sig = sig.resample(sig.fb*2, beta=0.1)
     E, wx, e = cequalisation.equalise_signal(sig, sig.os, 1e-3, sig.M, Ntaps=10, modes=modes, apply=True)
     if modes is None:
         modes = np.arange(sigmodes)
     E = sig.recreate_from_np_array(E)
     ser = np.mean(E.cal_ser())
     assert ser < 1e-5
Esempio n. 23
0
 def test_vs_gmi(self, snr, fast, with_snr):
     s = signals.SignalQAMGrayCoded(4, 10**3, nmodes=1)
     s2 = impairments.change_snr(s, snr)
     if with_snr:
         mi = s2.cal_mi(snr=snr, fast=fast)
         gmi = s2.cal_gmi(snr=snr)[0]
     else:
         mi = s2.cal_mi(fast=fast)
         gmi = s2.cal_gmi()[0]
     npt.assert_allclose(gmi, mi, rtol=0.05)
Esempio n. 24
0
 def test_ser_vs_theory(self, shift, M, snr):
     from qampy import theory, impairments
     s = signals.SignalQAMGrayCoded(M, 10**5, nmodes=1)
     ser_t = theory.ser_vs_es_over_n0_qam(10**(snr / 10), M)
     if ser_t < 1e-4:
         assert True
         return
     s2 = impairments.change_snr(s, snr)
     s2 = np.roll(s2, shift, axis=-1)
     ser = s2.cal_ser()
     npt.assert_allclose(ser, ser_t, rtol=0.4)
Esempio n. 25
0
 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
Esempio n. 26
0
 def test_swap_pols(self):
     snr = 30.
     sig = signals.SignalWithPilots(64, 2**16, 1024, 32, nframes=3, nmodes=2, fb=24e9)
     sig2 = sig.resample(2*sig.fb, beta=0.1, renormalise=True)
     sig2 = impairments.change_snr(sig2, snr)
     sig3 = sig2[::-1]
     sig4 = sig3[:, 20000:]
     sig4.sync2frame(corr_coarse_foe=False)
     s1, s2 = equalisation.pilot_equalizer(sig4, [1e-3, 1e-3], 17, True, adaptive_stepsize=True, foe_comp=False)
     ph = phaserec.find_pilot_const_phase(s2.extract_pilots()[:,:s2._pilot_seq_len], s2.pilot_seq)
     s2 = phaserec.correct_pilot_const_phase(s2, ph)
     ser = s2.cal_ser(synced=True)
     assert np.mean(ser) < 1e-4
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)
Esempio n. 28
0
 def test_symbols(self, sigmodes, symbolsmodes):
     selected_modes = np.arange(sigmodes)
     sig = signals.SignalQAMGrayCoded(4, 2**15, nmodes=sigmodes)
     sig = impairments.change_snr(sig, 15)
     sig = sig.resample(sig.fb*2, beta=0.1)
     if symbolsmodes is not None:
         symbols = sig.coded_symbols
         if symbolsmodes > 0:
             symbols = np.tile(symbols, (symbolsmodes, 1))
     else:
         symbols = None
     E, wx, e  = cequalisation.equalise_signal(sig, sig.os, 1e-3, sig.M, Ntaps=10, symbols=None, apply=True,
                                               modes=selected_modes)
     E = sig.recreate_from_np_array(E)
     ser = np.mean(E.cal_ser())
     assert ser < 1e-5
Esempio n. 29
0
 def test_cal_gmi_frames(self, frame):
     M = 64
     sig = signals.SignalWithPilots(M,
                                    10**4 + 1000,
                                    1000,
                                    0,
                                    nframes=3,
                                    nmodes=1)
     sig2 = impairments.change_snr(sig[:, :sig.frame_len], 25)
     sig[0, frame * sig.frame_len:(frame + 1) * sig.frame_len] = sig2[:]
     for i in range(3):
         gmi = sig.cal_gmi(frames=[i])[0]
         if i == frame:
             assert np.isclose(gmi, sig2.cal_gmi()[0])
         else:
             assert np.isclose(gmi, np.log2(M))
Esempio n. 30
0
 def test_est_snr_frames(self, frame):
     M = 64
     snr_in = 25.
     sig = signals.SignalWithPilots(M,
                                    10**4 + 1000,
                                    1000,
                                    0,
                                    nframes=3,
                                    nmodes=1)
     sig2 = impairments.change_snr(sig[:, :sig.frame_len], snr_in)
     sig[0, frame * sig.frame_len:(frame + 1) * sig.frame_len] = sig2[:]
     for i in range(3):
         snr = sig.est_snr(frames=[i])
         if i == frame:
             assert np.isclose(snr, 10**(snr_in / 10), rtol=0.03)
         else:
             assert np.all(snr > 10e15)