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

📄 gmguiiir3.m

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

% Last Modified by GUIDE v2.5 14-Jan-2008 22:39:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GMGUIIIR3_OpeningFcn, ...
                   'gui_OutputFcn',  @GMGUIIIR3_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 GMGUIIIR3 is made visible.
function GMGUIIIR3_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 GMGUIIIR3 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = GMGUIIIR3_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)% 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;
fp=1500;
fs=2000;
Wpp=2*pi*fp;
Wss=2*pi*fs;
ap=3;
as=40;
Fs=8000;
wp=Wpp/Fs;
ws=Wss/Fs;
Wp=2*Fs*tan(wp/2);
Ws=2*Fs*tan(ws/2);
Tp=1;
Ts=Ws/Wp;
e=sqrt(10^(ap/10)-1);
A=10^(as/20);
G=sqrt((A^2-1)/e^2);
N=ceil((log10(G+sqrt(G^2-1)))/(log10(Ts+sqrt(Ts^2-1))));
% N=7
Wc=Wp;
ar=1/e+sqrt(1+1/e^2);
a=0.5*(ar^(1/N)-(1/ar)^(1/N));
b=0.5*(ar^(1/N)+(1/ar)^(1/N));
kk=1;
for i=1:N
    s(i)=a*Wc*cos(pi/2+(2*i-1)*pi/(2*N))+j*b*Wc*sin(pi/2+(2*i-1)*pi/(2*N));
    pp(i)=(2*Fs-s(i))/(2*Fs+s(i));
    kk=-kk/(2*Fs+s(i));
end
zz=conj(repmat(-1,1,N))';
% 零点、极点、增益
[f,g]=zp2tf(zz,pp,kk);
f=fliplr(f);
g=fliplr(g);
g0=[g,0];
[H,w]=freqz(f,g,101);
K=1/max(abs(H));
[r,p,hh]=residue(f,g0);
n=0:100;
h=zeros(1,length(n));
for i=1:N+1
    for n=0:100
        h(n+1)=h(n+1)+r(i)*p(i)^n;
    end
end
axes(handles.axes1),plot(Fs*w/(2*pi),20*log10(K*abs(H)));
set(handles.axes1,'Xtick',[0 1500 2000 4000],'Ytick',[-40 -3]);
axis([0 4000 -60 0]);
title('幅频衰减特性');
xlabel('频率(Hz)');
ylabel('衰减(dB)');
grid;
axes(handles.axes2),stem(0:100,K*h,'.');
title('脉冲响应特性');
xlabel('n');
ylabel('h(n)');

⌨️ 快捷键说明

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