MATLAB Answers

Why do i get error while converting Block diagram to transfer function?

1 view (last 30 days)
Shubham kumar
Shubham kumar on 6 Sep 2021
Commented: Shubham kumar on 7 Sep 2021
I have been trying to convert given block diagram to simple transfer function using following code but it is showing error. I am not sure what i am doing wrong. Please help me.
%--------------------------------------------------------------------------
% TASK 1 - Block Diagram Reduction
% Reduce the given Block Diagram
% Given -------------------------------------------------------------------
s = tf('s');
k=1/3*s^0 %assign value 1=1/3
G1 = s;
G2 = k;
G3 = s+2;
%--------------------------------------------------------------------------
% Now we are required to define all the blocks input and output. As shown
% below
G1.u = 'e2';
G1.y = 'ug1';
G2.u = 'ug1';
G2.y = 'ug2';
G3.u = 'ug2';
G3.y = 'ug3';
%--------------------------------------------------------------------------
% Note: Now we are required to relate all these inputs and outputs
%--------------------------------------------------------------------------
sum1 = sumblk('e1','r','y','+-'); % e1 = r - y
sum2 = sumblk('e2','e1','ug3','+-'); % e2 = e1 - ug3
sum3 = sumblk('y','ug1','ug2'); % y = ug1 + ug2
% we have to find the relationship between r and y for our output transfer
% function. ---------------------------------------------------------------
[a, b, c, d] = ss2tf(connect(G1,G2,G3,sum1,sum2,sum3,'r','y'))
[num den] = ss2tf(a,b,c,d)
% Step Response -----------------------------------------------------------
inputTime = [0:.1:10];
inputSignal = ones(size(inputTime));
[outputResp, time] = step(OutputTF);%, inputSignal, inputTime);
subplot(3,1,2);
plot(time,outputResp);
title('Step Response');
xlabel('Time -->');
ylabel('Magnitude -->');

Accepted Answer

Paul
Paul on 6 Sep 2021
The problem is with this line:
[a, b, c, d] = ss2tf(connect(G1,G2,G3,sum1,sum2,sum3,'r','y'))
ss2tf only computes 2 outputs, but four are specifiied, and that's what throws the error. But there are more fundamental problems. It looks like you want to extract the a,b,c,d matrices of the ss object that is returned by connect(), but ss2tf is used to go in the other direction, i.e., take the state space matrices and convtert to a transfer function..
So for starters, change that line to:
[a, b, c, d] = ssdata(connect(G1,G2,G3,sum1,sum2,sum3,'r','y'));
to extract the matrices of the state space model.
But then there's another problem. Nowhere in the code is OutputTF defined. Presumably, that's supposed to be
OutputTF = tf(num,den);
If you get used to working with the LTI objects (ss, tf, and zpk), life becomes a lot simpler. For example, you can define OutputTF directly as:
OutputTF = tf(connect(G1,G2,G3,sum1,sum2,sum3,'r','y'));
and not have to go through the conversions manually.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!