My MATLAB hacks for replotting pretty Bode diagrams
I like the phase to get 'ticked off' at 90 degree intervals (instead of 100 degrees, which just doesn't make as much sense for a Bode plot). Below is code to do this, which I'll (nicely format! and) put in the 2.010 directory (for ps #2) soon:
function [mval,pval,wval] = bode_katie(mysys,w_use)
%function [mval,pval,wval] = bode_katie(mysys,w_use)
%mval = magnitude (ratio of output/input; NOT in dB!)
%pval = phase (in degree, NOT in radians!)
%wval = frequencies (x-axis) (in rad/sec, NOT is degrees!)
%
%...those are the same conventions used by the MATLAB
%function 'bode()'.
%'mysys' must be a single-input, single-output system.
if ~exist('w_use')
[m,p,w]=bode(mysys);
else
[m,p,w]=bode(mysys,w_use);
end
wval=w;
mval=0*[1:length(w)]; pval=mval;
for i=1:length(w)
mval(i)=m(:,:,i);
pval(i)=p(:,:,i);
end
e2.
% PLOT GAIN (dB)
subplot(4,2,1);
semilogx(wval,20*log10(mval),'b-');
xlabel('Freq. (rad/sec)');
ylabel('Magn. (dP)');
grid on;
% PLOT PHASE (degrees)
subplot(4,2,3);
semilogx(wval,pval,'b-');
xlabel('Freq. (rad/sec)');
ylabel('Phase (degrees)');
grid on;
ticval=90;
tmarks=[(ticval*floor(min(pval)/ticval)):(ticval):(ticval*(ceil(max(pval)/ticval)))];
while length(tmarks)<4
ticval=ticval/3;
tmarks=[(ticval*floor(min(pval)/ticval)):(ticval):(ticval*(ceil(max(pval)/ticval)))];
end
while length(tmarks)>12
ticval=ticval*2;
tmarks=[(ticval*floor(min(pval)/ticval)):(ticval):(ticval*(ceil(max(pval)/ticval)))];
end
set(gca,'YTick',tmarks);
grid on;
You may find this function useful in itself, or you might just want to use it to scalp ideas on how the syntax works, etc...
(An example of bode_katie() plots is shown on this page.... you can't use this function in a SUBPLOT of a figure -- only in the full figure. It's use is otherwise similar to the function 'bode()'.)