summaryrefslogtreecommitdiff
path: root/coursework17/ralston_script.m
blob: ce9240a3cb51c5da25259c9b740e567bee84762b (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
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
% Vin = aI' + bI

R = 0.5;    % 0.5Ohm
L = 0.0015; % 1.5mH
data_points = 10000;

% Go on for 8 time constants
time_constant = L/R;
step = time_constant*8/data_points;

% Signal 1 Vin = 5.5V
Vin = @(t) 5.5 + 0*t;  % 5.5V
current_initial=0;

[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
plot(t, Vout);
figure;

% Signal 2a Vin = 5.5*exp(-t^2/r) V
Vin = @(t) 5.5*exp(-t^2/(160e-6))  % 5.5V
current_initial=0;

[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
plot(t, Vout);
figure;

% Signal 2b Vin = 5.5*exp(-t/r)
Vin = @(t) 5.5*exp(-t/(160e-6))  % 5.5V
current_initial=0;

[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
plot(t, Vout);
figure;

% Signal 3
T(1) =  20e-6;  % 20us
T(2) =  450e-6; % 450us
T(3) =  1000e-6;% 1000us

for j=1:3
	f = 1/T(j);
	Vin = @(t) sin(2*pi*f*t);
	[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
	plot(t, Vout);
	figure;

	Vin = @(t) sawtooth(2*pi*f*t);
	[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
	plot(t, Vout);
	figure;

	Vin = @(t) square(2*pi*f*t);
	[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
	plot(t, Vout);
	figure;
end