我试图用butterworth低通滤波器过滤我的序列的频率响应。我的极点和零点情况很好,但似乎无法正确绘制我的频率响应。当我做我的轴总是超出规模。我尝试过使用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);
答案 0 :(得分:1)
要扩展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)');