很常见的设计题目
给你一个例程,只需要改一改参数就行了
clear all;
f=[0 0.19 0.2 0.3 0.31 0.59 0.6 0.8 0.81 1];
% 给定频率轴分点;
m=[0 0 1 1 0 0 1 1 0 0];
% 给定在这些频率分点上理想的幅频响应
N1=30;
N2=90;
% 取两种不同的滤波器长度;
b1=fir2(N1,f,m);
b2=fir2(N2,f,m);
% 得到两个滤波器;
subplot(311);
stem(b1,'.');grid;
subplot(312);
stem(b2,'.');grid;
M=128;
[h1,w]=freqz(b1,1,M,1);
[h2,w]=freqz(b2,1,M,1);
subplot(313);
plot(w,abs(h1),'b-',w,abs(h2),'g-');grid;
其中,f是归依化以后的频率 通过数字滤波器的采样频率算出来,根据通带和阻带算好f和m就行了
看一看help,这个函数应该有窗函数的选择 默认情况下是汉明窗
希望能够帮到你
clc;
clear;
N=15;
Wc=pi/4;
alpha=(N-1)/2;
n=0:1:(N-1);
m=n-alpha+eps;
hd=sin(Wc*m)./(pi*m);
Wn=(hamming(15));
h=hd.*Wn.';
figure(1),freqz(h,1);
figure(2),subplot(1,2,1),stem(n,abs(h));
subplot(1,2,2),stem(n,angle(h));
n=0:1:100;
x=cos(0.2*pi*n)+cos(0.8*pi*n)
subplot(312);
plot(n,x);
y=filter(h,1,x);
subplot(313);
plot(n,y);
grid on