-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHDB3.m
More file actions
94 lines (79 loc) · 1.72 KB
/
HDB3.m
File metadata and controls
94 lines (79 loc) · 1.72 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
% University of Rajshahi
% Name : Nakul Deb Nath
% Dept : CSE
% Date : 27-11-2018
clear;
clear all;
clc;
n=[1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1];
%n = input('Enter the bit Stream : ');
v = 3;
v1 = 3;
count = 0;
countOnes = 0;
for index = 1:length(n)
if n(index)==1;
bitsArray(index) = v;
v = -v;
count = 0;
countOnes = countOnes+1;
else
bitsArray(index) = 0;
count = count + 1;
if count == 4
count = 0;
if rem(countOnes,2) == 0
bitsArray(index-3) = v;
bitsArray(index-2) = 0;
bitsArray(index-1) = 0;
bitsArray(index) = v;
countOnes = countOnes + 2;
v = -v;
else
bitsArray(index-3) = 0;
bitsArray(index-2) = 0;
bitsArray(index-1) = 0;
bitsArray(index) = -v;
countOnes = countOnes + 1;
% v = -v;
end
end
end
end
i=1;
t = 0:0.001:length(n);
bt = 1/0.001;
for index = 1:length(t)
if t(index) <= i;
y(index)=bitsArray(i);
else
y(index) = bitsArray(i);
i = i+1;
end
end
plot(t,y, 'LineWidth', 1);
axis([0 length(n) -5 5]);
set(gca,'YTick', [-3 0 3])
set(gca,'XTick', 1:length(n))
title('HDB3')
hold on;
grid on;
v = 3;
v1 = -v;
for j = 1:length(y)/bt
if v1 == y(j*bt)
resiveBit(j) = 0;
resiveBit(j-1) = 0;
resiveBit(j-2) = 0;
resiveBit(j-3) = 0;
elseif y(j*bt) == v;
v1 = y(j*bt);
resiveBit(j) = 1;
elseif y(j*bt) == -v
resiveBit(j) = 1;
v1 = y(j*bt);
else
resiveBit(j) = 0;
end
end
display(resiveBit);