CAG2425 Lab 11
CAG2425 Lab 11
*Verify
Example1: Build an interface that does the following:
- represents graphically functions sin, cos and sin+cos in 3 different windows
- allows modifying the amplitudes for sin and cos, frequency and number of
displayed periods
- the variable for sine amplitude is A, for cos amplitude is B, for frequency is f and
number of periods is N
- The initial values are A=10; B=5; f=50 Hz; N=4
- The gui contains a button for CLOSE and a button for RESET (resetting the
characteristics to their initial values)
- The interface should also contain a menu for: displaying the front page, resetting the
characteristics to the initial values, displaying a jpg image and a closing function
%
% main.m file
%
close all;
A=10; % magnitude of signal 1 = sinus
B=5; % magnitude signal 2 = cosinus
f=50; % defining the frequency in Hz
N=4; % number of displayed cycles
%creating a new figure
Fig=figure('Name','Laboratory 11',...
'Units','normalized',...
'NumberTitle','off',...
'Position',[0.1 0.1 0.8 0.8],...
'Color',[0.5 0.5 0.9]);
% pushbuton CLOSE
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.9 0.9 0.08 .05],...
'String','CLOSE',...
'Backgroundcolor','#FAF0E6',...
'ForegroundColor','#800080',...
'FontName','Arial',...
'FontWeight','bold',...
'FontSize',12,...
'Callback','close');
%
% function file interfata
%
function interfata(A,B,f,N)
%
% function file display_pic
%
function display_pic
ax=axes('Position',[0.58 0.5 0.25 0.25]);
imshow('sincos.jpg','Parent',ax )
end
Example2: We present a gui example for the inverting and noninverting amplifier. Consider
a main window having the:
Title Amplifier
3 buttons in the center for:
o Documentation
o Noninverting amplifier
o Inverting amplifiers
o And a Close button on the right down part
The button for the Documentation will open a .pdf, .docx or .html document containing the
theoretical part of the project like title, author, theme, introduction, formulas, calculus, obtained
results, graphics, references, appendixes and whatever you feel the need to add.
The button for Inverting and the button for Noninverting amplifier circuits create a new
figure in each case, but the figure has the same structure and layout.
The two figures contain:
A title
A panel for parameter buttons – name and their values
A panel for chosing the signal to be plotted: sinusoidal or triangular
A figure showing the circuit
A part of the figure window containing the plots for the input and output voltages in
respect to time but also the voltage input-output characteristics.
These windows have also a „Return” button, for returning to the main menu of the GUI.
A menu can be added in the menu bar of the figure or anything else you need to develop and
optimise in your application.
% close button
uicontrol('Style','pushbutton',...
'Units','normalized',...
'FontWeight','bold',...
'Fontsize', 12,...
'BackgroundColor','#D6CADD',...
'Position',[0.85 0.03 0.1 0.06],...
'string','Close',...
'Callback','close');
%
% function file createfig.m
%
function createfig(avin,d,A,R1,R2,Vps1,Vps2,f,N)
% if the user pushed the "Noninverting Amp"
% button, the title of the figure
% becomes "Noninverting Amplifiers"
% and variable avin=0
if avin==0
figurename="NonInverting Amplifiers";
else
%
% function file documentation.m
% opens the documentation file
% here the "Documentation.docx" file
% documentation can be in format
% .pdf, .html, .docx etc
function documentation
open('Documentation.docx');
% end of the documentation.m file
end
%
% function file myInterface.m
%
function myInterface(avin,d,A,R1,R2,Vps1,Vps2,f,N)
% creates a container for the buttons
% of the wave form types=SINUS OR TRIANGLE
Tip_semnal=uibuttongroup('Visible','on',...
'BackgroundColor','#D6CADD',...%[1 1 0.8],...
'ForegroundColor','black',...
'Title','Waveform',...
'FontSize',14,...
'TitlePosition','centertop',...
'Position',[ 0.3 0.6 0.16 0.37]);