📄 sylb.m
字号:
clear all
clc
close all
load 'bgd';
%xishu=[fs wp ws rp rs fun];
xishu=[];
fs=;%采样频率
%选择滤波器
fun=;
mod=;
if fun<=2
wp=;%通带截止频率
ws=;%阻带截止频率
else
wp=;
ws=;
end
rp=;%通带波动系数
rs=;%阻带衰减系数
%确定滤波方式
switch fun
case 1
ft='low';
case 2
ft='high';
case 3
ft='bandpass';
case 4
ft='stop';
otherwise
ft='low';
end
%iir滤波器设计
switch mod
%巴特沃斯滤波器
case 1
[n wn]=buttord(wp/(fs/2),ws/(fs/2),rp,rs);
[b a]=butter(n,wn,ft);
%切比雪夫I型滤波器
case 2
[n wn]=cheb1ord(wp/(fs/2),ws/(fs/2),rp,rs);
[b a]=cheby1(n,rp,wn,ft);
%切比雪夫I型滤波器
case 3
[n wn]=cheb2ord(wp/(fs/2),ws/(fs/2),rp,rs);
[b a]=cheby2(n,rp,wn,ft);
%椭圆滤波器
case 4
[n wn]=ellipbuttord(wp/(fs/2),ws/(fs/2),rp,rs);
[b a]=ellip(n,rp,wn,ft);
end
%计算滤波器的响应频率
[h w]=freqz(b,a,1024,fs);
m=length(x);
t=0:1/fs:(m-1)/fs;
y=filter(b,a,x);
subplot(2,1,1);
plot(w,abs(h));
xlabel('频率(Hz)');
ylabel('幅值');
grid on;
subplot(2,1,2);
plot(t,x,':',t,y);
xlabel('时间(s)');
ylabel('幅值');
legend('滤波前','滤波后')
grid on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -