From abcd65d98b8a4830673d53eaa9665ad195b70b03 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Fri, 17 Feb 2017 14:43:50 +0000 Subject: work in progress solution for exercise 1 of coursework --- coursework17/ralston_script.m | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 coursework17/ralston_script.m (limited to 'coursework17/ralston_script.m') 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 -- cgit v1.2.3-54-g00ecf