失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 【滤波器】基于matlab GUI高通+低通+带通+带阻FIR滤波器设计【含Matlab源码 699期】

【滤波器】基于matlab GUI高通+低通+带通+带阻FIR滤波器设计【含Matlab源码 699期】

时间:2019-04-08 16:27:05

相关推荐

【滤波器】基于matlab GUI高通+低通+带通+带阻FIR滤波器设计【含Matlab源码 699期】

一、获取代码方式

获取代码方式1:

完整代码已上传我的资源: 【滤波器】基于matlab GUI高通+低通+带通+带阻FIR滤波器设计【含Matlab源码 699期】

获取代码方式2:

通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、数字滤波器设计简介

1 设计原理

1.1 滤波器概念

1.2 数字滤波器的系统函数和差分方程

1.3 数字滤波器结构的表示

1.4 数字滤波器的分类

2.1 IIR滤波器与FIR滤波器的分析比较

2.2 FIR滤波器的原理

3 FIR滤波器的仿真步骤

三、部分源代码

%--------------------------------------------------------------------------%利用kaiser窗设计低通滤波器m文件%默认输入参数: N=64%beta=5.568 %wc=0.5pi%输出参数:通带边界(wp)%阻带边界(ws)%通带波纹%阻带衰减%--------------------------------------------------------------------------function varargout = lpfilter(varargin)% LPFILTER M-file for lpfilter.fig%LPFILTER, by itself, creates a new LPFILTER or raises the existing%singleton*.%%H = LPFILTER returns the handle to a new LPFILTER or the handle to%the existing singleton*.%%LPFILTER('CALLBACK',hObject,eventData,handles,...) calls the local%function named CALLBACK in LPFILTER.M with the given input arguments.%%LPFILTER('Property','Value',...) creates a new LPFILTER or raises the%existing singleton*. Starting from the left, property value pairs are%applied to the GUI before lpfilter_OpeningFunction gets called. An%unrecognized property name or invalid value makes property application%stop. All inputs are passed to lpfilter_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 lpfilter% Last Modified by GUIDE v2.5 29-Jun- 13:21:40% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @lpfilter_OpeningFcn, ...'gui_OutputFcn', @lpfilter_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin & isstr(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before lpfilter is made visible.function lpfilter_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 lpfilter (see VARARGIN)% Choose default command line output for lpfilterhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes lpfilter wait for user response (see UIRESUME)% uiwait(handles.figure1);%--------------------------------------------------------------------------%设置滤波器长度,beta和截止频率编辑框的初始值%设置窗体的标题set(handles.figure1,'name','FIR低通滤波器');set(handles.edit_N,'string','64');set(handles.edit_beta,'string','5.568');set(handles.edit_fc,'string','0.5');%--------------------------------------------------------------------------%由设置的初始值求取滤波器的理想单位脉冲响应handles.wc=0.5*pi;handles.M=64;handles.hd=ideal_lp(handles.wc,handles.M);%--------------------------------------------------------------------------%绘制滤波器的理想单位脉冲响应axes(handles.axes_hd);n=[0:1:handles.M-1];plot(n,handles.hd);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55title('滤波器理想脉冲响应');axis([0 handles.M-1 min(handles.hd) max(handles.hd)+0.01]);xlabel('n');ylabel('hd(n)');grid on;guidata(hObject,handles);% --- Executes on button press in plot.function plot_Callback(hObject, eventdata, handles)% hObject handle to plot (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------------%从编辑框获取滤波器长度,beta和截止频率的值handles.M = str2double(get(handles.edit_N,'String'));handles.beta = str2double(get(handles.edit_beta,'String'));handles.wc = str2double(get(handles.edit_fc,'String'))*pi;%求取滤波器的理想单位脉冲响应handles.hd=ideal_lp(handles.wc,handles.M);%绘制滤波器的理想单位脉冲响应axes(handles.axes_hd);plot(0,0);n=[0:1:handles.M-1];plot(n,handles.hd);title('滤波器理想脉冲响应');axis([0 handles.M-1 min(handles.hd) max(handles.hd)]);xlabel('n');ylabel('hd(n)');grid on;%--------------------------------------------------------------------------%求取kaiser窗函数handles.w_kai=(kaiser(handles.M,handles.beta))';%绘制kaiser窗函数axes(handles.axes_wkaiser);plot(n,handles.w_kai);title('kaiser窗');axis([0 handles.M-1 min(handles.w_kai) max(handles.w_kai)]);xlabel('n');ylabel('w(n)');grid on;%--------------------------------------------------------------------------%求取滤波器的实际单位脉冲响应handles.h=handles.hd.*handles.w_kai;%绘制滤波器的实际单位脉冲响应axes(handles.axes_h);plot(n,handles.h);title('滤波器实际脉冲响应');axis([0 handles.M-1 min(handles.h) max(handles.h)]);xlabel('n');ylabel('h(n)');grid on;%--------------------------------------------------------------------------%求取滤波器的频率特性,并绘制幅频特性(转换到0—pi)[H,w] = freqz(handles.h,[1],handles.M*6,'whole');% freqz(handles.h,[1],handles.M*6);H=(H(1:1:handles.M*3))';w=(w(1:1:handles.M*3))';mag=abs(H);db=20*log10((mag+eps)/max(mag));% pha=angle(H);%绘制幅频特性(转换到0—pi)axes(handles.axes_lp);plot(w/pi,db);title('FIR滤波器的幅频特性(0-pi)');axis([0 1 min(db) max(db)]);xlabel('Frequency in pi units');ylabel('Decibels');grid on;guidata(hObject,handles);%--------------------------------------------------------------------------%由求得幅频特性计算通带边界,阻带边界,通带纹波和阻带衰减%由beta值计算阻带衰减Asif handles.beta<4.5513As=fzero(@myfun,20,[],handles.beta)+21;elseAs=handles.beta/0.1102+8.7;end%计算通带边界wp,阻带边界wsw_w=(As-7.95)/((handles.M-1)*14.36)*2;ws=0.5*(w_w+2*handles.wc/pi);wp=0.5*(2*handles.wc/pi-w_w);% mag=(mag+eps)/max(mag);%计算通带纹波rp% deta_w=2*pi/(handles.M*6);% w_temp=mag(floor(ws/deta_w));% mag_temp=abs(mag(1:floor(ws/deta_w))-w_temp);rp=20*log10(max(mag));%--------------------------------------------------------------------------%在相应的编辑框中显示通带边界,阻带边界,通带纹波和阻带衰减str=sprintf('%.2f',wp);set(handles.edit_wp,'string',str);str=sprintf('%.2f',ws);set(handles.edit_ws,'string',str);str=sprintf('%.4f',rp);set(handles.edit_rp,'string',str);str=sprintf('%.2f',-As);set(handles.edit_As,'string',str);%--------------------------------------------------------------------------%退出程序function exit_Callback(hObject, eventdata, handles)% hObject handle to exit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)close(handles.figure1);%--------------------------------------------------------------------------%自定义函数,计算理想低通滤波器的单位脉冲响应function hd=ideal_lp(wc,M);alpha=(M-1)/2;n = [0:1:(M-1)];m=n-alpha+eps;hd=sin(wc*m)./(pi*m);% --- Outputs from this function are returned to the command line.function varargout = lpfilter_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 structurevarargout{1} = handles.output;% --- Executes during object creation, after setting all properties.function edit_N_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_N (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_N_Callback(hObject, eventdata, handles)% hObject handle to edit_N (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_N as text% str2double(get(hObject,'String')) returns contents of edit_N as a double% --- Executes during object creation, after setting all properties.function edit_beta_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_beta (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_beta_Callback(hObject, eventdata, handles)% hObject handle to edit_beta (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_beta as text% str2double(get(hObject,'String')) returns contents of edit_beta as a double

四、运行结果

五、matlab版本及参考文献

1 matlab版本

a

2 参考文献

[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,.

[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,.

[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,.

如果觉得《【滤波器】基于matlab GUI高通+低通+带通+带阻FIR滤波器设计【含Matlab源码 699期】》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。