⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bpasfilter.m

📁 bandpass FIR filter 的MATLAB代码
💻 M
字号:
%问题: 设信号x(t)=sin(2*pi*80*t)+2*sin(2*pi*150*t), 由于某一原因,
%原始信号被白噪声污染,实际获得的信号为x2(t)=x+rand(size(x)),
%要求设计一个FIR滤波器恢复出原始信号。
clear all;
close all;
t=0.0:0.001:2.047;
x=sin(2*pi*80.*t);%+2*sin(2*pi*150.*t);
x1=x+randn(size(x));
L=length(x);
n1=1:1024;
n2=1:200;
M=64;

Y=fft(x1);  %噪声信号的频谱
E=fft(x);   %原始信号的频谱
E=abs(E(n1)); 
Y=abs(Y(n1));  %取绝对值

fs=1000;
df=fs/L;       
Wn=[75 80 145 155]/500;
b=fir1(M,Wn);       %hamming window,b是fir滤波器的系数
%freqz(b,1,512);
n=(1:length(b));
stem(n,b);

figure;
z=filter(b,1,x1);   %滤波后的信号
zk=fft(z);          %滤波后信号的频谱 
zk=abs(zk(n1));
subplot(311);
%plot(n2,x(1536+n2));title('原始信号x');
plot(1:L,x);title('原始信号x');
subplot(312);
plot(1:L,x1);title('在原始信号上加上噪声信号x');
subplot(313);
plot(1:L,z);title('经过滤波后的信号z');

figure;
subplot(311);
plot(n1*df,E);title('原始信号频谱');
subplot(312);
plot(n1*df,Y);title('噪声信号的频谱');
subplot(313);
plot(n1*df,zk);title('经过滤波后的信号频谱');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -