-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_coding1.py
66 lines (63 loc) · 1.91 KB
/
line_coding1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
num_bits=int(input("Enter the number of bits:"))
y=[i/2 for i in range(num_bits*2)]
y=[]
manchester=[]
diff_manchester=[]
bits=[]
for i in range(num_bits):
y.append(i)
y.append(i+0.5)
y.append(i+0.5)
y.append(i+0.5)
y.append(i+1)
print("Enter the bits:")
for i in range(num_bits):
num=int(input())
bits.append(num)
if num==1:
manchester.append(1)
manchester.append(1)
manchester.append(0)
manchester.append(-1)
manchester.append(-1)
if len(diff_manchester)==0:
diff_manchester.append(1)
diff_manchester.append(1)
diff_manchester.append(0)
diff_manchester.append(-1)
diff_manchester.append(-1)
else:
x=[diff_manchester[-4],diff_manchester[-1]]
diff_manchester.append(x[1])
diff_manchester.append(x[1])
diff_manchester.append(0)
diff_manchester.append(x[0])
diff_manchester.append(x[0])
elif num==0:
manchester.append(-1)
manchester.append(-1)
manchester.append(0)
manchester.append(1)
manchester.append(1)
if len(diff_manchester)==0:
diff_manchester.append(-1)
diff_manchester.append(-1)
diff_manchester.append(0)
diff_manchester.append(1)
diff_manchester.append(1)
else:
x=[diff_manchester[-4],diff_manchester[-1]]
diff_manchester.append(x[0])
diff_manchester.append(x[0])
diff_manchester.append(0)
diff_manchester.append(x[1])
diff_manchester.append(x[1])
plt.subplot(1, 2, 1)
plt.plot(y, diff_manchester)
plt.title("Manchester")
plt.subplot(1,2,2)
plt.plot(y,manchester)
plt.title("Differential Manchester")
plt.show()