基于MATLAB的FIR 数字低通滤波器设计本科毕业设计 下载本文

内容发布更新时间 : 2024/12/22 20:30:41星期一 下面是文章的全部内容请认真阅读。

天津大学仁爱学院2013届本科生毕业生设计(论文)

hn=hdn.*(wn');

[H,w]=freqz(hn,[1],1024,'whole'); dbH=20*log10((abs(H)+eps)/max(abs(H))); figure(4);subplot(1,3,1); stem(n,hn,'.');

xlabel('n');ylabel('h(n)');title('布莱克曼函数设计h(n)'); subplot(1,3,2); plot(w,abs(H));

xlabel('w');ylabel('H(jw)');title('h(n)的幅度谱');axis([0,3,0,1.5]); subplot(1,3,3); plot(w/pi,dbH);

xlabel('w/pi');ylabel('dB');title('损耗特性');axis([0,1,-100,0]); 5.2 利用频率抽样法设计低通滤波器程序

M=63; Wp=0.5*pi;%所需频率采样点个数及通带截止频率

m=0:(M+1)/2; Wm=2*pi*m./(M+1);%通频带上的采样点及阻带截止频率 mtr=floor(Wp*(M+1)/(2*pi))+2;%向负方向入floor(3.5)=3;floor(-3.2)=-4 Ad=[Wm<=Wp];Ad(mtr)=0.38;

Hd=Ad.*exp(-j*0.5*M*Wm);%构造频域采样向量H(k) Hd=[Hd conj(fliplr(Hd(2:(M+1)/2)))];

%fliplr函数实现矩阵的左右翻转conj是求复数的共轭 h=real(ifft(Hd));%h(n)=IDFT[H(k)]

w=linspace(0,pi,1000);%用于产生0,pi之间的1000点行矢量 H=freqz(h,[1],w);%滤波器的幅频特性图 figure(1)

plot(w/pi,20*log10(abs(H)));%参数分别是归一化频率与幅值

xlabel('归一化角频率');ylabel('增益/分贝');title('滤波器的增益响应'); axis([0 1 -50 0.5]);

f1=100;f2=300;f3=700;fs=2000;%待滤波正弦信号频率及采样频率 figure(2) subplot(211)

t=0:1/fs:0.25;%定义时间范围和步长

29

天津大学仁爱学院2013届本科生毕业生设计(论文)

s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);%滤波前信号 plot(t,s);%滤波前的信号图像

xlabel('时间/秒');ylabel('幅度');title('信号滤波前时域图'); subplot(212)

Fs=fft(s,512); AFs=abs(Fs);%将信号变换到频域及信号频域图的幅值 f=(0:255)*fs/512;%频率采样

plot(f,AFs(1:256));%滤波前的信号频域图

xlabel('频率/赫兹');ylabel('幅度');title('信号滤波前频域图'); figure(3)

sf=filter(h,1,s);%使用filter函数对信号进行滤波 subplot(211)

plot(t,sf)%滤波后的信号图像

xlabel('时间/秒');ylabel('幅度');title('信号滤波后时域图'); axis([0.2 0.25 -2 2]);%限定图像坐标范围 subplot(212)

Fsf=fft(sf,512); AFsf=abs(Fsf);%滤波后的信号频域图及信号频域图的幅值 f=(0:255)*fs/512;%频率采样

plot(f,AFsf(1:256))%滤波后的信号频域图

xlabel('频率/赫兹');ylabel('幅度');title('信号滤波后频域图'); 5.3(1)程序 function xt=xtg(N)

%实验五信号x(t)产生,并显示信号的幅频特性曲线

%xt=xtg(N) 产生一个长度为N,有加性高频噪声的单频调幅信号xt,采样频率Fs=1000Hz

%载波频率fc=Fs/10=100Hz,调制正弦波频率f0=fc/10=10Hz. Fs=1000;T=1/Fs;Tp=N*T; t=0:T:(N-1)*T;

fc=Fs/10;f0=fc/10; %载波频率fc=Fs/10,单频调制信号频率为f0=Fc/10; mt=cos(2*pi*f0*t); %产生单频正弦波调制信号mt,频率为f0 ct=cos(2*pi*fc*t); %产生载波正弦波信号ct,频率为fc xt=mt.*ct; %相乘产生单频调制信号xt nt=2*rand(1,N)-1; %产生随机噪声nt

30

天津大学仁爱学院2013届本科生毕业生设计(论文)

%=======设计高通滤波器hn,用于滤除噪声nt中的低频成分,生成高通噪声=======

fp=150; fs=200;Rp=0.1;As=70; fb=[fp,fs];m=[0,1];

% 滤波器指标

% 计算remezord函数所需参数f,m,dev

dev=[10^(-As/20),(10^(Rp/20)-1)/(10^(Rp/20)+1)];

[n,fo,mo,W]=remezord(fb,m,dev,Fs); % 确定remez函数所需参数

hn=remez(n,fo,mo,W); % 调用remez函数进行设计,用于滤除噪声nt中的低频成分

yt=filter(hn,1,10*nt); %滤除随机噪声中低频成分,生成高通噪声yt %================================================================ xt=xt+yt; %噪声加信号 fst=fft(xt,N);k=0:N-1;f=k/Tp;

subplot(3,1,1);plot(t,xt);grid;xlabel('t/s');ylabel('x(t)'); axis([0,Tp/5,min(xt),max(xt)]);title('(a) 信号加噪声波形')

subplot(3,1,2);plot(f,abs(fst)/max(abs(fst)));grid;title('(b) 信号加噪声的频谱')

axis([0,Fs/2,0,1.2]);xlabel('f/Hz');ylabel('幅度') 5.2(2)程序

%《数字信号处理(第三版)学习指导》第10章实验5程序exp5.m % FIR数字滤波器设计及软件实现 clear all;close all;

%==调用xtg产生信号xt, xt长度N=1000,并显示xt及其频谱,========= N=1000;xt=xtg(N);

fp=120; fs=150;Rp=0.2;As=60;Fs=1000; % 输入给定指标 % (1) 用窗函数法设计滤波器

wc=(fp+fs)/Fs; %理想低通滤波器截止频率(关于pi归一化) B=2*pi*(fs-fp)/Fs; %过渡带宽度指标 Nb=ceil(11*pi/B); %blackman窗的长度N hn=fir1(Nb-1,wc,blackman(Nb)); Hw=abs(fft(hn,1024));

% 求设计的滤波器频率特性

ywt=fftfilt(hn,xt,N); %调用函数fftfilt对xt滤波

%以下为用窗函数法设计法的绘图部分(滤波器损耗函数,滤波器输出信号波形) %省略

% (2) 用等波纹最佳逼近法设计滤波器 fb=[fp,fs];m=[1,0];

% 确定remezord函数所需参数f,m,dev

31

天津大学仁爱学院2013届本科生毕业生设计(论文)

dev=[(10^(Rp/20)-1)/(10^(Rp/20)+1),10^(-As/20)]; [Ne,fo,mo,W]=remezord(fb,m,dev,Fs); hn=remez(Ne,fo,mo,W); Hw=abs(fft(hn,1024));

% 确定remez函数所需参数

% 调用remez函数进行设计 % 求设计的滤波器频率特性

yet=fftfilt(hn,xt,N); % 调用函数fftfilt对xt滤波

%以下为用等波纹设计法的绘图部分(滤波器损耗函数,滤波器输出信号yw(nT)波形) %省略

32

外文资料

FIR Filter Design Techniques

Abstract:

This report deals with some of the techniques used to design FIR filters. In the beginning, the windowing method and the frequency sampling methods are discussed in detail with their merits and demerits. Different optimization techniques involved in FIR filter design are also covered, including Rabiner’s method for FIR filter design. These optimization techniques reduce the error caused by frequency sampling technique at the non-sampled frequency points. A brief discussion of some techniques used by filter design packages like Matlab are also included. Introduction

FIR filters are filters having a transfer function of a polynomial in z and is an all-zero filter in the sense that the zeroes in the z-plane determine the frequency response magnitude characteristic.The z transform of a N-point FIR filter is given by

(1)

FIR filters are particularly useful for applications where exact linear phase response is required. The FIR filter is generally implemented in a non-recursive way which guarantees a stable filter. FIR filter design essentially consists of two parts (i) approximation problem (ii) realization problem

The approximation stage takes the specification and gives a transfer function through four steps. They are as follows:

(i) A desired or ideal response is chosen, usually in the frequency domain. (ii) An allowed class of filters is chosen (e.g.the length N for a FIR filters).

(iii) A measure of the quality of approximation is chosen.

(iv) A method or algorithm is selected to find the best filter transfer function.

The realization part deals with choosing the structure to implement

1