-
Notifications
You must be signed in to change notification settings - Fork 0
/
DifferentialManchester.m
64 lines (49 loc) · 1.12 KB
/
DifferentialManchester.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
close all;
clear all;
clc;
bits = [1 1 1 1 1 1 1 0 0 0 1];
bitrate = 1;
voltage = 5;
sampling_rate = 1000;
sampling_time = 1/sampling_rate;
end_time = length(bits)/bitrate;
time = 0:sampling_time:end_time;
index = 1;
sign = 1;
if(bits(index)==1)
sign=sign*(-1);
end
%Modulation
for i = 1:length(time)
if bits(index) == 1
modulation(i) = -voltage*sign;
else
modulation(i) = voltage*sign;
end
if (time(i)*bitrate >= (index-bitrate/2))
modulation(i)= -modulation(i);
end
if time(i)*bitrate >= index
if(index<=length(bits) && bits(index)==1)
sign=sign*(-1);
end
index = index+1;
end
end
plot(time, modulation);
axis([0 end_time -voltage-2 voltage+2]);
grid on;
index = 1;
% Demodulation
for i = 1:length(modulation)
if modulation(i) == -voltage && time(i)*bitrate<(index-bitrate/2)
demodulation(index) = 1;
end
if modulation(i) == voltage && time(i)*bitrate<(index-bitrate/2)
demodulation(index) = 0;
end
if time(i)*bitrate >= index
index = index+1;
end
end
disp(demodulation);