Document

advertisement
SIGPRO011L-C11-09
MEMBERS
1. De Castro, Dominico Roi R
2. Jacaban, Clea Dell L.
12 February 2005
SIGNATURE
Engr. Leonardo Valiente Jr.
Instructor.
Building a Graphical User Interface
Experiment 5
Practice Exercises
%file pb1.m
f=250;
Fs=5000;
t=0:100;
y=sin(2*pi*f*t/Fs);
stem(t,y);
%file pb2m
f=500;
Fs=5000;
t=0:100;
y=sin(2*pi*f*t/Fs);
stem(t,y);
%file pb3m
f=1000
Fs=5000;
t=0:100;
y=sin(2*pi*f*t/Fs);
stem(t,y);
30+10=
40
%file pb4m
f=2000;
Fs=5000;
t=0:100;
y=sin(2*pi*f*t/Fs);
stem(t,y);
function varargout = dominico(varargin)
% DOMINICO M-file for dominico.fig
% DOMINICO, by itself, creates a new DOMINICO or raises the
existing
% singleton*.
%
% H = DOMINICO returns the handle to a new DOMINICO or the
handle to
% the existing singleton*.
%
% DOMINICO('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in DOMINICO.M with the given input
arguments.
%
% DOMINICO('Property','Value',...) creates a new DOMINICO or raises
the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before dominico_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to dominico_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help dominico
% Last Modified by GUIDE v2.5 19-Feb-2005 17:45:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @dominico_OpeningFcn, ...
'gui_OutputFcn', @dominico_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 dominico is made visible.
function dominico_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 dominico (see VARARGIN)
% Choose default command line output for dominico
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes dominico wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = dominico_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;
% -------------------------------------------------------------------function Untitled_8_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
250 Hz
500Hz
100Hz
2000Hz
Program (m-file)
function varargout = exp5(varargin)
% EXP5 Application M-file for exp5.fig
% FIG = EXP5 launch exp5 GUI.
% EXP5('callback_name', ...) invoke the named callback.
% Last Modified by GUIDE v2.0 19-Feb-2005 20:19:42
if nargin == 0 % LAUNCH GUI
fig = openfig(mfilename,'reuse');
% Generate a structure of handles to pass to callbacks, and store it.
handles = guihandles(fig);
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL
switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and
%| sets objects' callback properties to call them through the FEVAL
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback. You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks. Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
% -------------------------------------------------------------------function varargout = popupmenu_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = n_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = fc1_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = fc2_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = Filter_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = Lowpass_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = Highpass_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = Bandpass_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = Bandstop_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = fs_Callback(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = axes1_CreateFcn(h, eventdata, handles, varargin)
% -------------------------------------------------------------------function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)
n1=findobj(gcf,'Tag','n');
n2=str2num(get(n1,'string'));
fca=findobj(gcf,'Tag','fc1');
fca1=str2num(get(fca,'string'));
fcb=findobj(gcf,'Tag','fc2');
fcb1=str2num(get(fcb,'string'));
fs1=findobj(gcf,'Tag','fs');
fs2=str2num(get(fs1,'string'));
z=findobj(gcf,'Tag','popupmenu');
type=get(z,'Value');
if type==2
wn=fca1/(fs2/2);
[b,a]=fir1(n2,wn,'low');
axes(handles.axes1);
[h w]=freqz(b,a);
plot(20*log10(abs(h)));
axes(handles.axes2);
zplane(b,a);
elseif type==3
wn=fca1/(fs2/2);
[b,a]=fir1(n2,wn,'high');
axes(handles.axes1);
[h w]=freqz(b,a);
plot(20*log10(abs(h)));
axes(handles.axes2);
zplane(b,a);
elseif type==4
wn=[fca1 fcb1]*2/fs2;
[b,a]=fir1(n2,wn,'bandpass');
axes(handles.axes1);
[h w]=freqz(b,a);
plot(20*log10(abs(h)));
axes(handles.axes2);
zplane(b,a);
elseif type==5
wn=[fca1 fcb1]*2/fs2;
[b,a]=fir1(n2,wn,'stop');
axes(handles.axes1);
[h w]=freqz(b,a);
plot(20*log10(abs(h)));
axes(handles.axes2);
zplane(b,a);
else
end
Figure File (screen capture)
Sample Output
Lowpass
Highpass
Bandpass
Bandstop
Download