-
Notifications
You must be signed in to change notification settings - Fork 0
/
squarewaveperiodcalculator.m
55 lines (44 loc) · 1.12 KB
/
squarewaveperiodcalculator.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
loadspice("worstcaseanalysis.txt");
if exist("n002", "var")
vout = n002;
end
close all
plot(time{1}, vout{1}, "-")
title("Parameter Sweep of Time (s) vs. Vout (V)")
xlabel("Time (s)")
ylabel("Vout (V)")
ylim([-0.1, 3.4])
hold on
for i = 2:size(time, 2)
plot(time{i}, vout{i}, "-")
end
hold off
periods = zeros(size(vout));
for j = 1:size(vout, 2)
sampledata = vout{j};
sampletime = time{j};
periodstart = false;
for i = 1:size(sampledata, 2) - 1
if sampledata(i) > 3 && sampledata(i + 1) < 3
if periodstart == false
periodstartindex = i;
periodstart = true;
else
periodendindex = i;
break
end
end
end
periods(j) = sampletime(1, periodendindex) - sampletime(1, periodstartindex);
end
figure
plot(periods, ".", markersize=15)
title("Worst Case Analysis of Oscillator Period")
xlabel("Trial Number")
ylabel("Period (s)")
hold on
yline(1.1, "r--")
yline(0.9, "magenta--")
ylim([0.85, 1.15])
legend(["Period", "Upper Error Limit", "Lower Error Limit"], "Location", "southeast")
hold off