1. 程式人生 > 其它 >【濾波器】基於matlab GUI IIR+FIR數字濾波器設計【含Matlab原始碼 698期】

【濾波器】基於matlab GUI IIR+FIR數字濾波器設計【含Matlab原始碼 698期】

一、簡介

1 設計原理

1.1 濾波器概念

1.2 數字濾波器的系統函式和差分方程

1.3 數字濾波器結構的表示


1.4 數字濾波器的分類


2.1 IIR濾波器與FIR濾波器的分析比較

2.2 FIR濾波器的原理









3 FIR濾波器的模擬步驟

二、原始碼

function varargout = filter_2(varargin)
% FILTER_2 MATLAB code for filter_2.fig
%      FILTER_2, by itself, creates a new FILTER_2 or raises the existing
%      singleton*.
%
%      H = FILTER_2 returns the handle to a new FILTER_2 or the handle to
%      the existing singleton*.
%
%      FILTER_2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FILTER_2.M with the given input arguments.
%
%      FILTER_2('Property','Value',...) creates a new FILTER_2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before filter_2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to filter_2_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 filter_2

% Last Modified by GUIDE v2.5 16-May-2013 12:02:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @filter_2_OpeningFcn, ...
    'gui_OutputFcn',  @filter_2_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 filter_2 is made visible.
function filter_2_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 filter_2 (see VARARGIN)
global response;
global analog;
global window1;
global digital;
global analog_choose;

response=1;
analog=1;
analog_choose=1;
window1=1;
digital=1;

%set(handles.function_value,'String','Butterworth');
%set(handles.method_value,'String','direct form');
set(handles.order,'Enable','off');

% Choose default command line output for filter_2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes filter_2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = filter_2_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 IIR_button.
function IIR_button_Callback(hObject, eventdata, handles)
% hObject    handle to IIR_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global  analog_choose;
global response;
global analog;
if(get(hObject,'Value')==1)  %當選中IIR時遮蔽FIR模組
    set(handles.order_information,'String','order');
    set(handles.FIR_button,'Value',0);
    set(handles.filter_information,'String','IIR');
    set(handles.window_function,'Enable','off');
    set(handles.order,'Enable','off');
    set(handles.view_window,'Enable','off');
    set(handles.analog_filter,'Enable','on');
    set(handles.Apass,'Enable','on');
    set(handles.Astop,'Enable','on');
    set(handles.order,'Enable','off');
    
     set(handles.specify_order,'Enable','on'); set(handles.specify_order,'Value',0);%對階數的處理
         set(handles.custom_order,'Enable','on');set(handles.custom_order,'String','');
        set(handles.min_order,'Enable','on');set(handles.min_order,'Value',0);
    
    %get(handles.analog_method,'Value');
    if( analog_choose==1)
        set(handles.method_value,'String','direct form');
    else
        set(handles.method_value,'String','bilinear');
    end
    switch(analog)
        case 1
            set(handles.function_value,'String','Butterworth');
        case 2
            set(handles.function_value,'String','chebyshev1');
        case 3
            set(handles.function_value,'String','chebyshev2');
    end
    switch(response)
        case 1
            set(handles.type_information,'String','Lowpass');
        case 2
            set(handles.type_information,'String','Highpass');
        case 3
            set(handles.type_information,'String','Bandpass');
        case 4
            set(handles.type_information,'String','Bandstop');
    end
else
    set(handles.window_function,'Enable','on');
    set(handles.order,'Enable','on');
    set(handles.view_window,'Enable','on');
    set(handles.order,'Enable','on');
end
% Hint: get(hObject,'Value') returns toggle state of IIR_button


% --- Executes on button press in FIR_button.
function FIR_button_Callback(hObject, eventdata, handles)
% hObject    handle to FIR_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global digital;
global response;
global window1;

if(get(hObject,'Value')==1)  %當選中FIR時遮蔽IIR模組
    set(handles.IIR_button,'Value',0);
    set(handles.filter_information,'String','FIR');
    set(handles.window_function,'Enable','on');
   % set(handles.order,'Enable','on');
    set(handles.view_window,'Enable','on');
    set(handles.analog_filter,'Enable','off');
    set(handles.Apass,'Enable','off');
    set(handles.Astop,'Enable','off');
    %set(handles.order,'Enable','on');
   
   if(digital==2)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%處理階數
        set(handles.specify_order,'Enable','off');
        set(handles.custom_order,'Enable','off');
        set(handles.min_order,'Enable','off');
        set(handles.window_function,'Enable','off');
        set(handles.view_window,'Enable','off');
        set(handles.order_information,'String','sample')
        set(handles.order,'Enable','on');
        end 
    
    switch(response)
        case 1
            set(handles.type_information,'String','Lowpass');
        case 2
            set(handles.type_information,'String','Highpass');
        case 3
            set(handles.type_information,'String','Bandpass');
        case 4
            set(handles.type_information,'String','Bandstop');
    end
    if(digital==1)
        set(handles.method_value,'String','window');
    else
        set(handles.method_value,'String','FSI');
    end
    switch(window1)
        case 1
            set(handles.function_value,'String','Hamming');
        case 2
            set(handles.function_value,'String','Blackman');
        case 3
            set(handles.function_value,'String','Hann');
        case 4
            set(handles.function_value,'String','Rectangular');
    end
else
    set(handles.analog_filter,'Enable','on');
    set(handles.Apass,'Enable','on');
    set(handles.Astop,'Enable','on');
    set(handles.order,'Enable','off');
    
end
% Hint: get(hObject,'Value') returns toggle state of FIR_button


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over filter_information.
function filter_information_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to filter_information (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

三、執行結果


四、備註

版本:2014a
完整程式碼或代寫加1564658423