实验 5 程序示例:
① 为频率特性加频域容差图;
② 在对数幅频特性上加要求的指标标识;
③ 量化子程序的调用;
[N,Wc]=buttord([0.2,0.3],[0.1,0.4],1,25);
[B,A]=butter(N,Wc);
[H,W]=freqz(B,A,128);
Bq=qan2dR(B,10);
Aq=qan2dR(A,10);
[Hq,W]=freqz(Bq,Aq,128);
Hlogam=20*log10(abs(H)+eps);
Hlogam=(Hlogam.*[Hlogam>=-80])+(-80*[Hlogam<-80]);
alfa=[-25,-1,-1,-25];
omega=pi*[0.1,0.2,0.3,0.4];
ap=10^(alfa(2)/20);
as=10^(alfa(1)/20);
Halfa1=[0,1,1,0];
omega1=[omega(2),omega(2),omega(3),omega(3)];
Halfa2=[as,as,0,0,ap,ap,0,0,as,as];
omega2=[0,omega(1),omega(1),omega(2),omega(2), ...
omega(3),omega(3),omega(4),omega(4),pi];
figure(1)
hold on
plot(omega2,Halfa2,omega1,Halfa1)
plot(W,abs(H),'r')
hold off
figure(2)
plot(W,Hlogam,omega,alfa,'r+')
figure(3)
plot(W,abs(Hq),omega2,Halfa2,omega1,Halfa1)
function beq=qan2dR(d,b)
%d 需要量化的矢量;b二进制表数的位数(不计符号位);采用舍入处理;
m=1;d1=abs(d);
fix(d1)>0while
d1=abs(d)/(2^m);
m=m+1;
end
beq=fix(d1*2^b+.5);
beq=sign(d).*beq.*2^(m-b-1);