How to check if two transfer functions are the same?
Show older comments
I want to verify that two transfer functions are equal.
For example:
Kc = 0.4262; Ti=1.35;
C1 = pidstd(Kc,Ti);
tf(C1)
s = tf('s');
Gc1 = Kc*(1+1/(Ti*s))
assert(tf(C1) == Gc1)
Raises:
Undefined operator '==' for input arguments of type 'tf'.
Also note:
Gc1
tf(C1)
Gc1 - tf(C1)
Gc1 =
0.5754 s + 0.4262
-----------------
1.35 s
Continuous-time transfer function.
ans =
0.4262 s + 0.3157
-----------------
s
Continuous-time transfer function.
ans =
0
Static gain.
Accepted Answer
More Answers (2)
Bill Tubbs
on 12 Aug 2020
Edited: Bill Tubbs
on 12 Aug 2020
5 Comments
Paul
on 12 Aug 2020
What is the definition of equality that you want to use for transfer functions?
As you just showed, the built-in isequal function appears to require that tf's have the same coefficients. But in order to use that definition you also have to specify another constraint, like the the leading coefficient of the denominator has to be unity.
What about this case:
>> G1=tf(1,[1 1])
G1 =
1
-----
s + 1
Continuous-time transfer function.
>> G2=tf([1 2],conv([1 1],[1 2]))
G2 =
s + 2
-------------
s^2 + 3 s + 2
Continuous-time transfer function.
For your application, would you want isequal(G1,G2) to evaluate to true or false?
Bill Tubbs
on 12 Aug 2020
Edited: Bill Tubbs
on 12 Aug 2020
Paul
on 13 Aug 2020
Disclaimer: Only talking about SISO systems that don't have delays, though I think most if not all of this will exetend to systems with input or output delays.
If you're going to use Walter's approach, then you may need to account for some tolerance, as is always a concern when checking for equality. Here's an example where the difference between the two tf's should be zero, but they are not due to rounding. Depending on how you come up with your two tf's that you're comparing, this may or may not be of interest to you.
>> sys1=tf(rss(10));
>> sys2=sys1;
>> sys2.num{1}=sys2.num{1}*pi;
>> sys2.den{1}=sys2.den{1}*pi;
>> isequal(tfdata(sys1 - sys2), {0})
ans =
logical
0
Of course the difference is small.
>> [~,~,k]=zpkdata(sys2-sys1)
k =
1.8094e-14
Making your decision on equality based on k is probably the better way to go if you're deriving two tf's that should be equal in principle but aren't equal numerically.
As for normalizing the leading coefficient of the denominator, either do it the manual way as you did above or convert your tf to one of the other forms and convert back:
>> sys1=tf(3,3*[1 1]);
>> tf(zpk(sys1))
ans =
1
-----
s + 1
Continuous-time transfer function.
If you go down this route, you might as well just leave it in the zpk form, unless you really need a tf for some reason. Keep in mind that the double conversion could yield slightly different coefficients than the manual approach due to rounding effects in the conversion algorithms.
See doc minreal if by "simpiify a tf" you mean get rid of poles and zeros that (should) cancel. Hey, I just discovered that minreal also simplifies the gain.
>> minreal(sys1)
ans =
1
-----
s + 1
Continuous-time transfer function.
I haven't checked the inner workings of minreal so don't know if that's a preferred approach to get that leading coefficient to one.
Bill Tubbs
on 13 Aug 2020
Bill Tubbs
on 6 Nov 2020
Bill Tubbs
on 6 Nov 2020
Edited: Bill Tubbs
on 6 Nov 2020
4 Comments
Paul
on 6 Nov 2020
What result do you expect for this case:
G1=tf(1e-11);
G2=tf(1e-11,[1 0]);
Out of curiosity, what is the motivation behind this exercise?
Bill Tubbs
on 7 Nov 2020
Paul
on 7 Nov 2020
Well, based on my own experience you never know what a student will submit ;).
I'm not aware of any built-in way to display the transfer function in the form of (as+1)/(bs+1). You could probably write your own, but probably not worth it.
I suppose another alternative that doesn't rely on comparing transfer functions algebraically would be to come up with some criteria on the difference between the impulse responses for the two cases.
Bill Tubbs
on 7 Nov 2020
Edited: Bill Tubbs
on 7 Nov 2020
Categories
Find more on Assumptions 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!