clc,clear;
N=input('输入窗函数阶数N=:');
w1=input('输入通带频率(输入值应小于1):');
w2=input('输入截止频率(输入值应小于1):');
w1=w1*pi;
w2=w2*pi;
%==========================================================================
alpha=(N-1)/2;
n=[0:(N-1)];
m=n-alpha+eps;
h1=sin(w1*m)./(pi*m);
h2=sin(w2*m)./(pi*m);
h=h1-h2;
%==========================================================================
k=input('请选择窗的类型:\n 1、矩形窗\n 2、汉宁窗\n 3、汉明窗\n 4、布拉克曼窗\n 5、凯泽窗\n');
switch k
case 1
x=win(0,N-1,0,N-1); %矩形窗
figure,
subplot(1,2,1);
stem(n,x,'.'); %得到数字信号波形表示方法函数STEM
xlabel('n'); %X坐标标签
ylabel('x'); %Y坐标标签
string=['矩形窗时域图形','N=',num2str(N)];%波形标题
text((0.6*N),0.8,string); %波形标题
[H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(1,2,2);
plot(m/pi,db);
xlabel('w/pi');
ylabel('dB');
title('矩形窗的频率特性(db)');
axis([0,1,-100,0]);
string=['矩形窗','N=',num2str(N)];
case 2
x=win(0,N-1,0,N-1);
x=(0.5-0.5*cos(2*pi*n/(N-1))).*x;
figure,
subplot(1,2,1);
stem(n,x,'.');
xlabel('n');
ylabel('x');
string=['汉宁窗时域图形','N=',num2str(N)];
text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(1,2,2);
plot(m/pi,db);
xlabel('w/pi');
ylabel('dB');
title('汉宁窗的频率特性(db)');
axis([0,1,-100,0]);
string=['汉宁窗','N=',num2str(N)];
case 3
x=win(0,N-1,0,N-1);
x=(0.54-0.46*cos(2*pi*n/(N-1))).*x;
figure,
subplot(1,2,1);
stem(n,x,'.');
xlabel('n');
ylabel('x');
string=['汉明窗时域图形','N=',num2str(N)];
text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(1,2,2);
plot(m/pi,db);
xlabel('w/pi');
ylabel('dB');
title('汉明窗的频率特性(db)');
axis([0,1,-100,0]);
string=['汉明窗','N=',num2str(N)];
case 4
x=win(0,N-1,0,N-1);
x=(0.42-0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1))).*x;
figure,
subplot(1,2,1);
stem(n,x,'.');
xlabel('n');
ylabel('x');
string=['布拉克曼窗时域图形','N=',num2str(N)];
text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(1,2,2);
plot(m/pi,db);
xlabel('w/pi');
ylabel('dB');
title('布拉克曼窗的频率特性(db)');
axis([0,1,-100,0]);
string=['布拉克曼窗','N=',num2str(N)];
otherwise
x=win(0,N-1,0,N-1);
a=input('请输入a(典型值为4<a<9)=');
b=a*sqrt(1-(2*n/(N-1)-1).^2);
x=(besseli(0,b)/besseli(0,a)).*x;
figure,
subplot(1,2,1);
stem(n,x,'.');
xlabel('n');
ylabel('x');
string=['凯泽窗时域图形','N=',num2str(N)];text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(1,2,2);
plot(m/pi,db);
xlabel('w/pi');
ylabel('dB');
title('凯泽窗的频率特性(db)');
axis([0,1,-100,0]);
string=['凯泽窗','N=',num2str(N)];
end
h3=h.*x;
%==========================================================================
figure;
subplot(2,1,1);
stem(n,h,'.');
axis([0,N-1,-0.31,0.31]);
hold on;
x1=zeros(N);
plot(n,x1,'r-');
xlabel('n');
ylabel('h(n)');
title('理想信号');
text((0.3*N),0.2,string);
subplot(2,1,2);
stem(n,h3,'.');
axis([0,N-1,-0.31,0.31]);
hold on;
x1=zeros(N);
plot(n,x1,'r-');
xlabel('n');
ylabel('h(n)*win');
title('实际低通滤波器的h(n)');
text((0.3*N),0.2,string);
figure;
[H,m]=freqz(h,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,1);
plot(m/pi,db);
title('理想信号频谱');
axis([0,1,-100,0]);
[H,m]=freqz(h3,[1],1024,'whole'); %求其频率响应
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,2);
plot(m/pi,db);
title('通过滤波器以后的频谱');
axis([0,1,-100,0]);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.版本:matlab2021a,包含仿真操作录像,操作录像使用windows media player播放。 2.领域:FIR滤波器 3.内容:基于MATLAB的FIR滤波器性能仿真,包括矩形窗、汉明窗,海宁窗,布莱克曼窗四种窗函数,对比滤波前后效果以及对比各个窗函数的频谱特性。 4.注意事项:注意MATLAB左侧当前文件夹路径,必须是程序所在文件夹位置,具体可以参考视频录。
资源推荐
资源详情
资源评论
收起资源包目录
基于MATLAB的FIR滤波器性能仿真,包括矩形窗、汉明窗,海宁窗,布莱克曼窗.rar (23个子文件)
matlab代码
43.jpg 29KB
IIR滤波器设计与仿真matlab代码
iir.m 2KB
IIPL.m 240B
IIPH.m 236B
41.jpg 33KB
42.jpg 26KB
13.jpg 29KB
22.jpg 27KB
21.jpg 33KB
23.jpg 29KB
fir_design.m 5KB
12.jpg 39KB
32.jpg 34KB
oness.m 58B
win.m 81B
plotspec2.m 703B
11.jpg 33KB
plotspec.m 826B
test.m 186B
31.jpg 33KB
操作录像0039.avi 21.19MB
top.m 4KB
33.jpg 29KB
共 23 条
- 1
fpga和matlab
- 粉丝: 15w+
- 资源: 2548
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页