summaryrefslogtreecommitdiff
path: root/coursework17/ralston_script.m
diff options
context:
space:
mode:
Diffstat (limited to 'coursework17/ralston_script.m')
-rw-r--r--coursework17/ralston_script.m50
1 files changed, 50 insertions, 0 deletions
diff --git a/coursework17/ralston_script.m b/coursework17/ralston_script.m
new file mode 100644
index 0000000..9db929f
--- /dev/null
+++ b/coursework17/ralston_script.m
@@ -0,0 +1,50 @@
+% 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);
+
+% Signal 2a Vin = 5.5*exp(-t^2/r) V
+Vin = @(t) 5.5*exp(-(t*160*10^(-6))^2) % 5.5V
+current_initial=0;
+
+[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
+plot(t, Vout);
+
+% Signal 2b Vin = 5.5*exp(-t/r)
+Vin = @(t) 5.5*exp(-t*160*10^(-6)) % 5.5V
+current_initial=0;
+
+[t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
+plot(t, Vout);
+
+% 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);
+
+ Vin = @(t) sawtooth(2*pi*f*t);
+ [t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
+ plot(t, Vout);
+
+ Vin = @(t) square(2*pi*f*t);
+ [t, Vout] = ralston(R, L, Vin, current_initial, step, data_points*step);
+ plot(t, Vout);
+end