-
Notifications
You must be signed in to change notification settings - Fork 0
/
bipolar_AMI.m
64 lines (51 loc) · 1.1 KB
/
bipolar_AMI.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
clc; %clear command line
clear all; %clear variables
close all; %clear figures
%bits = [1 0 1 0 0 0 1 0 1 1 0 1 0 0 1];
bits = [0 1 1 0 0 1 0 0 1];
%Modulation :
bitRate = 1;
voltage = 5;
samplingRate = 1000;
samplingTime = 1/samplingRate;
endTime = length(bits)/bitRate;
time = 0:samplingTime:endTime;
index = 1;
sign = 1;
modulation = [];
if(bits(index)==1)
sign = -1*sign;
end
for i = 1:length(time)
if(bits(index)==0)
modulation(i) = 0;
else
modulation(i) = sign*voltage;
end
if(time(i)*bitRate >= index)
index = index+1;
if(index <= length(bits) && bits(index)==1)
sign = -1*sign;
end
end
end
plot(time,modulation,'LineWidth',3);
axis([0 endTime -voltage-5 voltage+5]);
grid on;
%Demodulation :
index = 1;
prev = voltage;
demodulation = [];
for i = 1:length(modulation)
if(modulation(i) == 0)
demodulation(index) = 0;
else
demodulation(index) = 1;
end
if(time(i)*bitRate >= index)
index = index+1;
end
end
disp(demodulation);
% alternate mark inversion
% zero = 0; 1 = alternate