-
Notifications
You must be signed in to change notification settings - Fork 4
/
CE_DeltaModulation.m
86 lines (78 loc) · 1.35 KB
/
CE_DeltaModulation.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
78
79
80
81
82
83
84
85
86
clc;
clear all;
close all;
pkg load signal
%Signal Parameters
A=1;
fc=1;
t=linspace(0,1,1000);
x_t=A*sin(2*pi*fc*t);
s=.2;
%Delta Modulation
s_t=0;
v=1;
mqc_t=0;
for i=1:5:length(t)
if(x_t(1,i)>mqc_t(1,v))
s_t(1,v)=1;
mqc_t(1,v+1)=mqc_t(1,v)+s;
else
s_t(1,v)=0;
mqc_t(1,v+1)=mqc_t(1,v)-s;
end
t1(1,v)=t(1,i);
v=v+1;
end
subplot(3,1,1) %first plot
plot(t,x_t);
title('Message Signal (1904215)');
xlabel('Time Axis');
ylabel('Amplitude');
hold on
stairs(t1,mqc_t(2:201))
subplot(3,1,2) %second plot
stairs(s_t)
title('Delta Modulated Signal (1904215)');
xlabel('Time Axis');
ylabel('Amplitude');
hold on
stem(s_t,'r')
axis([0 200 -0.5 1.5])
%Demodulation
mq_t=0;
%Convert bit stream into steps and integrate
for i=1:length(s_t)
if(s_t(i)==1)
mq_t(i+1)=mq_t(i)+s;
else
mq_t(i+1)=mq_t(i)-s;
end
end
%Filtering through LPF
[b,a]=butter(5,.1);
r_t=filter(b,a,mq_t);
subplot(3,1,3) %third plot
plot(t1,r_t(2:201))
title('Demodulated Signal (1904215)');
xlabel('Time Axis');
ylabel('Amplitude');
hold on;
xn=0;
for i=1:l
if x(i)>xn(i)
d(i)=1;
xn(i+1)=xn(i)+delta;
else d(i)=0; xn(i+1)=xn(i)-delta;
end
end
stairs(xn)
hold on
for i=1:d
if d(i)>xn(i)
d(i)=0;
xn(i+1)=xn(i)-delta;
else d(i)=1;
xn(i+1)=xn(i)+delta;
end
end
plot(xn);