-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwm_new.m
95 lines (80 loc) · 1.33 KB
/
pwm_new.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
87
88
89
90
91
92
93
94
95
close all;
clear all;
clc;
tmax=8;
step=0.01;
t=0:step:tmax;
f1=1/6;
f2=1;
A=1;
y=A*sin(2*pi*f1*t );
figure;
subplot(6,1,1);
plot(t,y);
grid;
title('message signal');
xlabel('time period');
ylabel('amplitude');
x=A*sawtooth(2*pi*f2*t);
subplot(6,1,2);
plot(t,x);
grid;
title('sawtooth signal');
xlabel('time period');
ylabel('amplitude');
z=y-x;
subplot(6,1,3);
plot(t,z);
grid;
title('subtracted signal');
xlabel('time period');
ylabel('amplitude');
n = length(t);
PWM = zeros(1,n);
for i=1:n-1
if z(i)>0
PWM(i)=1;
elseif z(i)<=0
PWM(i)=0;
end
end
subplot(6,1,4);
plot(t,PWM);
grid;
title('pwm');
xlabel('time period');
ylabel('amplitude');
notPWM = zeros(1,n);
for i=1:n-1
if PWM(i)==1
notPWM(i)=0;
elseif PWM(i)==0
notPWM(i)=1;
end
end
subplot(6,1,5);
plot(t,notPWM);
grid;
PPM =zeros(1,n);
T2=(1/f2);
m=(tmax/T2);
tsample=0;
for i=0:step:T2
tsample=tsample+1;
end
for j=0:1:m-1
for i=(j*(tsample-1)+1):1:((j+1)*(tsample-1))
if notPWM(i)==0
PPM(i)=0;
elseif notPWM(i)==1
PPM(i)=1;
break;
end
end
end
subplot(6,1,6);
plot(t,PPM);
grid;
title('PPM signal');
xlabel('time period');
ylabel('amplitude');