一、简介
1 设计原理
1.1 滤波器概念
1.2 数字滤波器的系统函数和差分方程
1.3 数字滤波器结构的表示
1.4 数字滤波器的分类
2.1 IIR滤波器与FIR滤波器的分析比较
2.2 FIR滤波器的原理
3 FIR滤波器的仿真步骤
二、源代码
function varargout = lbq(varargin)
% LBQ MATLAB code for lbq.fig
% LBQ, by itself, creates a new LBQ or raises the existing
% singleton*.
%
% H = LBQ returns the handle to a new LBQ or the handle to
% the existing singleton*.
%
% LBQ('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LBQ.M with the given input arguments.
%
% LBQ('Property','Value',...) creates a new LBQ or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before lbq_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to lbq_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help lbq
% Last Modified by GUIDE v2.5 11-Jun-2017 11:17:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @lbq_OpeningFcn, ...
'gui_OutputFcn', @lbq_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before lbq is made visible.
function lbq_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to lbq (see VARARGIN)
% Choose default command line output for lbq
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes lbq wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = lbq_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
clear all;
fp=[300 400];fs=[200 500];
rp=3;rs=18;
Fs=2000;
wp=fp*2*pi/Fs;
ws=fs*2*pi/Fs;
%Firstly to finish frequency prewarping;
wap=2*Fs*tan(wp./2)
was=2*Fs*tan(ws./2);
[n,wn]=buttord(wap,was,rp,rs,'s');
%Note:'s'!
[z,p,k]=buttap(n);
[bp,ap]=zp2tf(z,p,k)
%
bw=wap(2)-wap(1)
w0=sqrt(wap(1)*wap(2))
[bs,as]=lp2bp(bp,ap,w0,bw)
%
[h1,w1]=freqs(bp,ap);
figure(1)
plot(w1,abs(h1));grid;
ylabel('lowpass G(p)')
%
w2=[0:Fs/2-1]*2*pi;
h2=freqs(bs,as,w2);
%Note:z=(2/Ts)(z-1)/(z+1);
[bz1,az1]=bilinear(bs,as,Fs)
[h3,w3]=freqz(bz1,az1,1000,Fs);
figure(2)
plot(w2/2/pi,20*log10(abs(h2)),w3,20*log10(abs(h3)));grid;
ylabel('Bandpass AF and DF')
xlabel('Hz')
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
%基于窗函数设计FIR滤波器
wp=0.5*pi;ws=0.66*pi;%性能指标
wdelta=ws-wp;%通带宽度
N=ceil(8*pi/wdelta) %滤波器长度
if rem(N,2)==0
N=N+1;
end
三、运行结果
四、备注
版本:2014a