summaryrefslogtreecommitdiff
path: root/135/CH3/EX3.33/EX33.sce
blob: 70560a3161f142e37e72d7f188622ceba6bac510 (plain)
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
// Example 3.33: vo
clc, clear
t=[0:0.001:12];
vin=10*sin(2*%pi*t/4); // Input voltage in volts
// From Fig. 3.73
vint=vin+5;
for i=1:length(vint)
    if vint(i)>0 then
        // Diode is OFF
        vo(i)=vint(i); // in volts
    else
        break;
    end
end
for i=i:length(vint)
    if vint(i)==-5 then
        break;
    else
        // Diode is ON
        vo(i)=0;
    end
end
for i=i:length(vint)
    // Capacitor is charged to 5 V
    vo(i)=vint(i)+5; // in volts
end
plot2d(t,vo,rect=[0,-5,12,25]);
xtitle("Output voltage","t","vo");