Last active
April 9, 2022 03:57
-
-
Save cychitivav/4f03ef260bb565601cee6f6549a70f7e to your computer and use it in GitHub Desktop.
Function to convert a symbolic expression to a transfer function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sys = sym2tf(symf,ts) | |
%TF2SYM Converts symbolic function to transfer function | |
% sys = SYM2TF(symf) converts the symbolic function symf of class 'sym' | |
% to transfer function. | |
% | |
% sys = SYM2TF(...,ts) converts the symbolic function s of class 'sym' | |
% to discrete transfer function. | |
% | |
% See also TF, SYM. | |
if length(symvar(symf)) > 1 | |
error("only one symbolic variable ('s' or 'z') is allowed") | |
end | |
[N,D] = numden(symf); | |
N = sym2poly(N); | |
D = sym2poly(D); | |
if symvar(symf) == 's' | |
sys = tf(N,D); | |
elseif symvar(symf) == 'z' | |
if nargin < 2 | |
error('You must specify the sampling time for a discrete-time transfer function') | |
end | |
sys = tf(N,D,ts); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment