如何使用 Matlab 绘制巴特沃斯滤波器的频率响应

How to plot frequency response of butterworth filter using Matlab

我正在尝试绘制经过巴特沃斯低通滤波器滤波后序列的频率响应。我的极点和零点图很好,但似乎无法正确绘制我的频率响应。当我这样做时,我的轴总是超出比例。我尝试使用 Matlab 的 bode 函数无济于事。我一直在使用的示例输入是这样的 buttdes(1000, 2500, -3, -20, 20000)。任何帮助深表感谢!!到目前为止,这是我的代码:

function buttdes(fpass, fstop, dp, ds, fs)

%// Design a discrete-time Butterworth filter

%// BUTTDES(fpass, fstop, dp, ds, fs) designs and plots the bode plot

%// of the resulting analog-equivalent filter that has been

%// designed to match the analog parameters fpass (in Hz),

%// fstop (in Hz), dp (in dB) and ds (in dB).

%// fs is the sample rate in Hz

wp = fpass/fs;        
ws = fstop/fs;
WpT = 2 * tan(wp / 2);
WsT = 2 * tan(ws / 2);
qp = log10(10^-(dp/10)-1);
qs = log10(10^-(ds/10)-1);

N = ceil((qs-qp) / 2 / log10(WsT / WpT)); 
WcT = WpT * 10^(-qp/2/N);

k = 0:N-1;
skT = WcT * exp(j*pi*(2*k+N+1)/2/N);

b = real(prod(skT./(skT -2))) * poly(-ones(1, N));
a = real(poly(-(skT+2)./(skT-2)));

zplane(b, a);

要扩展 Navan 的评论,您可以使用 freqz 命令计算和绘制滤波器的频率响应。 freqz 位于信号处理工具箱中,因此如果您没有该工具箱,则需要另一种方法。

freqz 通常绘制两个图:(1) 一个幅度响应图和 (2) 一个相位响应图。如果你只想要振幅响应,你可以这样画

%compute the filter response
npoints = 1000;  %how many points to you want?   
[h,f]=freqz(b,a,npoints,fs);
response_dB = 10.*log10(h.*conj(h));
response_deg = 180/pi*angle(h);

% make plot
figure;
semilogx(f,response_dB);
xlabel('Frequency (Hz)');
ylabel('Response (dB)');