Esempio n. 1
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. 2
0
 def test_coarse_freq_offset(self, fo, mode_offset):
     snr = 37
     ntaps = 19
     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)
     sig3 = impairments.simulate_transmission(sig2,
                                              snr,
                                              freq_off=fo,
                                              modal_delay=[0, mode_offset])
     sig4 = helpers.normalise_and_center(sig3)
     sig4 = sig4[:, 2000:]
     sig4.sync2frame(corr_coarse_foe=True)
     s1, s2 = equalisation.pilot_equaliser(sig4, [1e-3, 1e-3],
                                           ntaps,
                                           True,
                                           adaptive_stepsize=True,
                                           foe_comp=True)
     d, ph = phaserec.pilot_cpe(s2, nframes=1)
     assert np.mean(d.cal_ber()) < 1e-5
Esempio n. 3
0
 def test_pilot_based_nframe_ber(self, frames ):
     mysig = signals.SignalWithPilots(64,2**16,2**10,32,nmodes=2,Mpilots=4,nframes=4,fb=24e9)
     mysig2 = mysig.resample(mysig.fb*2,beta=0.1)
     mysig3 = impairments.simulate_transmission(mysig2,snr=25, modal_delay=(4000, 4000))
     mysig3.sync2frame()
     wxy, eq_sig,_ = equalisation.pilot_equaliser_nframes(mysig3, (1e-3, 1e-3), 45, foe_comp=False, frames=frames)
     assert np.all(eq_sig.cal_ber(frames=frames) < 5e-3)
Esempio n. 4
0
 def test_pilot_based_nframe_len(self, frames ):
     mysig = signals.SignalWithPilots(64,2**16,2**10,32,nmodes=2,Mpilots=4,nframes=4,fb=24e9)
     mysig2 = mysig.resample(mysig.fb*2,beta=0.01)
     mysig3 = impairments.simulate_transmission(mysig2,snr=25)
     mysig3.sync2frame()
     wxy, eq_sig,_ = equalisation.pilot_equaliser_nframes(mysig3, (1e-3, 1e-3), 45, foe_comp=False, frames=frames)
     assert eq_sig.shape[-1] == eq_sig.frame_len*len(frames)
 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. 6
0
 def test_est_snr_value(self, nframes):
     s = signals.SignalWithPilots(16,
                                  2**16,
                                  128,
                                  32,
                                  nmodes=1,
                                  nframes=nframes)
     snr = s.est_snr()
     assert snr[0] > 1e25
Esempio n. 7
0
 def test_evm_value(self, nframes):
     s = signals.SignalWithPilots(16,
                                  2**16,
                                  128,
                                  32,
                                  nmodes=1,
                                  nframes=nframes)
     evm = s.cal_evm()
     assert evm[0] < 1e-4
Esempio n. 8
0
 def test_ser_value(self, nframes):
     s = signals.SignalWithPilots(16,
                                  2**16,
                                  128,
                                  32,
                                  nmodes=1,
                                  nframes=nframes)
     ser = s.cal_ser()
     assert ser[0] == 0
Esempio n. 9
0
 def test_pilot_signal(self, dt, shift):
     s = signals.SignalWithPilots(32, 2**12, 256, 32, dtype=dt)
     if shift is not None:
         s1 = np.roll(s, 120, axis=-1)
         s3 = s1.get_data(np.array([shift]))
     else:
         s3 = s.get_data()
     assert np.dtype(dt) is s3.dtype
     assert np.dtype(dt) is s3.symbols.dtype
Esempio n. 10
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. 11
0
 def test_pilot_signal(self, dt, nframes):
     s = signals.SignalWithPilots(32,
                                  2**12,
                                  256,
                                  32,
                                  nframes=nframes,
                                  dtype=dt)
     assert np.dtype(dt) is s.dtype
     assert np.dtype(dt) is s.symbols.dtype
     assert np.dtype(dt) is s.pilots.dtype
 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. 13
0
 def test_ber_value(self, nframes):
     s = signals.SignalWithPilots(16,
                                  2**16,
                                  128,
                                  32,
                                  nmodes=1,
                                  nframes=nframes)
     s += 0.05 * (np.random.randn(2**16 * nframes) +
                  1.j * np.random.randn(2**16 * nframes))
     ber = s.cal_ber()
     assert ber[0] == 0
Esempio n. 14
0
 def test_framesync_noshift(self, snr):
     sig = signals.SignalWithPilots(64,
                                    2**16,
                                    1024,
                                    32,
                                    nframes=2,
                                    nmodes=2,
                                    fb=20e9)
     s2 = sig.resample(sig.fb * 2, beta=0.1)
     s3 = impairments.simulate_transmission(s2, snr)
     assert s3.sync2frame()
Esempio n. 15
0
 def test_pilot_based(self, rollframe, modal_delay, method):
     from qampy import phaserec
     mysig = signals.SignalWithPilots(64,2**16,2**10,32,nmodes=2,Mpilots=4,nframes=3,fb=24e9)
     mysig2 = mysig.resample(mysig.fb*2,beta=0.01)
     mysig3 = impairments.simulate_transmission(mysig2,snr=25,dgd=10e-12, freq_off=100e6,lwdth=100e3,roll_frame_sync=rollframe, modal_delay=modal_delay)
     mysig3.sync2frame()
     mysig3.corr_foe()
     wxy, eq_sig = equalisation.pilot_equaliser(mysig3, (1e-3, 1e-3), 45, foe_comp=False, methods=method)
     cpe_sig, ph = phaserec.pilot_cpe(eq_sig,N=5,use_seq=False)
     gmi = np.mean(cpe_sig.cal_gmi()[0])
     assert gmi > 5.5
Esempio n. 16
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. 17
0
 def test_realvalued_framesync(self, method):
     # currently we do not support real-valued equalisers for frame-sync
     sig = signals.SignalWithPilots(64,
                                    2**16,
                                    1024,
                                    32,
                                    nframes=2,
                                    nmodes=2,
                                    fb=20e9)
     s2 = sig.resample(sig.fb * 2, beta=0.1)
     with pytest.raises(ValueError):
         s2.sync2frame(method=method)
Esempio n. 18
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
Esempio n. 19
0
 def test_cal_gmi_value(self, M, nframes, dtype):
     s = signals.SignalWithPilots(M,
                                  2**16,
                                  128,
                                  32,
                                  nmodes=1,
                                  nframes=nframes,
                                  dtype=dtype)
     s += (0.0004 * (np.random.randn(2**16 * nframes) +
                     1.j * np.random.randn(2**16 * nframes))).astype(dtype)
     nbits = np.log2(M)
     gmi, gmi_pb = s.cal_gmi()
     npt.assert_almost_equal(gmi[0], nbits)
Esempio n. 20
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. 21
0
 def test_cal_ser_frames(self, frame):
     sig = signals.SignalWithPilots(64,
                                    10**4 + 1000,
                                    1000,
                                    0,
                                    nframes=3,
                                    nmodes=1)
     sig[0, 1010 + frame * sig.frame_len] *= 1j
     for i in range(3):
         ser = sig.cal_ser(frames=[i])
         if i == frame:
             assert np.isclose(ser, 1 / 10**4)
         else:
             assert np.isclose(ser, 0)
     ser = sig.cal_ser(frames=[0, 1, 2])
     assert np.isclose(ser, 1 / (3 * 10**4))
Esempio n. 22
0
 def test_get_data2(self, nmodes, nframes):
     N = 2**16
     Nseq = 256
     ph_i = 32
     s = signals.SignalWithPilots(64,
                                  N,
                                  Nseq,
                                  ph_i,
                                  nframes=nframes,
                                  nmodes=nmodes)
     shifts = []
     for i in range(nmodes):
         sf = np.random.randint(0, 2**12)
         shifts.append(sf)
         s[i] = np.roll(s[i], sf)
     npt.assert_array_almost_equal(s.get_data(shifts),
                                   np.tile(s.symbols, nframes))
Esempio n. 23
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)
Esempio n. 24
0
 def test_cal_evm_frames(self, frame):
     M = 64
     sig = signals.SignalWithPilots(M,
                                    10**4 + 1000,
                                    1000,
                                    0,
                                    nframes=3,
                                    nmodes=1)
     dd = np.diff(np.unique(sig.coded_symbols.real)).min()
     sig[0, 1010 + frame * sig.frame_len] += dd * 0.6
     for i in range(3):
         evm = sig.cal_evm(frames=[i])
         if i == frame:
             assert np.isclose(evm, 0.00185164)  # calculated before
         else:
             assert np.isclose(evm, 0)
     evm = sig.cal_evm(frames=[0, 1, 2])
     assert np.isclose(evm, 0.00106904)
Esempio n. 25
0
 def test_data_mix_realandcomplexmethods(self, method):
     # currently we do not support to mix real-valued and complex equaliser methods
     sig = signals.SignalWithPilots(64,
                                    2**16,
                                    1024,
                                    32,
                                    nframes=2,
                                    nmodes=2,
                                    fb=20e9)
     s2 = sig.resample(sig.fb * 2, beta=0.1)
     s3 = impairments.simulate_transmission(s2,
                                            25,
                                            modal_delay=[10000, 10000])
     s3.sync2frame()
     with pytest.raises(ValueError):
         equalisation.pilot_equaliser(s3, (1e-3, 1e-3),
                                      11,
                                      methods=(method, "sbd"))
Esempio n. 26
0
 def test_cal_ber_frames(self, frame):
     M = 64
     sig = signals.SignalWithPilots(M,
                                    10**4 + 1000,
                                    1000,
                                    0,
                                    nframes=3,
                                    nmodes=1)
     dd = np.diff(np.unique(sig.coded_symbols.real)).min()
     sig[0, 1010 + frame * sig.frame_len] += dd * 0.8
     for i in range(3):
         ber = sig.cal_ber(frames=[i])
         if i == frame:
             assert np.isclose(ber, 1 / (np.log2(M) * 10**4))
         else:
             assert np.isclose(ber, 0)
     ber = sig.cal_ber(frames=[0, 1, 2])
     assert np.isclose(ber, 1 / (3 * np.log2(M) * 10**4))
Esempio n. 27
0
 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
Esempio n. 28
0
 def test_pickle(self):
     import tempfile
     import pickle
     dr = tempfile.TemporaryDirectory()
     fp = open(dr.name + "/data.pic", "wb")
     s = signals.SignalWithPilots(128, 2**16, 256, 32)
     pickle.dump(s, fp)
     fp.close()
     fp2 = open(dr.name + "/data.pic", "rb")
     s2 = pickle.load(fp2)
     fp2.close()
     dr.cleanup()
     npt.assert_array_almost_equal(s, s2)
     npt.assert_array_almost_equal(s.symbols, s2.symbols)
     npt.assert_array_almost_equal(s.pilots, s2.pilots)
     npt.assert_array_almost_equal(s.coded_symbols, s2.coded_symbols)
     npt.assert_array_almost_equal(s.pilot_seq, s2.pilot_seq)
     npt.assert_array_almost_equal(s.ph_pilots, s2.ph_pilots)
     npt.assert_array_almost_equal(s.get_data(), s2.get_data())
     assert s.fb == s2.fb
     assert s.fs == s2.fs
     assert s.M == s2.M
     assert s.pilot_scale == s2.pilot_scale
     assert s.nframes == s2.nframes
Esempio n. 29
0
 def test_too_short_frame(self):
     with pytest.raises(AssertionError):
         ss = signals.SignalWithPilots(64, 2**16, 1024, 32, nframes=3)
         oo = np.copy(ss)
         out = ss.recreate_from_np_array(oo[:,:int(ss.frame_len/2)])
Esempio n. 30
0
 def test_recreate_nframes(self, nlen):
     ss = signals.SignalWithPilots(64, 2**16, 1024, 32, nframes=3)
     oo = np.copy(ss)
     oo1 = np.tile(oo, (1, int((nlen*ss.frame_len)//ss.frame_len)))
     oo2 = np.hstack([oo1, oo[:, :oo.shape[-1]*int(nlen%ss.frame_len)] ])
     out = ss.recreate_from_np_array(oo2)