等波纹fir半带低通滤波器设计matlab代码
时间: 2023-12-29 22:02:04 浏览: 116
以下是Matlab代码实现等波纹FIR半带低通滤波器设计:
%% 等波纹FIR半带低通滤波器设计
% 设计参数
f_pass = 0.2; % 通带截止频率
f_stop = 0.3; % 阻带截止频率
delta_p = 0.01; % 通带最大衰减
delta_s = 0.1; % 阻带最小衰减
% 计算过渡带宽度
delta_f = f_stop - f_pass;
% 计算滤波器阶数和截止频率
A = -20*log10(sqrt(delta_p*delta_s)); % 计算通带过渡带宽度
N = ceil((A-8)/(4.57*delta_f)); % 计算滤波器阶数
wc = f_pass + delta_f/2 + (A/22)*delta_f; % 计算滤波器截止频率
% 计算窗函数
M = N+1;
w = kaiser(M, A);
% 计算理想低通滤波器的频率响应
h_lp_ideal = wc/pi*sinc(wc/pi*(0:M-1));
% 将低通滤波器的频率响应平移至半带
h_bp_ideal = 2*h_lp_ideal.*cos(pi/2*(0:M-1))';
% 计算等波纹半带滤波器的频率响应
h_bp_eq = h_bp_ideal.*w';
% 画出滤波器频率响应曲线
f = linspace(0, 1, 1024);
h_lp_ideal_f = wc/pi*sinc(wc/pi*f);
h_bp_ideal_f = 2*h_lp_ideal_f.*cos(pi/2*f)';
h_bp_eq_f = h_bp_ideal_f.*kaiser(length(h_bp_ideal_f), A)';
figure;
plot(f, 20*log10(abs(h_lp_ideal_f)), 'r', f, 20*log10(abs(h_bp_ideal_f)), 'g', f, 20*log10(abs(h_bp_eq_f)), 'b');
xlim([0, 1]); ylim([-80, 10]);
title('Frequency response of the filter');
xlabel('Normalized frequency'); ylabel('Magnitude (dB)');
legend('Ideal low-pass filter', 'Ideal half-band filter', 'Equal-ripple half-band filter');
阅读全文