MATLAB代码;采用窗函数设计法完成低通滤波器的设计,参数为: wp1=0.35*pi; wp=0.35*pi;ws=0.8*pi;Ap=-3dB, As=-45dB;
时间: 2024-05-13 13:18:16 浏览: 198
低通滤波器设计与实现(基于MATLAB)
5星 · 资源好评率100%
以下是MATLAB代码,使用窗口函数法设计低通滤波器:
```matlab
% 定义参数
wp1 = 0.35*pi;
wp = 0.35*pi;
ws = 0.8*pi;
Ap = 3; % 通带最大衰减
As = 45; % 阻带最小衰减
% 计算通带、阻带截止频率
wp2 = wp1 + (ws - wp)/2;
ws2 = wp1 + (ws - wp)*3/4;
% 计算通带、阻带宽度
delta_p = abs(wp - wp1);
delta_s = abs(ws - ws2);
% 计算窗口长度
L = ceil((As - 7.95)/(2.285*delta_s));
% 计算窗口
w = blackman(L+1)';
% 计算理想低通滤波器的频率响应
N = 1001;
n = 0:N-1;
hd = (wp/pi) * sinc((wp/pi)*(n-N/2)) .* (hamming(N)');
% 计算实际低通滤波器的频率响应
h = hd .* w;
H = fft(h, 1024);
H = H(1:512);
% 绘制滤波器的幅频响应曲线
w_axis = linspace(0, pi, 512);
figure;
plot(w_axis/pi, 20*log10(abs(H)));
grid on;
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude (dB)');
title('Filter Frequency Response');
% 输出滤波器系数
disp(h);
```
阅读全文