I am currently taking Computer Controlled Systems this Spring 2014 that is being
taught by professor Armando Rodriguez.
His website: http://aar.faculty.asu.edu/
http://aar.faculty.asu.edu/classes/eee481S12/
Professor
Sch Elect Comptr & Energy Engr
Faculty
Mail Code: 5706
GWC 352 (Map)
(480)965-3712
The following are notes for this course:
% why would you want to use the
% home command?
clear all
close all
clear
clc
clf
%
% 3-6-2014
%
% M.J. Thompson
%
% GOAL: PLOT ERRORS ASSOCIATED WITH 3 MOST COMMONLY USED
% DISCRETIZATION METHODS
%
% 1) Forward difference backward Euler
% s1=(z-1) / T
% 2) Backward difference forward Euler
% s2= s1/z
% 3) Bilinear Tustin trapezoilda method
% s3= 2/T [z-1] / [z+1]
%
%
%
w=[0:0.001:20] % Vector of discrete-time
temp1 = (exp(j.*w)-1);
e1 = abs(j.*w-temp1); % FDBE
temp2 = j.*w.*temp1;
e2 = abs(j.*w-temp2); % BDFE
temp3 = 2.*temp1./(exp(j.*w)+1);
e3 = abs(j.*w-temp3) % BTT
figure(10)
subplot(4,1,1)
plot(w,e1,'b-',w,e2,'r-',w,e3,'k-') % plot 3 errors vs w
axis([0 20, 0 20]) % set ranges on x and y axes
grid minor % set grid on
title('Discretization Error vs Frequency')
xlabel(' Discrete frequency: \omega (rad/sec)')
ylabel('Magnitude of Error')
legend('e1','e2','e3')
subplot(4,1,2)
plot(w,e1,'b-',w,e2,'r-',w,e3,'k-') % plot 3 errors vs w
axis([0 4, 0 5]) % set ranges on x and y axes
grid minor % set grid on
title('Discretization Error vs Frequency')
xlabel(' Discrete frequency: \omega (rad/sec)')
ylabel('Magnitude of Error')
legend('e1','e2','e3')
subplot(4,1,3)
plot(w,e1,'b-',w,e2,'r-',w,e3,'k-') % plot 3 errors vs w
axis([0 2, 0 0.5]) % set ranges on x and y axes
grid minor % set grid on
title('Discretization Error vs Frequency')
xlabel(' Discrete frequency: \omega (rad/sec)')
ylabel('Magnitude of Error')
legend('e1','e2','e3')
subplot(4,1,4)
plot(w,e1,'b-',w,e2,'r-',w,e3,'k-') % plot 3 errors vs w
axis([0 1.2, 0 0.1]) % set ranges on x and y axes
grid minor % set grid on
title('Discretization Error vs Frequency')
xlabel(' Discrete frequency: \omega (rad/sec)')
ylabel('Magnitude of Error')
legend('e1','e2','e3')
% why would you want to use return command?
-----------------------------------------------------------------------
Matlab: Ways to integrate under the curve with Forward Euler and backward Euler methods
% Setup: solve y' = f(t,y(t)), y(0) = y0, t <= T, with
g = @(t)(t.^4 - 6*t.^3 + 12*t.^2 - 14*t + 9)./(1+t).^2;
f = @(t,y)(y.^2 - g(t));
y0 = 2;
T = 2.2;
% Exact solution
yexact = @(t)(1-t).*(2-t)./(1+t);
hfine = 1e-3;
tfine = 0:hfine:T;
yfine = yexact(tfine);
figure(1); clf;
plot(tfine,yfine,'r-','linewidth',2)
axis([0 T -1 2]);
set(gca,'fontsize',16);
%% Numerical solution: Forward Euler (FE)
for h = [.2 .1 .05]
t = 0:h:T;
nsteps = length(t)-1;
yFE = [y0; zeros(nsteps, 1)];
for n = 1:nsteps
yFE(n+1) = yFE(n) + h*f(t(n),yFE(n));
end
figure(1); hold on;
plot(t,yFE,'b-x','linewidth',1);
axis([0 T -1 2]);
end
xlabel('t'); ylabel('y'); title('Forward Euler')
legend('Exact','h = .2', 'h = .1', 'h = .05');
%% Numerical solution: Runge-Kutta 2 (RK)
figure(1); clf;
plot(tfine,yfine,'r-','linewidth',2)
set(gca,'fontsize',16);
for h = [.2 .1 .05]
t = 0:h:T;
nsteps = length(t)-1;
yRK = [y0; zeros(nsteps, 1)];
for n = 1:nsteps
yFE = yRK(n) + h*f(t(n),yRK(n));
yRK(n+1) = yRK(n) + h/2*...
( f(t(n),yRK(n)) + f(t(n+1), yFE) );
end
figure(1); hold on;
plot(t,yRK,'b-x','linewidth',1);
axis([0 T -1 2]);
end
xlabel('t'); ylabel('y'); title('Runge-Kutta 2')
legend('Exact','h = .2', 'h = .1', 'h = .05');
%% Numerical solution: Backward Euler (BE)
figure(1); clf;
plot(tfine,yfine,'r-','linewidth',2)
set(gca,'fontsize',16);
for h = [.1 .05]
t = 0:h:T;
nsteps = length(t)-1;
yBE = [y0; zeros(nsteps, 1)];
for n = 1:nsteps
F = @(x)(x - yBE(n) - h*f(t(n+1),x));
yBE(n+1) = fzero(F,yBE(n));
end
figure(1); hold on;
plot(t,yBE,'b-x','linewidth',1);
axis([0 T -1 2]);
end
xlabel('t'); ylabel('y'); title('Backward Euler')
legend('Exact','h = .1','h = .05');
%% Numerical solution: Midpoint method (MM)
figure(1); clf;
plot(tfine,yfine,'r-','linewidth',2)
set(gca,'fontsize',16);
for h = [.2 .1 .05]
t = 0:h:T;
nsteps = length(t)-1;
yMM = [y0; zeros(nsteps, 1)];
for n = 1:nsteps
F = @(x)(x - yMM(n) - h/2*...
( f(t(n),yMM(n)) + f(t(n+1),x)) );
yMM(n+1) = fzero(F,yMM(n));
end
figure(1); hold on;
plot(t,yMM,'b-x','linewidth',1);
axis([0 T -1 2]);
end
xlabel('t'); ylabel('y'); title('Midpoint method')
legend('Exact','h = .2', 'h = .1','h = .05');
------------------------------------------------------------------------
The least significant bit
http://en.wikipedia.org/wiki/Least_significant_bit
Harry Nyquist
http://en.wikipedia.org/wiki/Harry_Nyquist
Paper about Harry Nyquist
http://www.dsif.fee.unicamp.br/~moschim/cursos/simulation/nyquist28.pdf
Resolution = voltage difference / 2^n
Drawing root locus by hand