#import cProfile import numpy as np from qampy.core import io from qampy import signals import os as os_mod fb = 40. os = 2 fs = os*fb N = 3*10**5 M = 64 QAM = signals.QAMModulator(M) snrs = [10, 20, 30] #lw_LO = [100e3] hdfn1 ="/tmp/sav_meas_test_single_pol.h5" hdfn2 ="/tmp/sav_meas_test_dual_pol.h5" if os_mod.path.exists(hdfn1): os_mod.remove(hdfn1) #single pol h5_sp = io.create_h5_meas_file(hdfn1, "single polarisation test save") for snr in snrs: X, symbolsX, bitsX = QAM.generateSignal(N, snr, baudrate=fb, samplingrate=fs, PRBS=True) id_m = io.save_osc_meas(h5_sp, X, osnr=snr, wl=1550, samplingrate=fs, symbolrate=fb, MQAM=M) io.save_inputs(h5_sp, id_m, symbols=symbolsX) h5_sp.close() if os_mod.path.exists(hdfn2):
import numpy as np import matplotlib.pyplot as plt from qampy import signals """ Check the symbol rate of a QAM signal against the theoretical symbol rate""" M = 32 snr = np.arange(5, 25, 1) N = 10**5 ser = [] ser2 = [] modl = signals.QAMModulator(M) for sr in snr: data_rx, symbols, bits = modl.generate_signal(N, sr) ser.append(modl.cal_ser(data_rx, symbol_tx=symbols)) ser2.append(modl.cal_ser(data_rx, bits_tx=bits)) ser = 10 * np.log10(np.array(ser)) ser2 = 10 * np.log10(np.array(ser2)) theory_ser = 10 * np.log10(modl.theoretical_ser(10**(snr / 10))) assert np.allclose( ser, ser2 ), "SER calculated from symbol is different to ser calculated from bits" #assert np.allclose(ser, theory_ser, atol=1), "SER calculated from symbol is different to theoretical ser" plt.figure() plt.plot(snr, theory_ser, label='theory') plt.plot(snr, ser, 'or', label='calculation') plt.xlabel('SNR [dB]') plt.ylabel('SER [dB]') plt.legend() plt.show()