Matlab 6.x Howtos
How to draw a Bode Plot and Superimpose another plot to it
- Requirements: You need the Control Systems Toolbox (to be able to use
the bode command)
% This examples
shows how to draw a bode plot
% and then superimpose to it another plot
% First define the system transfer function
G=tf(10,[1 2 1]);
% Find its Bode Plot (note left hand side argument)
[mag,pha,w]=bode(G);
% Plot the Magnitude and Phase Plots
% Magninutde Plot
figure(1)
semilogx(w,20*log10(squeeze(mag))) % note the squeeze function
% label the plot
title('|G(j\omega|')
xlabel('Frequency [rad/sec]')
ylabel('Magnitude')
grid
% Phase Plot
figure(2)
semilogx(w,(squeeze(pha)))
% Label the plot
title('Phase of G(j\omega')
xlabel('Frequency [rad/sec]')
ylabel('Phase [deg]')
grid
% To superimpose another figure just "hold on" to it
% To add to the first figure, first select it
figure(1)
% now hold it
hold on
% now add whatever you want
semilogx([.1 1],[1 1],'or')
semilogx([.1 1],[1 1],'-g')
% Now add something to figure 2
figure(2)
hold on
% we will add a continuous green horizontal line at -90 deg.
semilogx([.1 10],[-90 -90],'-g')
% Once done release the hold
figure(1),hold off
figure(2),hold off