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

📄 fir.m

📁 designed a lowpass filter to extract cos(0.1*pi) component from x(n)
💻 M
字号:
clear all
clc
n=0:127; N=length(n); % When N become bigger,bigger precision 
n1=0:255; N1=length(n1);
M=(N1-N)/2;
w=2*pi*[0:1/(N1-1):1];
wc=0.2*pi;  % cutoff frequency
alpha=(N-1)/2;
w_1=boxcar(2*M-1); % rectangular window function
w1=[w_1',zeros(1,N1-2*M+1)];
m=n-alpha+eps;
hd=sin(wc*m)./(pi*m); % lowpass filter
h_d=[hd,zeros(1,N1-N)];
hn=h_d.*w1;  
[h,W_1]=freqz(hn,1,N1/2);
h=[abs(h'),zeros(1,N1/2)]; 
subplot(221)
plot(n1,hn);grid on;
xlabel('n');ylabel('h(n)');title('Designed lowpass filter in time domain');
subplot(222)
plot(w,h);grid on;
xlabel('w');ylabel('h(w)');title('Designed lowpass filter in frequency domain');
axis([0 pi 0 1.2]);

% Input signal x(n)
noise_mu=0;  % mean=0
noise_var=0.01;  %variance 
noise=randn(size(n)).*sqrt(noise_var) + noise_mu; 
xn=noise+cos(0.1*pi*n)+0.75*cos(0.3*pi*n)+cos(0.5*pi*n);
w__a=[xn,zeros(1,N1-N)];
X=fft(w__a);
subplot(223)
plot(w,abs(X));
xlabel('w');ylabel('x(w)');title('Input signal in frequency domain');
axis([0 pi 0 70]);

% After fir filtering
y=abs(X).*h;
subplot(224)
plot(w,y);
xlabel('w');ylabel('y(w)');title('Output signal in frequency domain');
axis([0 pi 0 70]);



⌨️ 快捷键说明

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