MATLAB: How to have a Bode plot with poles and zeros shown in it

bodeexportMATLABpoles and zeros

Hello,
I am looking for a way to find a Bode Plot with the poles and zeros shown in it, just like it is in the Sisotool. I also need this plot in a figure, where I can export it?

Best Answer

Try this:
sys = tf([1 0 0 1], [2 3 4 5 0]); % Create System
sysdata = tfdata(sys);
[plocs,zlocs] = pzmap(sys);
Implocs = unique(abs(imag(plocs)));
Imzlocs = unique(abs(imag(zlocs)));
[mag,phase,wout] = bode(sys);
magsv = squeeze(mag);
phasv = squeeze(phase);
[pks,locs] = findpeaks(magsv);
locs = [1; locs; numel(wout)];
mpls = interp1(wout, magsv, Implocs);
mzos = interp1(wout, magsv, Imzlocs);
ppls = interp1(wout, phasv, Implocs);
pzos = interp1(wout, phasv, Imzlocs);
figure
subplot(2,1,1)
semilogx(wout, mag2db(magsv))
hold on
plot(Implocs, mag2db(mpls), 'xr')
plot(Imzlocs, mag2db(mzos), 'or')
hold off
grid
subplot(2,1,2)
semilogx(wout, phasv)
hold on
plot(Implocs, ppls, 'xr')
plot(Imzlocs, pzos, 'or')
hold off
grid
The Control Systems (and System Identification) Toolbox plotting functions are too difficult to work with, so it is simply easier to get the outputs and plot them separately.
Note — This example will work for a SISO system. It will be necessary to adapt it to work with more complicated systems.