How to convert symbolic transfer function to state space?
Show older comments
I have this transfer function:
where alpha, beta1, and beta2 are unknown constants. I want to convert this to a state space in MATLAB. But regardless of what I do it just doesnt work out.
where alpha, beta1, and beta2 are unknown constants. I want to convert this to a state space in MATLAB. But regardless of what I do it just doesnt work out.Accepted Answer
More Answers (2)
Hi Sam,
I was hoping that the OP would show a little more effort before giving the answer. Anyway ...
The code should be modified to use the 'all' input to coeffs so as to return the 0 coefficients as well. That way we can use dencoeff as well, which is what we'd want in general, and not return numeric A and D matrices
syms s alpha beta_1 beta_2
assume(alpha, 'real');
assume(beta_1, 'real');
assume(beta_2, 'real');
%% Plant transfer function in symbolic form
Gp = ((alpha + beta_2)*s^2 + 3*beta_1*s + 9*alpha)/(s^3 + 0*s^2 + 9*s + 0)
[num, den] = numden(Gp)
[numcoeff, numterm] = coeffs(num, s, 'all')
[dencoeff, denterm] = coeffs(den, s, 'all')
[A, B, C, D] = tf2ss(numcoeff, dencoeff)
simplify(C*inv(s*eye(3)-A)*B + D) % verify
1 Comment
Sam Chak
on 2 Dec 2023
Don't mind the OP. I'm also learning new things from you. Thus, I believe your proposed solution in the comment should be the true answer to this question because you have demonstrated how to execute this correctly in MATLAB. More importantly, it deserves my vote.
@Paul's method is to use tf2ss(). In the past, I used this approach, but now I no longer use it since learning that the syntax ss(tf(num, den)) can achieve what I want. I also wasn't aware that tf2ss() can accept inputs of 'sym' (symbolic) data type.
syms s alpha beta_1 beta_2
assume(alpha, 'real');
assume(beta_1, 'real');
assume(beta_2, 'real');
%% Plant transfer function in symbolic form
Gp = ((alpha + beta_2)*s^2 + 3*beta_1*s + 9*alpha)/(s^3 + 0*s^2 + 9*s + 0)
%% tf2ss(num, den) requires inputs of numerator and denominator in vector form
[num, den] = numden(Gp)
[numcoeff, numterm] = coeffs(num, s)
[dencoeff, denterm] = coeffs(den, s)
%% check data type
class(numcoeff)
%% Obtain state-space matrices in symbolic form
[A, B, C, D] = tf2ss(numcoeff, [1 0 9 0])
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!











