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

📄 gmguiiir1.m

📁 数字信号处理:1.卷积 2.抽样 3.滤波器
💻 M
字号:
function varargout = GMGUIIIR1(varargin)
% GMGUIIIR1 M-file for GMGUIIIR1.fig
%      GMGUIIIR1, by itself, creates a new GMGUIIIR1 or raises the existing
%      singleton*.
%
%      H = GMGUIIIR1 returns the handle to a new GMGUIIIR1 or the handle to
%      the existing singleton*.
%
%      GMGUIIIR1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GMGUIIIR1.M with the given input arguments.
%
%      GMGUIIIR1('Property','Value',...) creates a new GMGUIIIR1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GMGUIIIR1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GMGUIIIR1_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 GMGUIIIR1

% Last Modified by GUIDE v2.5 12-Jan-2008 16:36:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GMGUIIIR1_OpeningFcn, ...
                   'gui_OutputFcn',  @GMGUIIIR1_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 GMGUIIIR1 is made visible.
function GMGUIIIR1_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 GMGUIIIR1 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = GMGUIIIR1_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 edit1_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit1 (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'));endfunction edit1_Callback(hObject, eventdata, handles)% hObject    handle to edit1 (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 edit1 as text%        str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% 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)
clear i;Wp=30;
Ws=40;
ap=1;
as=30;
T=Ws/Wp;
K=sqrt((10^(ap/10)-1)/(10^(as/10)-1));
N=ceil(-log10(K)/log10(T));
% N=15;
Wc=min([Wp*(10^(ap/10)-1)^(-1/(2*N)),Ws*(10^(as/10)-1)^(-1/(2*N))]);
for i=1:N
    s(i)=Wc*exp(j*pi*(1/2+(2*(i-1)+1)/(2*N)));
end
string=['Ha(s)=',sprintf('\n%e',Wc^N),'·'];
for i=1:(N-1)/2
    [num,den]=series(1,[1 -s(i)],1,[1 -s(N+1-i)]);
    if den(2)>=0&den(3)>=0
        str=['1/(s^2+',sprintf('%.4f',den(2)),'s+',sprintf('%.4f',den(3)),')·'];
    else
        if den(2)<0&den(3)>=0
            str=['1/(s^2',sprintf('%.4f',den(2)),'s+',sprintf('%.4f',den(3)),')·'];
        else
            if den(2)>=0&den(3)<0
                str=['1/(s^2+',sprintf('%.4f',den(2)),'s',sprintf('%.4f',den(3)),')·'];
            else
                str=['1/(s^2',sprintf('%.4f',den(2)),'s',sprintf('%.4f',den(3)),')·'];
            end
        end
    end
    string=strvcat(string,str);
end
if s(i+1)>=0    
    str=['1/(s',sprintf('%.4f',-s(i+1)),')'];
else
    str=['1/(s+',sprintf('%.4f',-s(i+1)),')'];
end    
string=strvcat(string,str);
set(handles.edit1,'string',string);

zz=[],pp=s,k=Wc^N;% 零点、极点、增益
[b,a]=zp2tf(zz,pp,k);
[r,p,h]=residue(b,a);
t=0:0.01:2;
h=zeros(1,length(t));
for i=1:N
    h=h+r(i)*exp(p(i)*t);
end
w=0:100;
H=freqs(b,a,w);
axes(handles.axes1),plot(w,abs(H));
set(handles.axes1,'Xtick',[0 30 40 100],'Ytick',[0 0.89 1]);
title('幅频特性');
xlabel('频率(rad/s)');
ylabel('幅度');
grid;
axes(handles.axes2),plot(w,20*log10(abs(H)));
set(handles.axes2,'Xtick',[0 30 40 100],'Ytick',[-100 -30 -1]);
axis([0 100 -100 0]);
title('幅频衰减特性     衰减(dB)');
xlabel('频率(rad/s)');
grid;
axes(handles.axes3),plot(w,unwrap(angle(H))/pi);
set(handles.axes3,'Xtick',[0 30 40 100],'Ytick',[-4.8852 -3.4692 0]);
title('相频特性     相位(π)');
xlabel('频率(rad/s)');
grid;
axes(handles.axes4),plot(t,h/100);
title('脉冲响应特性');
xlabel('t(s)');
ylabel('ha(t)');

⌨️ 快捷键说明

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