Matlab-FIR数字低通滤波器设计-时域滤波

鹅毛在路上了
Matlab领域优质创作者
2023-06-19 22:52:16
clc,clear,close all;
t = -100:1:100;
L = length(t);
fs = 2;
x1 = sin(2*pi*0.1.*t/fs);
x2 = sin(2*pi*0.3.*t/fs);
x3 = x1 + x2;
%时域信号
figure(1)
subplot(311)
plot(t,x1,"LineWidth",1.5)
grid on 
subplot(312)
plot(t,x2,"LineWidth",1.5)
grid on
subplot(313)
plot(t,x3,"LineWidth",1.5)
grid on
%滤波器设计
wn = 0.2;  %截止频率wn为0.2pi(0.2Hz),wn = 2pi*f/fs
N = 60;  %阶数选择
hn = fir1(N-1,wn,boxcar(N));  %10阶FIR低通滤波器
figure(2)
freqz(hn,1);
figure(3)
y = fftfilt(hn,x3);  %经过FIR滤波器后得到的信号
plot(t,y,"LineWidth",1.5)
grid on
%频谱分析
Y = fft(y);  %输出信号的fft
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(L/2))/L;
figure(4)
plot(f,P1,"LineWidth",1.5) 
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%0.1Hz与0.3Hz频率差距太小,精度自行调整,容易频谱泄漏

 

 

 

 

...全文
338 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

183

社区成员

发帖
与我相关
我的任务
社区描述
欢迎加入Matlab编程社区,支持各专业领域有关Matlab的博文、编程知识、经验分享,感谢每一份支持,您的鹅毛在路上了~
matlab 个人社区 山东省·潍坊市
社区管理员
  • Wayne_Fine
  • 数学建模加油站
  • MATLAB码农
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧