Tuesday, November 26, 2019

Dss

## PN sequence generation with Max length
x0= 1
x1= 0
x2 =0
x3 =0
N = 7 
for i in range(1,N+1):
  x3 =x2
  x2 =x1
  x1 = x0
  x0 =(x1^x3)
  print ('The PN sequence at step:',i)
  x = [x1, x2, x3]
  print ('x=',x)
m = [7,8,9,10,11,12,13,17,19]#
N = [2**mm-1 for mm in m]
print ('Table 9.1 Range of PN Sequence lengths')
print ('_________________________________________________________')
print ('Length of shift register (m) =',m)
print ('PN sequence Length (N) =',N)
print ('_________________________________________________________')








##Properties of PNsequence
from numpy import corrcoef as corr
from matplotlib.pyplot import plot,xlabel,ylabel,title,show

#Period of PN Sequence N = 7
#Properites of maximum-length sequence

#Assign Initial value for PN generator
x0= 1
x1= 0
x2 =0
x3 =0
N = 7 
one_count = 0
zero_count = 0
C=[]
C_level=[]
t=[]
for i in range(1,N+1):
  x3 =x2#
  x2 =x1#
  x1 = x0#
  x0 =(x1^x3)
  print ('The PN sequence at step :',i)
  x = [x1 ,x2 ,x3]
  print ('x=',x)
  C.append(x3)
  if(C[i-1]==1):
    C_level.append(1)
    one_count = one_count+1
  elif(C[i-1]==0):
    C_level.append(-1)
    zero_count = zero_count+1  
print ('Output Sequence : ',C) 
print ('Output Sequence levels :',C_level)
if(zero_count < one_count):
  print ('Number of 1s in the given PN sequence : ',one_count)
  print ('Number of 0s in the given PN sequence :',zero_count)
  print ('Property 1 (Balance property) is satisified')
Rc_tuo = corr(C_level,rowvar=N)
t = range(1,2*len(C_level)+1)
plot(t,C_level+C_level)
xlabel('                                        t')
title('Waveform of maximum-length sequence ')
show()













## Generation of waveforms in DSSS/BPSK spread spectrum transmitter
from numpy import ones ,sin , arange , hstack ,nditer , pi 
import numpy as np
from matplotlib.pyplot import plot , subplot , xlabel , ylabel , title , show
t =range(0,13+1)
N =7#
m=[7,8,9,5]
l=[2**n-1 for n in m]
print('/n Values of length',l)
wt=arange(0,0.01+1,0.01)
bt=hstack([[1*xx for xx in ones(N)],[-1*yy for yy in ones(N)]])
ct= [0,0,1,1,1,0,1,0,0,1,1,1,0,1]
ct_polar= [-1,-1,1,1,1,-1,1,-1,-1,1,1,1,-1,1]
mt= [a*b for a,b in nditer([bt,ct_polar])]
Carrier = [2*sin(wtt*2*pi) for wtt in wt]
st= []#
for i in range(0,len(mt)):
    st=st+[mt[i]*Cr for Cr in Carrier]
subplot(3,1,1)
plot(t,mt)
xlabel('                                                                t')
title('Product Signal m(t)')
subplot(3,1,2)
plot(Carrier)
xlabel('                                                               t')
title('Carrier Signal')
subplot(3,1,3)
plot(st)
xlabel('                                                               t')
title('DS/BPSK signal s(t)')
show()

No comments:

Post a Comment

qpsk

from numpy import ones,arange,cos,sin,pi from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show M =4# i = range(0,M) t = a...