clc;clear;close; fc=1000; ap=1;as=25;fp=100;fs=300; wp=2*pi*fp/fc; ws=2*pi*fs/fc; Wanp=wp*fc; Wans=ws*fc; [N,wanc]=buttord(Wanp,Wans,ap,as,'s'); [b,a]=butter(N,Wans,'s'); [B1,A1]=impinvar(b,a,fc); [H1,w]=freqz(B1,A1,'whole'); subplot(2,1,1); plot(w*fc/2/pi,20*log10(abs(H1)));grid on; axis([0,1000,-40,0]);ylabel('H1幅值dB'); title; ap=1;as=25;fp=100;fs=300; fc=1000; wp=2*pi*fp/fc; ws=2*pi*fs/fc; anp=2*fc*tan(wp/2); ans=2*fc*tan(ws/2); [N,anc]=buttord(anp,ans,ap,as,'s'); [b,a]=butter(N,anc,'s'); [B2,A2]=bilinear(b,a,fc); [H2,w]=freqz(B2,A2,'whole'); subplot(2,1,2);plot(w*fc/2/pi,20*log(abs(H2))); axis([0,1000,-100,0]);grid on; xlabel;ylabel; title; 这个代码错哪里啦?
时间: 2023-12-18 10:03:37 浏览: 174
MatLab基本知识学习详细.pdf
这段代码存在一些问题:
1. `title`、`xlabel`、`ylabel` 函数需要传入字符串参数,否则会报错;
2. `20*log` 函数应该改为 `20*log10`;
3. `xlabel` 和 `ylabel` 函数也需要传入字符串参数。
以下是修改后的代码:
```
clc; clear; close;
fc = 1000; ap = 1; as = 25; fp = 100; fs = 300;
wp = 2*pi*fp/fc; ws = 2*pi*fs/fc;
Wanp = wp*fc; Wans = ws*fc;
[N, wanc] = buttord(Wanp, Wans, ap, as, 's');
[b, a] = butter(N, Wans, 's');
[B1, A1] = impinvar(b, a, fc);
[H1, w] = freqz(B1, A1, 'whole');
subplot(2, 1, 1);
plot(w*fc/2/pi, 20*log10(abs(H1))); grid on; axis([0, 1000, -40, 0]);
ylabel('H1幅值(dB)'); title('频率响应');
ap = 1; as = 25; fp = 100; fs = 300; fc = 1000;
wp = 2*pi*fp/fc; ws = 2*pi*fs/fc;
anp = 2*fc*tan(wp/2); ans = 2*fc*tan(ws/2);
[N, anc] = buttord(anp, ans, ap, as, 's');
[b, a] = butter(N, anc, 's');
[B2, A2] = bilinear(b, a, fc);
[H2, w] = freqz(B2, A2, 'whole');
subplot(2, 1, 2);
plot(w*fc/2/pi, 20*log10(abs(H2))); axis([0, 1000, -100, 0]);
grid on; xlabel('频率(Hz)'); ylabel('幅值(dB)'); title('频率响应');
```
阅读全文