⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lowpass.m

📁 matlab做的可视化界面
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = lowpass(varargin)
% LOWPASS M-file for lowpass.fig
%      LOWPASS, by itself, creates a new LOWPASS or raises the existing
%      singleton*.
%
%      H = LOWPASS returns the handle to a new LOWPASS or the handle to
%      the existing singleton*.
%
%      LOWPASS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LOWPASS.M with the given input arguments.
%
%      LOWPASS('Property','Value',...) creates a new LOWPASS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before lowpass_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to lowpass_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 lowpass

% Last Modified by GUIDE v2.5 23-Nov-2006 17:24:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @lowpass_OpeningFcn, ...
                   'gui_OutputFcn',  @lowpass_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 lowpass is made visible.
function lowpass_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 lowpass (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = lowpass_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 during object creation, after setting all properties.
function Hr_rp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Hr_rp (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 ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function Hr_rp_Callback(hObject, eventdata, handles)
% hObject    handle to Hr_rp (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 Hr_rp as text
%        str2double(get(hObject,'String')) returns contents of Hr_rp as a double


% --- Executes during object creation, after setting all properties.
function Hr_rs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Hr_rs (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 ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function Hr_rs_Callback(hObject, eventdata, handles)
% hObject    handle to Hr_rs (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 Hr_rs as text
%        str2double(get(hObject,'String')) returns contents of Hr_rs as a double


% --- Executes during object creation, after setting all properties.
function Hw_wp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Hw_wp (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 ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function Hw_wp_Callback(hObject, eventdata, handles)
% hObject    handle to Hw_wp (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 Hw_wp as text
%        str2double(get(hObject,'String')) returns contents of Hw_wp as a double


% --- Executes during object creation, after setting all properties.
function Hw_ws_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Hw_ws (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 ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function Hw_ws_Callback(hObject, eventdata, handles)
% hObject    handle to Hw_ws (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 Hw_ws as text
%        str2double(get(hObject,'String')) returns contents of Hw_ws as a double


% --- Executes on button press in Hd_design.
function Hd_design_Callback(hObject, eventdata, handles)
% hObject    handle to Hd_design (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


 fs=str2double(get(handles.Hf_fs,'String'));
rp = str2double(get(handles.Hr_rp,'String'));
rs = str2double(get(handles.Hr_rs,'String'));
ws = str2double(get(handles.Hw_ws,'String'));
wp = str2double(get(handles.Hw_wp,'String'));
as = str2double(get(handles.Hr_rstop1,'String'));
ap = str2double(get(handles.Hr_rpass,'String'));
as2 = str2double(get(handles.Hr_rstop2,'String'));

 if  get(handles.radio_fir,'Value')==1
[type]=selecttype(get(handles.Hl_low,'Value'),get(handles.Hh_high,'Value'),get(handles.Hb_bandpass,'Value'),get(handles.Hb_bandstop,'Value'));
[b,a,n]=fir_filter(fs,wp,ws,rp,rs,as,ap,type);
else
    [type]=selecttype(get(handles.Hl_low,'Value'),get(handles.Hh_high,'Value'),get(handles.Hb_bandpass,'Value'),get(handles.Hb_bandstop,'Value'));
 [b,a,n]=iir_filter(fs,wp,ws,rp,rs,as,ap,type,get(handles.popupmenu2,'Value'));
 end
    
[H,W]=freqz(b,a);
handles.metricdata.b = b;
guidata(hObject,handles)
handles.metricdata.a = a;
guidata(hObject,handles)

axes(handles.Ha_axes1);
plot(W/pi,20*log10(abs(H)));grid on;
figure;freqz(b,a);

% fvtool(b,a);
% --- Executes during object creation, after setting all properties.
function [type]=selecttype(type1,type2,type3,type4)
if type1==1
    type=1;
elseif type2==1
    type=2;
elseif type3==1
    type=3;
else
    type=4;
end
%-----------------------------------------------------------------
function [b,a,n]=fir_filter(fs,wp,ws,rp,rs,as,ap,type)
  N1=abs(ceil(8*pi/(ws/fs-wp/fs)));
    N2=abs(ceil(8*pi/(wp/fs-rp/fs)));
     N3=abs(ceil(8*pi/(wp/fs-ws/fs)));
     N4=abs(ceil(8*pi/(rp/fs-wp/fs)));
    wnl=(ws+wp)/fs/2;
    wnb=(wp+rp)/fs/2;
    wns=(ws+rs)/fs/2;
     a=1;
   
   if type==1
    n=N1; b=fir1(n,wnl);
    elseif type==2
    n=N3;  b=fir1(n,wnl,'high');
    elseif type==3
       n=N2; b=fir1(n,[wnb wns],'bandpass');
    else
       n=N4;  b=fir1(n,[wnb wns],'stop');
    end
%-----------------------------------------------------------------
  function [b,a,n]=iir_filter(fs,wp,ws,rp,rs,as,ap,type,point)
    if type==1
      [b,a,n]=lowfilter(fs,wp,ws,rp,rs,point);
    elseif type==2
        [b,a,n]=highfilter(fs,wp,ws,rp,rs,point);
    elseif type==3
      [b,a,n]=bandpassfilter(fs,wp,ws,rp,rs,as,ap,point);
    else
      [b,a,n]=bandstopfilter(fs,wp,ws,rp,rs,as,ap,point);
    end

  
%-----------------------------------------------------------------
function [b,a,n]=lowfilter(fs,wp,ws,rp,rs,point)
lowpass_sel_index = point;
switch lowpass_sel_index
    case 1
     [n,wn]=buttord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=butter(n,wn);
    case 2
       [n,wn]=cheb1ord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=cheby1(n,rp,wn);
    case 3
            [n,wn]=cheb2ord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=cheby2(n,rp,wn);
    case 4
     [n,wn]=ellipord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=ellip(n,rp,rs,wn);

end

%-----------------------------------------------------------------
   function [b,a,n]=highfilter(fs,wp,ws,rp,rs,point)
lowpass_sel_index = point;
switch lowpass_sel_index
    case 1
     [n,wn]=buttord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=butter(n,wn,'high');
    case 2
       [n,wn]=cheb1ord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
    case 3
            [n,wn]=cheb2ord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=cheby2(n,rp,wn,'high');
    case 4
     [n,wn]=ellipord(wp/fs/2,ws/fs/2,rp,rs);
[b,a]=ellip(n,rp,rs,wn,'high');

end

%-----------------------------------------------------------------

function [b,a,n]=bandpassfilter(fs,wp,ws,rp,rs,as,ap,point)
lowpass_sel_index = point;
switch lowpass_sel_index
    case 1
     [n,wn]=buttord([wp/fs/2 ws/fs/2],[rp/fs/2,rs/fs/2],ap,as);
[b,a]=butter(n,wn);
    case 2
       [n,wn]=cheb1ord([wp/fs/2 ws/fs/2],[rp/fs/2,rs/fs/2],ap,as);
[b,a]=cheby1(n,ap,wn);
    case 3
            [n,wn]=cheb2ord([wp/fs/2 ws/fs/2],[rp/fs/2,rs/fs/2],ap,as);
[b,a]=cheby2(n,ap,wn);
    case 4
     [n,wn]=ellipord([wp/fs/2 ws/fs/2],[rp/fs/2,rs/fs/2],ap,as);
[b,a]=ellip(n,ap,as,wn);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -