You are on page 1of 2

from random import randint

def rect(T,b):
m = []
for t in range(T):
m.append(b)
return m

def pulse_train(data,T):
sig = []
for i in range(len(data)):
for j in range(T):
sig.append(data[i])
return sig

def clock(n,fs):
clk = []
for i in range(n):
for j in range(int(fs/4)):
clk.append(1)
for j in range(int(fs/4)):
clk.append(0)
return clk

fc = 10;
fs = 16*fc;
N = 5;
t=np.linspace(0,N,N*fs)

c = np.cos(2*math.pi*fc*t)
plt.figure(1)
plt.subplot(3,1,1)
plt.plot(t,c)
data = []
for i in range(2*N):
data.append(randint(0,1))

# data = [1, 0, 1, 1, 0, 1, 1, 0, 0, 1]
T = int(fs/2)
m = pulse_train(data,T)
m = [x*2-1 for x in m]
# plt.figure(2)
plt.subplot(3,1,2)
plt.plot(t,m,'b')

s = np.multiply(c,m)
#plt.figure(3)
plt.subplot(3,1,3)
plt.plot(t,s)

clk = clock(len(data),fs)
# plt.figure(4)
# plt.subplot(2,1,2)
# plt.plot(t,clk,'r')

# plt.show(block=False)
plt.show()

You might also like