MATLAB Answers

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

조회 수: 1(최근 30일)
Shubham kumar
Shubham kumar 2021년 9월 6일
댓글: Shubham kumar 2021년 9월 7일
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 -->');

채택된 답변

Paul
Paul 2021년 9월 6일
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.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by