필터 지우기
필터 지우기

Dealing with transfer function in symbolic math toolbox.

조회 수: 146 (최근 30일)
Hamza Harbi
Hamza Harbi 2023년 9월 8일
댓글: Paul 2023년 9월 9일
I used the command syms to symbolize the letter 's' and use it to construct transfer functions. is there a way to bodeplot the TF or getting it's DC gain without having to manually copy the numbers into a Numerator and Denominator vectors to use the function TF(Numerator,Denominator)?
thanks in advance.

채택된 답변

Star Strider
Star Strider 2023년 9월 9일
Yes.
Once you have the symbolic polynomials in s, use the sym2poly function to extract the coefficiinets. (It may be necesary to use the collect function fiirst on each of the numerator and denominator polynomials.)
Example —
syms s
H(s) = (2*s^2 + 5*s + 1) / (s^3 + 7*s^2 +2*s + 7) % Arbitrary Transfer Function
H(s) = 
[nm,dn] = numden(H)
nm(s) = 
dn(s) = 
nmd = sym2poly(nm)
nmd = 1×3
2 5 1
dnd = sym2poly(dn)
dnd = 1×4
1 7 2 7
Hs = tf(nmd,dnd)
Hs = 2 s^2 + 5 s + 1 --------------------- s^3 + 7 s^2 + 2 s + 7 Continuous-time transfer function.
figure
bode(Hs)
grid
figure
step(Hs)
grid
At least my random transfer function appears to be stable!
.

추가 답변 (1개)

Sam Chak
Sam Chak 2023년 9월 9일
In MATLAB, the transfer function is preferred to be modeled as a tf-class System Object, which is used for simulating dynamic systems with inputs that change over time. System Objects can take advantage of many useful functions from the Control System, Robust Control, and System Identification Toolboxes for modeling, analysis, design, and simulation.
However, if a dynamic system is modeled as a Symbolic Function, then some extra work is required to mathematically compute the log-magnitude curve and the phase-angle curve. Two methods are shown below:
Method 1: When a dynamic system is modeled as a System Object:
% transfer function as a System Object
G = tf(12, [1 2 3])
G = 12 ------------- s^2 + 2 s + 3 Continuous-time transfer function.
className = class(G)
className = 'tf'
get(G)
Numerator: {[0 0 12]} Denominator: {[1 2 3]} Variable: 's' IODelay: 0 InputDelay: 0 OutputDelay: 0 InputName: {''} InputUnit: {''} InputGroup: [1×1 struct] OutputName: {''} OutputUnit: {''} OutputGroup: [1×1 struct] Notes: [0×1 string] UserData: [] Name: '' Ts: 0 TimeUnit: 'seconds' SamplingGrid: [1×1 struct]
A = dcgain(G)
A = 4
figure(1)
bodeplot(G), grid on
Method 2: When a dynamic system is modeled as a Symbolic Function:
% transfer function as a Symbolic Function
syms G(s)
G(s) = 12/(s^2 + 2*s + 3)
G(s) = 
className = class(G)
className = 'symfun'
Gdc = limit(G, s, 0) % calculate DC gain using limit as s → 0
Gdc = 
4
% Compute response against the frequency ω on a logarithmic scale with base 10.
omega = logspace(-1, 2); % create log scale for ω on x-axis from 10⁻¹ to 10²
Gjw = vpa(subs(G, s, 1j*omega), 4); % G(jω)
GjwMag = 20*log10(abs(Gjw)); % log-magnitude of G(jω)
GjwPha = rad2deg(angle(Gjw)); % phase-angle of G(jω)
figure(2)
tiledlayout(2, 1, 'TileSpacing', 'Compact');
nexttile()
semilogx(omega, GjwMag), , grid on % plot the log-magnitude of G(jω)
ylabel('Magnitude (dB)');
title("Frequency Response of G(s) = "+string(G))
set(gca, 'XLim', [0 max(omega)]);
nexttile()
semilogx(omega, GjwPha), grid on % plot the phase-angle of G(jω)
xlabel('Frequency (rad/s)');
ylabel('Phase (deg)');
set(gca, 'XLim', [0 max(omega)]);
set(gca, 'YLim', [-180 0]);
yticks(-180:45:0)
  댓글 수: 2
Hamza Harbi
Hamza Harbi 2023년 9월 9일
thank you for your effort @Sam Chak, it seems a long way but i enjoyed trying it on my transfer function.
Paul
Paul 2023년 9월 9일
Seems pretty short, and can be made even shorter using Control System Toolbox for the plotting.
syms G(s) w
G(s) = 12/(s^2 + 2*s + 3);
omega = logspace(-1, 2); % create log scale for ω on x-axis from 10⁻¹ to 10²
Gjw = vpa(subs(G, s, 1j*omega), 4); % G(jω)
bodeplot(frd(double(Gjw),omega));

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by