my plot shows nothing! any suggestion would be appreciated. I know i can use bode() and tf, but i wanna do it in this way. thanks

1 次查看(过去 30 天)
syms w
% Resistor = 1000 Ohm
ZR = 1e3;
% Inductor = 100 mH
ZL = 100e-3;
% Capacitor = 500 microF
ZC = 500e-6;
for w = 200*pi:2000*pi
%transfer function
H = 100 * ( 1j*w / ( 1j*w + ( 1 / (ZR*ZC) ) ) );
%gain
gain_dB = mag2db(real(H))
%phase
phase = angle(H);
end
%frequency
fr_Hz = linspace(100,1000);
% plot the gain
figure(1)
plot(fr_Hz,gain_dB)
title('Bode Plot Gain')
xlabel('Frequency (Hz)')
ylabel('Gain (dB)')
% plot the phasor
figure(2)
plot(fr_Hz, phase)
title('Bode Plot (Phasor)')
xlabel('Frequency (Hz)')
ylabel('Phase (\circ)')

采纳的回答

Star Strider
Star Strider 2017-11-28
Save your variables to vectors by subscripting them:
w = 200*pi:2000*pi;
for k1 = 1:length(w)
%transfer function
H(k1) = 100 * ( 1j*w(k1) / ( 1j*w(k1) + ( 1 / (ZR*ZC) ) ) );
%gain
gain_dB(k1) = mag2db(real(H(k1)));
%phase
phase(k1) = angle(H(k1));
end
There is no need to use the Symbolic Math Toolbox here, and it will just slow things down. I leave the rest to you.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Classical Control Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by