# freqs

## 语法

``h = freqs(b,a,w)``
``[h,wout] = freqs(b,a,n)``
``freqs(___)``

## 说明

``h = freqs(b,a,w)` 返回由系数向量 `b` 和 `a` 指定的模拟滤波器在角频率 `w` 处计算得出的复频率响应。`

``[h,wout] = freqs(b,a,n)` 使用 `n` 个频率点计算 `h` 并在 `wout` 中返回对应的角频率。`

``freqs(___)` 不带输出参量，它在当前图窗窗口中以角频率的函数的形式绘制幅值和相位响应。您可以将此语法与上述任何一种输入语法结合使用。`

## 示例

`$H\left(s\right)=\frac{0.2{s}^{2}+0.3s+1}{{s}^{2}+0.4s+1}.$`

```a = [1 0.4 1]; b = [0.2 0.3 1]; w = logspace(-1,1); h = freqs(b,a,w); mag = abs(h); phase = angle(h); phasedeg = phase*180/pi; subplot(2,1,1) loglog(w,mag) grid on xlabel('Frequency (rad/s)') ylabel('Magnitude') subplot(2,1,2) semilogx(w,phasedeg) grid on xlabel('Frequency (rad/s)') ylabel('Phase (degrees)')```

```figure freqs(b,a,w)```

```n = 5; fc = 2e9; [zb,pb,kb] = butter(n,2*pi*fc,"s"); [bb,ab] = zp2tf(zb,pb,kb); [hb,wb] = freqs(bb,ab,4096);```

```[z1,p1,k1] = cheby1(n,3,2*pi*fc,"s"); [b1,a1] = zp2tf(z1,p1,k1); [h1,w1] = freqs(b1,a1,4096);```

```[z2,p2,k2] = cheby2(n,30,2*pi*fc,"s"); [b2,a2] = zp2tf(z2,p2,k2); [h2,w2] = freqs(b2,a2,4096);```

```[ze,pe,ke] = ellip(n,3,30,2*pi*fc,"s"); [be,ae] = zp2tf(ze,pe,ke); [he,we] = freqs(be,ae,4096);```

```[zf,pf,kf] = besself(n,2*pi*fc); [bf,af] = zp2tf(zf,pf,kf); [hf,wf] = freqs(bf,af,4096);```

```plot([wb w1 w2 we wf]/(2e9*pi), ... mag2db(abs([hb h1 h2 he hf]))) axis([0 5 -45 5]) grid xlabel("Frequency (GHz)") ylabel("Attenuation (dB)") legend(["butter" "cheby1" "cheby2" "ellip" "besself"])```

```[b,a] = besself(5,10000); % Bessel analog filter design freqs(b,a) % Plot frequency response```

## 算法

`freqs` 返回由 `b``a` 指定的一个模拟滤波器的复频率响应。该函数计算虚轴上频率点 s = 处拉普拉斯变换多项式

`$H\left(s\right)=\frac{B\left(s\right)}{A\left(s\right)}=\frac{b\left(1\right){s}^{n}+b\left(2\right){s}^{n-1}+\cdots +b\left(n+1\right)}{a\left(1\right){s}^{m}+a\left(2\right){s}^{m-1}+\cdots +a\left(m+1\right)}$`

```s = 1j*w; h = polyval(b,s)./polyval(a,s); ```