Matlab Goodness for System Analysis
This is mostly for my own reference, but I hope someone else will benefit from it. It’s mainly to play with transfer functions.
First, generate the transfer function:
% numerator coefficients for s^2 + 2s + 4
num = [1 2 4]
% denominator coefficients for s + 6
den = [ 1 6 ]
% build the transfer function
H = tf(num, den)
% now we can do fun stuff like get a bode plot
bode(H)
% or plot it over a range of frequencies, 100 to 200 radians/s
bode(H,{100,200})
% or we could get the gain and phase shift for a certain frequency, 4pi here
[gain, phase] = bode(H, 4pi)
% how about zeroes and poles? Okay...
tzero(H)
poles(H)To add some more stuff, the transfer function can also be generated when you have the factored form of it to begin with:% if the denominator looks like (s-1)(s-2)(s-3) poles = [1 2 3] % same for zeros: (s+1)(s+2)(s+3) zeros = [-1 -2 -3] % and finally, gain K k = 1 % now we can get the system like so: H = zpk(zeros, poles, k)I may add more at a later point. Not too fancy stuff here, but pretty helpful to what I needed done.
Related posts: