【matlab】矩形窗/三角窗/hanning窗/hamming窗/blackman窗的频率响应图

%{
--------------------------------------------------------------------------- 
File:Matlab的窗函数,矩形窗                               
功能:降低旁瓣水平
参数: 
--------------------------------------------------------------------------- 
%}
%N =51 
%==========================================================================
%求矩形窗的频率响应图  
%==========================================================================
W = linspace(-pi,pi,4096);
wn0 = rectwin(51)   %矩形窗函数 
%20*log10(abs(WN))  
[h1,w0] = freqz(wn0,1,W); 
%subplotfigure(5,1,1);  
subplot(511);
plot(w0/pi,20*log10(abs(h1/max(h1))));  
axis([-1 1 -100 0]); 
xlabel('归一化频率 /\pi');  
ylabel('20log_{10}|W(e^{j\omega})| /dB');  
title('矩形窗的傅里叶变换'); 
set(gca,'YTick',[-100 -80 -60 -40 -20 0])  
set(gca,'XTick',[-1 :0.2: 1])   
%set(gca,'XAxisLocation','top');%设置X轴在上方  
%set(gca,'XAxisLocation','buttom');%设置X轴在下方  
set(gca,'YAxisLocation','left'); %设置Y轴在左方  
text(1,-124,'\pi');%gtext('\pi');

%==========================================================================
%求三角窗的频率响应图  
%==========================================================================
wn1 = bartlett(51)
[h1,w1] = freqz(wn1,1,W);  
%figure(5,1,2); 
subplot(512);
plot(w1/pi,20*log10(abs(h1/max(h1))));  
%plot(w/pi,20*log10(h1/max(h1))); % 警告: 复数 X 和/或 Y 参数的虚部已忽略 
axis([-1 1 -100 0]); 
xlabel('归一化频率 /\pi');  
ylabel('20log_{10}|W(e^{j\omega})| /dB'); 
title('三角窗的傅里叶变换');   
set(gca,'YTick',[-100 -80 -60 -40 -20 0]) 
set(gca,'XTick',[-1 :0.2: 1])  
%set(gca,'XAxisLocation','top');%设置X轴在上方  
set(gca,'YAxisLocation','left'); %设置Y轴在左方  
text(1,-124,'\pi');%gtext('\pi');
%==========================================================================
%hanning 窗的频率响应图   
%==========================================================================
wn2 = hanning(51)  
[h1,w2] = freqz(wn2,1,W);  
%figure(5,1,3); 
subplot(513);
plot(w2/pi,20*log10(abs(h1/max(h1))));  
axis([-1 1 -100 0]); 
xlabel('归一化频率 /\pi');  
ylabel('20log_{10}|W(e^{j\omega})| /dB');  
title('Hanning的傅里叶变换');
set(gca,'YTick',[-100 -80 -60 -40 -20 0]);  
set(gca,'XTick',[-1 :0.2: 1]);  
%set(gca,'XAxisLocation','top');%设置X轴在上方  
set(gca,'YAxisLocation','left'); %设置Y轴在左方 
text(1,-124,'\pi');%gtext('\pi');
%==========================================================================
%hamming 窗的频率响应图    
%==========================================================================
wn3 = hamming(51) 
[h1,w3] = freqz(wn3,1,W); %离散系统频响特性的函数freqz()
%figure(5,1,4);  
subplot(514);
plot(w3/pi,20*log10(abs(h1/max(h1)))); 
axis([-1 1 -100 0]); 
xlabel('归一化频率 /\pi'); 
ylabel('20log_{10}|W(e^{j\omega})| /dB');  
title('Hamming的傅里叶变换');
set(gca,'YTick',[-100 -80 -60 -40 -20 0])  
set(gca,'XTick',[-1 :0.2: 1])  
%set(gca,'XAxisLocation','top');%设置X轴在上方  
set(gca,'YAxisLocation','left'); %设置Y轴在左方 
text(1,-124,'\pi');%gtext('\pi');
%==========================================================================
%Blackman   wn1 = blackman(51) 
%==========================================================================
wn4 = blackman(51)
[h1,w4] = freqz(wn4,1,W); 
%figure(5,1,5); 
subplot(515);
plot(w4/pi,20*log10(abs(h1/max(h1))));   
axis([-1 1 -100 0]);  
xlabel('归一化频率 /\pi'); 
ylabel('20log_{10}|W(e^{j\omega})| /dB');  
title('Blackman的傅里叶变换'); 
set(gca,'YTick',[-100 -80 -60 -40 -20 0]) 
set(gca,'XTick',[-1 :0.2: 1]) 
%set(gca,'XAxisLocation','top');%设置X轴在上方  
set(gca,'YAxisLocation','left'); %设置Y轴在左方 
text(1,-124,'\pi');%gtext('\pi');

--------------------- 
作者:Treysure 
来源:CSDN 
原文:https://blog.csdn.net/u013346007/article/details/54178322 

  • 5
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
以下是用MATLAB代码实现矩形Blackman、汉宁、汉明滤波器的示例代码: 1. 矩形滤波器 ```matlab % 采样频率 fs = 1000; % 信号频率 f = 50; % 信号长度 L = 1000; % 时间序列 t = (0:L-1)/fs; % 信号 x = sin(2*pi*f*t); % 矩形滤波器 win = rectwin(L); y = x .* win; % 画 figure; subplot(2,1,1); plot(t,x); xlabel('Time (s)'); ylabel('Amplitude'); title('Original Signal'); subplot(2,1,2); plot(t,y); xlabel('Time (s)'); ylabel('Amplitude'); title('Rectangular Window Filtered Signal'); ``` 2. Blackman滤波器 ```matlab % 采样频率 fs = 1000; % 信号频率 f = 50; % 信号长度 L = 1000; % 时间序列 t = (0:L-1)/fs; % 信号 x = sin(2*pi*f*t); % Blackman滤波器 win = blackman(L); y = x .* win; % 画 figure; subplot(2,1,1); plot(t,x); xlabel('Time (s)'); ylabel('Amplitude'); title('Original Signal'); subplot(2,1,2); plot(t,y); xlabel('Time (s)'); ylabel('Amplitude'); title('Blackman Window Filtered Signal'); ``` 3. 汉宁滤波器 ```matlab % 采样频率 fs = 1000; % 信号频率 f = 50; % 信号长度 L = 1000; % 时间序列 t = (0:L-1)/fs; % 信号 x = sin(2*pi*f*t); % 汉宁滤波器 win = hann(L); y = x .* win; % 画 figure; subplot(2,1,1); plot(t,x); xlabel('Time (s)'); ylabel('Amplitude'); title('Original Signal'); subplot(2,1,2); plot(t,y); xlabel('Time (s)'); ylabel('Amplitude'); title('Hanning Window Filtered Signal'); ``` 4. 汉明滤波器 ```matlab % 采样频率 fs = 1000; % 信号频率 f = 50; % 信号长度 L = 1000; % 时间序列 t = (0:L-1)/fs; % 信号 x = sin(2*pi*f*t); % 汉明滤波器 win = hamming(L); y = x .* win; % 画 figure; subplot(2,1,1); plot(t,x); xlabel('Time (s)'); ylabel('Amplitude'); title('Original Signal'); subplot(2,1,2); plot(t,y); xlabel('Time (s)'); ylabel('Amplitude'); title('Hamming Window Filtered Signal'); ``` 这些代码可以直接复制到MATLAB命令行中运行,也可以保存为.m文件在MATLAB中直接运行。其中,变量fs表示采样频率,f表示信号频率,L表示信号长度,t是时间序列,x是原始信号,win是函数,y是滤波后的信号。在画时,subplot(2,1,1)表示将画布分为两行一列,第一个画在第一行,第二个画在第二行。xlabel、ylabel和title分别表示横轴标签、纵轴标签和标题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值