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 view (last 30 days)
Show older comments
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)')
0 Comments
Accepted Answer
Star Strider
on 28 Nov 2017
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 Comments
More Answers (0)
See Also
Categories
Find more on Classical Control Design 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!