import commlib as cl import numpy as np N = 1024 TS = 1e-9 T = 20 * TS sa2 = 1.0 t = cl.time_axis(T, N) p = cl.square(t, TS) f = cl.frequency_axis(t) P = cl.spectrum(t, p) SX = sa2 / TS * np.abs(P)**2.0 cl.plot_signal(f / 1e9, SX, close_all=True, xlabel='f [GHz]', ylabel='SX') cl.plot_signal(f * TS, SX / np.max(SX), xlabel='f * TS', ylabel='SX [normalized]', xlim=[-1, 1], show_grid=True) SX1 = cl.window(f, SX, -1 / TS, +1 / TS) total = np.trapz(SX, f) total1 = np.trapz(SX1, f) print('power fraction :', total1 / total)
import commlib as cl import numpy as np TS = 1e-3 # Symbol duration # symbols ak = np.array([0.5, 0.25, 1.0, 0.5]) t, x = cl.pam_waveform2(ak, TS) cl.plot_signal(t, x, plot_type='-o', close_all=True)
import commlib as cl import matplotlib.pyplot as plt T = 10 T1 = 1 N = 1000 t = cl.time_axis(-T, T, N) x = cl.square(t, T1) f = cl.frequency_axis(t) X = cl.spectrum(t, x) plt.close('all') cl.plot_signal(t, x, xlabel='t', ylabel='x', figure_no=1) cl.plot_signal(f, X, xlabel='f', ylabel='X', figure_no=2) Et = cl.energy(t, x) Ef = cl.energy(f, X) print('Energy in the time domain :', Et) print('Energy in the frequency domain :', Ef)