%绘制3P2Z补偿器Bode图
clear

%输入电压Vg,输出电压Vout
Vg = 30;Vout = 15;R = 7.5;
%电感内阻
rL = 30e-3;
%电容内阻
rC = 0.8e-3;
%电感感值
L = 200e-6;
%电容容值
C = 1000e-6;
%频率,采样时间
fs = 20e3;Ts = 1/fs;
%稳定占空比
D = Vout/Vg;
%传输延时
td = 400e-9+D*Ts;
%载波振幅
Nr = 1; 
s = tf('s');
%理想传递函数

Gvds = (Vg/Nr)*(1+s*rC*C)/(1+s*(L/R+rC*C)+s^2*L*C);


Wp0 = 240*2*pi;
Wp1 = 1.14e4*2*pi;
Wp2 = 9.17e4*2*pi;
Wz1 = 344*2*pi;
Wz2 = 510*2*pi;

Comp = (s/Wz1+1)*(1+s/Wz2)/(s/Wp0)/(1+s/Wp1)/(1+s/Wp2);
P=bodeoptions;
P.Grid = 'On';
P.FreqUnits='Hz';
openloop=Comp*Gvds;
figure(1);%建立窗口
bode(openloop,P);
margin(Comp*Gvds);

Gcz = c2d(Comp, Ts,'tustin') 

[num den] = tfdata(Gcz, 'v')
