def askxmtr(anthcn, FB, Fs, ptype, pparms, xtype, fcparms): """ Amplitude Shift Keying (ASK) Transmitter for Choherent ('coh') and Non-coherent ('noncoh') ASK Signals >>>>> tt,xt,st = askxmtr(anthcn,FB,Fs,ptype,pparms,xtype,fcparms) <<<<< where tt:time axis for x(t), starts at t=-TB/2 xt:transmitted ASK signal, sampling rate Fs x(t) = s(t)*cos(2*pi*fc*t+(pi/180)*thetac) tt:time axis for x(t), starts at t=-TB/2 st:baseband PAM signal s(t) for 'coh' st = sit + 1j*sqt for 'noncoh' sit:PAM signal of an*cos(pi/180*thetacn) sqt:PAM signal of an*sin(pi/180*thetacn) xtype:Transmitter type from list {'coh','noncoh'} anthcn = [an] for {'coh'} anthcn = [[an],[thetacn]] for {'noncoh'} an:N-symbol DT input sequence a_n, 0<=n<N thetacn: N-symbol DT sequence theta_c[n] in degrees, used instead of thetac for {'noncoh'} ASK FB:baud rate of a_n (and theta_c[n]), TB=1/FB Fs:sampling rate of x(t), s(t) ptype:pulse type from list ['man','rcf','rect','rrcf','sinc','tri'] pparms = [] for {'man','rect','tri'} pparms = [k, alpha] for {'rcf','rrcf'} pparms = [k, beta] for {'sinc'} k:"tail" truncation parameter for {'rcf','rrcf','sinc'} (truncates at -k*TB and k*TB) alpha:Rolloff parameter for {'rcf','rrcf'}, 0<=alpha<=1 beta:Kaiser window parameter for {'sinc'} fcparms = [fc, thetac] for {'coh'} fcparms = [fc] for {'noncoh'} fc:carrier frequency in Hz thetac: carrier phase in deg (0: cos, -90: sin) """ xtype = xtype.lower() ptype = ptype.lower() if xtype == 'coh': an = anthcn fc = fcparms[0] tt, st = pamfun.pam12(an, FB, Fs, ptype, pparms=[]) st[where(st < 0)] = 0 thetac = fcparms[1] xt = st * cos(2 * pi * fc * tt + thetac) elif xtype == 'noncoh': an = anthcn[0] fc = fcparms thetacn = anthcn[1] tt, sit = pamfun.pam12(an * cos(thetacn), FB, Fs, ptype, pparms=[]) tt, sqt = pamfun.pam12(an * sin(thetacn), FB, Fs, ptype, pparms=[]) st = sit + 1j * sqt xt = real(st * exp(1j * 2 * pi * fc * tt)) else: print("xtype is incorrect") return tt, xt, st
Fs = 1000 # Sampling rate FB = 100 # Baud rate FB EbNodB = float(EbNodB[-1]) # Specified SNR Eb/No in dB N = 100000 # Number of symbols ptype, pparms = 'tri', [] # Pulse type/parameters an_set = [-1, +1] # Set of possible an values M = len(an_set) # Number of signal levels # ***** Compute Eb for given p(t) and signal constellation ***** Es_prime = 0 for i in an_set: tt, pt = pamfun.pam12(array([i]), FB, Fs, ptype, pparms) # PAM signal Es_prime += (cumsum(pt * pt) / Fs)[-1] Es = Es_prime / len(an_set) Eb = Es / log2(M) # ***** Generate PAM signal using random data ***** dn = array(floor(2 * rand(N)), int) # Random binary data signal an = 2 * dn - 1 # Polar binary sequence tt, st = pamfun.pam12(an, FB, Fs, ptype, pparms) # PAM signal # ***** Generate Gaussian noise signal ***** nt = randn(len(tt)) # Gaussian noise # >>>>> Compute An such that rt has desired SNR Eb/No <<<<<