示例#1
0
    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 <<<<<

N0 = Eb / (10**(EbNodB / 10))
An = pow(N0 * Fs / 2, 0.5)
rt = st + An * nt  # Noisy PAM signal

# ***** PAM signal receiver *****
dly = 0
bn, bt, ixn = pamfun.pamrcvr10(tt, rt, [FB, dly], ptype, pparms)
dnhat = array(zeros(len(bn)), int)
ix = where(bn > 0)[0]
dnhat[ix] = ones(len(ix))  # Received binary data, quantized

# ***** Compare dn, dnhat and compute Ps(E) *****

nerror = list(abs(dn - dnhat)).count(1)
PsE = nerror / len(dn)
示例#2
0
def askrcvr(tt, rt, rtype, fcparms, FBparms, ptype, pparms):
    """
    Amplitude Shift Keying (ASK) Receiver for
    Coherent ('coh') and Non-coherent ('noncoh') ASK Signals
    >>>>> bn,bt,wt,ixn = askrcvr(tt,rt,rtype,fcparms,FBparms,ptype,pparms) <<<<<
    where bn:received DT sequence b[n]
    bt:received 'CT' PAM signal b(t)
    wt = wit + 1j*wqt
    wit:in-phase component of b(t)
    wqt:quadrature component of b(t)
    ixn:sampling time indexes for b(t)->b[n], w(t)->w[n]
    tt:time axis for r(t)
    rt:received (noisy) ASK signal r(t)
    rtype:receiver type from list ['coh','noncoh']
    fcparms = [fc, thetac] for {'coh'}
    fcparms = [fc] for {'noncoh'}
    fc:carrier frequency in Hz
    thetac:carrier phase in deg (0: cos, -90: sin)
    FBparms = [FB, dly]
    FB:baud rate of PAM signal, TB=1/FB
    dly:sampling delay for b(t)->b[n], fraction of TB
    sampling times are t=n*TB+t0 where t0=dly*TB
    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'}
    """
    ptype = ptype.lower()
    rtype = rtype.lower()
    Fs = int(len(tt) / (tt[-1] - tt[0]))
    FBparms = FBparms
    pparms = pparms
    if rtype == 'coh':
        fc = fcparms[0]
        thetac = fcparms[1]
        rt = 2 * rt * cos(2 * pi * fc * tt + thetac)
        bn, bt, ixn = pamfun.pamrcvr10(tt, rt, FBparms, ptype, pparms)
        wt = bt
        bn[where(bn > 0.0001)] = 1
        bn[where(bn <= 0.0001)] = 0
    elif rtype == 'noncoh':
        an = anthcn[0]
        fc = fcparms
        thetacn = anthcn[1]
        vt = 2 * rt * exp(-1j * 2 * pi * fc * tt)
        bni, wit, ixni, = pamfun.pamrcvr10(tt, real(vt), FBparms, ptype,
                                           pparms)
        bnq, wqt, ixnq, = pamfun.pamrcvr10(tt, imag(vt), FBparms, ptype,
                                           pparms)
        bt = (wit**2 + wqt**2)**0.5
        N = ceil(FBparms[0] * (tt[-1] - tt[0]))
        ixn = array(around((arange(N) + 0.5 + FBparms[1]) * Fs / FBparms[0]),
                    int)
        bn = bt[ixn]
        bn[where(bn > 0.01)] = 1
        bn[where(bn <= 0.01)] = 0
        wt = wit + 1j * wqt
    else:
        print("xtype is incorrect")
    bn = array(bn, int8)
    return bn, bt, wt, ixn