-
Notifications
You must be signed in to change notification settings - Fork 0
/
octave_HDB3.m
77 lines (64 loc) · 1.28 KB
/
octave_HDB3.m
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
clc; #... Clear command line
clear all; #... Clear variables
close all; #... Clear figures
bits = [1 1 0 0 0 0 1 0 0 0 0];
#... Modulation
bitrate = 1;
voltage = 5;
sampling_rate = 1000;
sampling_time = 1/sampling_rate;
end_time = length(bits)/bitrate;
time = 0:sampling_time:end_time;
count = 0;
zero = 0;
one = 0;
for i = 1:length(bits)
if bits(i) == 0
count = count+1;
else
count = 0;
one = one+1;
endif
if count == 4
bits(i) = -1; count = 0;
if rem(one, 2) == 0
bits(i-3) = 1;
endif
endif
endfor
index = 1;
sign = -1;
for i = 1:length(time)
modulation(i) = bits(index)*sign*voltage;
if time(i)*bitrate >= index
if bits(index) == 1
sign = -sign;
endif
index = index+1;
endif
endfor
plot(time, modulation);
axis([0 end_time -voltage-5 voltage+5]);
line([0 end_time], [0 0]);
grid on;
#... Demodulation
index = 1;
for i = 1:length(modulation)
demodulation(index) = modulation(i)/voltage;
if time(i)*bitrate >= index
index = index+1;
endif
endfor
last = 0;
for i = 1:length(demodulation)
if demodulation(i) != 0
if last != 0 && demodulation(i) == last
for j = -3:0
demodulation(i+j) = 0;
endfor
endif
last = demodulation(i);
endif
endfor
demodulation = abs(demodulation);
disp(demodulation);