Anda di halaman 1dari 32

ABSTRACT

Removing noise from audio signals requires a nondiagonal processing of time-frequency


coefficients to avoid producing musical noise. State of the art algorithms perform a
parameterized filtering of spectrogram coefficients with empirically fixed parameters. A Blind
Source Separation procedure is introduced, which adjusts all parameters adaptively to signal
property by minimizing a Stein estimation of the risk. Numerical experiments demonstrate the
performance and robustness of this procedure through objective and subjective evaluations.

In adaptive blind source separation, the order of recovered source signals is unpredictable due to
order indeterminacy. However, it is sometimes desired that the reconstructed source signals be
arranged in specified order according to their stochastic properties. To this end, some asymmetry
is introduced to the equilibrium point, and a new unsymmetrical natural gradient algorithm is
proposed, which can separate the source signals in desired order. The validity of the proposed
algorithm is confirmed through extensive computer simulations.














CHAPTER 1

Introduction

1.1 Introduction to Speech Denoising

Based on the fact that noise and distortion are the main factors that limit the capacity of
data transmission in telecommunications and that they also affect the accuracy of the results
in the signal measurement systems, whereas, modeling and removing noise and distortions
are at the core of theoretical and practical considerations in communications and signal
processing.

Another important issue here is that, noise reduction and distortion removal are major
problems in applications such as; cellular mobile communication, speech recognition, image
processing, medical signal processing, radar, sonar, and any other application where the
desired signals cannot be isolated from noise and distortion. The use of wavelets in the field
of de-noising audio signals is relatively new, the use of this technique has been increasing
over the past 20 years.

One way to think about wavelets matches the way how our eyes perceive the world when
they are faced to different distances. In the real world, a forest can be seen from many
different perspectives; they are, in fact, different scales of resolution. From the window of
an airplane, for instance, the forest cover appears as a solid green roof. From the window of
a car, the green roof gets transformed into individual trees, and if we leave the car and
approach to the forest, we can gradually see details such as the trees branches and leaves. If
we had a magnifying glass, we could see a dew drop on the tip of a leaf. As we get closer to
even smaller scales, we can discover details that we had not seen before.



On the other hand, if we tried to do the same thing with a photograph, we would be
completely frustrated. If we enlarged the picture "closer" to a tree, we would only be able to
see a blurred tree image; we would not be able to spot neither the branch, nor the leaf, and it
would be impossible to spot the dew drop. Although our eyes can see on many scales of
resolution, the camera can only display one at a time.

In this chapter, we introduce a way to reduce noise in an audio signal by using
wavelet transforms. We developed this technique by using the wavelet tool in MATLAB. A
Simulink is used to acquire an audio signal and we use it to convert the signal to a digital
format so it can be processed. Finally, a Graphical User Interface Development
Environment (GUIDE) is used to create a graphical user interface.


1.2 Denoising Speech Signals by Wavelet Transform

Here is presented an investigation of the use of wavelet theory for practical signal denoising.
This study is a research for speech enhancement for the needs of small portable devices and
particularly hearing-aid devices.

Fourier transform based spectral analysis is the dominant analytical tool for frequency
domain analysis. However, Fourier transform cannot provide any information of the spectrum
changes with respect to time. Fourier transform assumes the signal is stationary, but speech
signal is always non-stationary. To overcome this deficiency, a modified method-short time
Fourier transform allows to represent the signal in both time and frequency domain through time
windowing function. The window length determines a constant time and frequency resolution.
Thus, a shorter time windowing is used in order to capture the transient behavior of a signal; we
sacrifice the frequency resolution. The nature of the real speech signals is nonperiodic and
transient; such signals cannot easily be analyzed by conventional transforms. So, an alternative
mathematical tool wavelet transform must be selected to extract the relevant time-amplitude
information from a signal. In the meantime, we can improve the signal to noise ratio based on
prior knowledge of the signal characteristics.
1.2.1 Wavelet Denoising

Wavelet denoising is considered a non-parametric method. Thus, it is distinct from parametric
methods in which parameters must be estimated for a particular model that must be assumed a
priori. Assume that the observed data

X (t) = S(t)+ N(t) (1.1)

contains the true signal S(t) with additive noise N(t) as functions in time t to be sampled. Let W()
and W1() denote the forward and inverse wavelet transform operators. Let D(,) denote the
denoising operator with to recover (t) as an estimate of S(t). Then the three steps

Y =W(X ) (1.2)

Z = D(Y, ) (1.3)

S =W
1
(Z) (1.4)

summarize the procedure. Of course, this summary of principles does not reveal the details of
implementing the operators W or D, or selection of the threshold . B. Wavelet Transform In this
work, we stated only some keys equations and concepts of wavelet transform, more rigorous
mathematical treatment of this subject can be found in equation 1.2. Continuous-time wavelet
transform of f(t) is defined as:


CWT

f (a, b)= W

(b, a)=a
-1/2
()

/dt (1.5)




Here a, b R, a 0 and they are dilating and translating coefficients, respectively. This
multiplication of |a|-1/2 is for energy normalization purposes so that the transformed signal will
have the same energy at every scale. The analysis function (t), the so-called mother wavelet,
has to satisfy that it has a zero net area, which suggest that the transformation kernel of the
wavelet transform is a compactly support function (localized in time).

One drawback of the CWT is that the representation of the signal is often redundant,
since a and b are continuous over R (the real number). The original signal can be completely
reconstructed by a sample version of Wf (b,a).

Typically, we sample Wf (b,a) in dyadic grid, i.e., a = 2
-m
and b = n2
-m
, m,n Z+.
Substituting the last one into (1.5):

CWT

f (a, b)= ()

dt (1.6)

where m,n(t) = 2
-m
(2
m
t-n) is the dilated and translated version of the mother wavelet (t).
Due to the orthonormal properties, there is no information redundancy in the discrete wavelet
transform.

In addition, with this choice of a and b, there exists the multiresolution analysis (MRA)
algorithm, which decompose a signal into scales with different time and frequency resolution.
The differences between different mother wavelet functions (e.g. Haar, Daubechies, Coiflets,
Symlet, Biorthogonal and etc.) consist in how these scaling signals and the wavelets are defined.
The choice of wavelet determines the final waveform shape; likewise, for Fourier transform, the
decomposed waveforms are always sinusoid. The wavelet decomposition results in levels of
approximated and detailed coefficients. The algorithm of wavelet signal decomposition and
reconstruction of the signal from the wavelet transform is illustrated in numerous sources.




1.2.2 Thresholding

Let's say that the data has sample size n if it has been sampled at n points ti such that Xi
X(ti). Then for an orthogonal W, there will also be n transform coefficients Yj. If we prefer to use
a threshold (such as the minimax threshold or the universal threshold) that depends only on n,
then can be predetermined and we can use the three-step denoising procedure already
described. However, if we prefer to use a data-adaptive threshold
= d(U ) (1.7)

such as the threshold selected by Stein's Unbiased Risk Estimator (SURE)) that depends not just
on n but on U (which again represents the data in any generic domain), then we must use a four-
step procedure

There are four common rules for selecting the threshold in practice: heursure, minimax,
rigsure and sqtwolog. Minimax and SURE threshold selection rules are moreconservative and
would be more convenient when small details of the signal lie near the noise range. The two
other rules remove the noise more efficiently.

On the other side, thresholding can be done in different ways. Most popular techniques
are hard thresholding and soft thresholding (Fig. 1.1). Hard thresholding is the simplest method
but soft one has nice mathematical properties.


Figure 1.1-Hard Thresholding

Hard thresholding can be described as the usual process of setting to zero the elements whose
absolute values are lower than the threshold. The hard threshold signal is x if x > , and is 0 if x
<= . Soft thresholding is an extension of hard thresholding, first setting to zero the elements
whose absolute values are lower than the threshold, and then shrinking the nonzero coefficients
towards 0. The soft threshold signal is

sign(x)(x ) if x > and is 0 if x <= .

A subpart of 30 records has a narrowband duplicate sampled at 8 kHz. They are contaminated
with different types of noise from a couple of common noisy environments, (listed in Table 1.1).
The noise is added to the speech signal in four particular SRNs: (15 dB, 10 dB, 5 dB, 0 dB). The
so produced pairs of reference and noisy signals are used for evaluating wavelet transform
denoising.


Table 1.1- Common Noisy Environment







1.1.3 Overview of algorithm:

1. Read sound file, for example .wav file from the directory
2. Decide what length of the signal want to analyze, here we have chosen 60,000 and it is
not necessary to analyze entire signal.
3. Next wavedec performs wavelet decomposition of the signal.
4. For denosing one need to give some parameters, like some threshold value. Those
elements in the signal whose value is lower than the threshold is made zero.
5. Plot the figure.











Figure 1.2: Flowchart of denoising of signal

Input the noisy audio signal to be denoised
Decide the length of the signal that has to be denoised (may not
be the entire signal)
Perform the decomposition of the signal using wavedec function in matlab
Denoise the noisy signal using wavelet transformation
Plot the figure of denoised signal
End
Chapter 2
Wavelet Transformation
2.1 Wavelet Families
The Wavelet Toolbox software includes a large number of wavelets that we can use for both
continuous and discrete analysis. For discrete analysis, examples include orthogonal wavelets
(Daubechies extremal phase and least asymmetric wavelets) and B-spline biorthogonal
wavelets. For continuous analysis, the Wavelet Toolbox software includes Morlet, Meyer,
derivative of Gaussian, and Paul wavelets.

The choice of wavelet is dictated by the signal or image characteristics and the nature of the
application. If you understand the properties of the analysis and synthesis wavelet, you can
choose a wavelet that is optimized for your application.

Wavelet families vary in terms of several important properties. Examples include:

Support of the wavelet in time and frequency and rate of decay.

Symmetry or anti symmetry of the wavelet. The accompanying perfect reconstruction filters
have linear phase.

Number of vanishing moments. Wavelets with increasing numbers of vanishing moments result
in sparse representations for a large class of signals and images.

Regularity of the wavelet. Smoother wavelets provide sharper frequency resolution.
Additionally, iterative algorithms for wavelet construction converge faster.

Existence of a scaling function, .
For continuous analysis, the Wavelet Toolbox software provides a Fourier-transform
based analysis for select analysis and synthesis wavelets. Signal Reconstruction from Continuous
Wavelet Transform Coefficients illustrates the use of the inverse continuous wavelet transform
(CWT) for simulated and real-world signals.

Entering waveinfo at the command line displays a survey of the main properties of
available wavelet families. For a specific wavelet family, use waveinfo with the wavelet family
short name. You can find the wavelet family short names listed in the following table and on the
reference page for wave info.


To display detailed information about the Daubechies least asymmetric orthogonal
wavelets, enter: waveinfo ('sym')
To compute the wavelet and scaling function (if available), use wavefun.

2.2 Threshold selection
There are many existing formulas for obtaining threshold value. In this section we review some of
the most popular of them. In all these formulas is the threshold value

2.2.1Universal method:
Donoho and Johnstone derived a general optimal universal threshold for the white Gaussian
noise under a mean square error criterion and its side condition that with high probability, the
enhanced signal f is at least as smooth as the clean signal f [3, 4]. In this method threshold is
selected as:

= () (2.1)

In this formula n is number of samples in the noisy signal and is the standard deviation of
noise that
is estimated by the relation [2]

,
()

- (2.2)

In which Yij is the first level detail coefficients of wavelet transform of noisy speech.
This method tries to optimize the performance as measured by the risk function
In practice, the threshold value obtained by this method is not ideal for speech signals due the
poor correlation between MSE and subjective quality and the more realistic presence of
correlated noise

2.2.2 Minimax method:
In this method that is also proposed by Donoho and Johnstone, it supposed that Y = N(,1) is
the observation, then is selected such that minimizes the following relation

*
(()

)+ (2.3)

2.2.3 SURE method

SURE or Stein Unbiased Risk is also introduced by Donoho and Johnstone for wavelet
de-noising, this method denoises wavelet coefficients so that the mean squared error is
minimized, where MSE is estimated by Stein's unbiased risk estimator based on the variance of
the coefficients.

2.2.4 Proposed Energy-Estimation method
Suppose { f i } and { z i } are the clean speech and noise processes respectively, those are related
with noisy signal samples as:

y i f i z I (2.4)

In which{ z i } is a zero-mean, white Gaussian noise with standard derivation and independent of{ f i }
As noise and clean speech are independent and as their standard derivations represent their power, we
have:

P y P f P z (2.5)

Where P represents the power of the signal. Therefore for a specific frame we have:

E y E f E z (2.6)

Where E is the signal energy in the current frame.
The relation between the wavelet coefficients for our signal processes is:

W y W f W z (2.7)

Where W is the wavelet transform. Therefore by using the wavelet transform properties and using the
(1.6),we have:

EW EWf E Wz (2.8)

that shows the relation between the signals energy in wavelet domain.
Therefore, from the speech and noise signals properties and wavelet transform characteristics we have:

E Wy = E f + Ez (2.9)

That means the energy of the noisy speech frame in the wavelet domain is equal to sum of clean signal
energy and noise energy in the time domain.











Chapter 3
BLIND SOURCE SEPARATION
3.1 Introduction
Blind source separation, also known as blind signal separation, is the method of separation of
a set of source signals from a set of mixed signals, without the aid of information (or with very
little information) about the source signals or the mixing process.
This problem is in general highly underdetermined, but useful solutions can be derived
under a surprising variety of conditions. Much of the early literature in this field focuses on the
separation of temporal signals such as audio. However, blind signal separation is now routinely
performed on multidimensional data, such as images and tensors, which may involve no time
dimension whatsoever.
Since the chief difficulty of the problem is its under determination, methods for blind source
separation generally seek to narrow the set of possible solutions in a way that is unlikely to
exclude the desired solution.
In one approach, exemplified by principal and independent component analysis, one
seeks source signals that are minimally correlated or maximally independent in a probabilistic
or information-theoretic sense.
A second approach, exemplified by nonnegative matrix factorization, is to impose
structural constraints on the source signals. These structural constraints may be derived from a
generative model of the signal, but are more commonly heuristics justified by good empirical
performance. A common theme in the second approach is to impose some kind of low-
complexity constraint on the signal, such as sparsity in some basis for the signal space. This
approach can be particularly effective if one requires not the whole signal, but merely its most
salient features.



3.2 Methods of Blind Signal Separation
There are different methods of blind signal separation:
Principal components analysis
Singular value decomposition
Independent component analysis
Dependent component analysis
Non-negative matrix factorization
Low-complexity coding and decoding
Stationary subspace analysis
Common spatial pattern

3.3 Problem
Let us consider unknown source signals s
i
(t), i= 0,1,2n,which are mutually in- dependent. It
is assumed that the sources s
i
(t) are stationary processes and each source has moments of any
order with a zero mean. The model for the output is
x(t) = As(t) (3.1)

where A R
nxn
is an unknown non-singular mixing matrix, s(t) =[s
1
(t),s
2
(t)s
n
(t)]
T
and
x(t)=[x
1
(t),x
2
(t)x
n
(t)]
T
.

Without knowing the source signals and the mixing matrix, we want to recover the original
signals from the observations x(t) by the following linear transform:

y(t) = Wx(t) (3.2)

where y(t) = [y
1
(t)..y
n
(t)]
T
and W R
nxn
is a de-mixing matrix.

It is impossible to obtain the original sources s
i
(t) because they are not identical in the statistical
sense. However, except for a permutation of indices, it is possible to obtain c
i
s
i
(t) where the
constants c
i
are indefinite nonzero scalar factors. The source signals are identifiable in this sense.
So our goal is to find the matrix W such that [y
1
,..,y
n
] coincides with a permutation of
[s
1
,,s
n
] except for the scalar factors. The solution W is the matrix which finds all independent
components in the outputs.

3.4 EASI and RLS
EASI : Equivariant Adaptive Separation by Independence
RLS : Recursive Least-Squares
















CHAPTER 4
GRAPHICAL USER INTERFACE
4.1 What is GUI?
A user interface is the point of contact or method of interaction between a person and a
computer or computer program. It is the method used by the computer and user to exchange
information. The computer displays text and graphics on the computer screen and may generate
sound with the speaker. The user communicates with the computer by using an input such as
keyboard, mouse, trackball, Computer OS or application. Often a computer or program is chosen
on the basis of pleasing design and the functional efficiency of its user interface.
It is a user interface incorporating graphics objects such as windows, icons, buttons,
menus and text. Selecting or activating these objects in some way usually causes an action or
change to occur. The most common activation method is to use a mouse or other pointing device
to control the movement of a pointer on the screen and to press a mouse button to signal object
selection or some other action.
Predefined dialog boxes:
Essentially, every computer application offers the capability to open and save data files.
To navigate the dictionary structure OS or windows managers provide dialog boxes to perform
the task of identifying file names and dictionary paths. In MATLAB, these tasks are performed
by the functions uigetfile, uiputfile and uigetdir. None of these functions actually opens or saves
files. All they do is return a file name or a dictionary path that can be used along with the low
level I/O functions. These dialog boxes match the operation of standard OS dialog boxes that
identify files for operating and saving and for choosing dictionaries. For example, using uigetfile
to find the startup.m file on the authors computer produces the following result.
>> [fname.dirpath] =uigetfile(*.m)
fname=
startup.m
dirpath=
C:\matlabR14\work\
Appending the file name to the dictionary path gives the unique file specifications for startup.m:
>> myfile =[dirpath fname]
myfile=
C:\matlabR14\work\startup.m
Using uiputfile to save a MAT-file in the work dictionary on the authors computer produces the
following result:
>> fc =uisetfont
fc=
FontName: Palatino
FontUnits: Points
FontSize: 12
FontWeight: normal
FontAngle: italic
Here, fc is a structure containing the feature chosen in the uisetfont GUI. The results are in the
proper from to set the font properties of any text object.
4.2 GUI Creation Fundamentals
The fundamental steps of GUI creation are as follows:
1. Understand what you want the GUI to do. This often the most difficult step. In many
cases, what you want the GUI to do changes as new ideas and options are discovered
during GUI construction
2. Sketch the GUI layout, now on the basis of final sketch; create the GUI using UI objects.
This can be done by creating a code in an M-file. Alternatively, the MATLAB Graphical
User Interface Development (GUIDE) can be used.
3. Create a MATLAB code that is executed when a user interacts with the GUI. This
callback code is most often contained in the same M-file as the code that creates the GUI.
4. Test and debug the GUI. In particular if the GUI will be used by others, try interacting
with the GUI in ways that you never intended yet in ways a less knowledge user may
actually use it.

GUIDE:
It stands for Graphical User Interface Development Environment. It is a tool that has
been designed to make building your own GUIs easier, faster and more consistent. To create,
place, align and resize UI objects, the function guide provides a property editor and inspector
that lists object properties and lets the user modify these properties interactively and a menu
editor for interactive editing and rearranging defined pull-down and contextual menus. GUIDE
stores the graphical user interfaces in a FIG-file and creates an M-file to initiate the GUI and
store the code used for callbacks. GUIDE has improved considerably with every MATLAB
release. At this point GUIDE works well and creates easily debugged and maintainable GUIs.
The only weakness of GUIDE is the wealth of knowledge to understand all the nuances involved
in creating the well functioning GUI that does exactly what is desired.

OBJECTS:
HANDLE graphics is based on the idea that every component of a MATLAB graphic is
an object that each object has a unique identifier or handle associated with it, and that each object
has properties that can be modified as desired. Here the term object is defined as a closely related
collection of data and functions that form a unique whole. In MATLAB, a graphics object is a
distinct component that can be manipulated individually. All plotting and graphics in MATLAB
create graphic objects. Some produces composite objects, and some produce core objects.
Graphical objects in MATLAB are arranged in a hierarchy of parent objects and associated child
objects. The computer screen itself is the root object and the parent of everything else, one or
more figure objects are children of the root. The objects axes, annotation axes and the collection
of core objects are children of axes. All objects that are children of figure objects in the hierarchy
except for the core objects are called composite objects.

OBJECT HANDLES:
In MATLAB each object has an associated identifier called a handle which is a double
precision number. Each time an object is created a unique handle is created for it. For the handle
of the root object the computer screen is always zero. The Hf_fig=figure command and creates a
new figure and returns its handle in the Hf_fig variable. Figure handles are normally integers and
are usually displayed in the figure window title bar. Other objects handles are typically non
integer numbers in full MATLAB precision. All object creation functions return the handles of
the objects they create.

OBJECT PROPERTIES:
All objects have a set of properties that define their characteristics. It is by setting these
properties that you modify how graphics are displayed. The properties associated with each
object type are unique although a number of property names are common to all objects. Object
properties include characteristics such as objects position, color, object type, parent object
handle, child object handle and many others. Each distinct object has properties associated with
it that can be changed without affecting other objects of the same type. Object properties consist
of property names and their associated property values. Property names are character strings.
They are typically displayed in mixed case, with the initial letter of each word capitalized. For
example, the property name Linestyle identifies the line style for a line object. In addition , you
need to use only enough characters to uniquely identify the property name. For example, the
position property of an axes object can be called Position, position or even pos.

FINDING OBJECTS:
Handle graphics provides access to objects in a figure and allows the user to customize
graphics by using the getset commands. The use of these functions requires to know the handle
of the objects to be manipulated. In cases where handles are unknown, MATLAB provides a
number of functions for finding object handles. Two of these functions, gcf and gca were
introduced earlier.
For example:

>> Hf_fig=gcf
Returns the handle of the current figure.

>>Hoax=gca
Returns the handle of the current axes in the current figure.

>>Hx_obj=gco
Returns the handle of the current object in the current figure; alternatively,

>>.Hx_obj=gco(Hf_fig)
Returns the handle of the current object in the figure associated with the handle.Hf_fig. Once an
object handle has been obtained the object type can be found by queuing an objects.Type
property which is a character-string object name such as figure, axes or text. The Type
property is common to all objects.
It is possible to hide specific handles by using the HandleVisibility property common to
all objects. The property is convenient because it keeps the user from inadvertently deleting or
changing the properties of an object. When an object has its HandleVisibility. Property set to
off or to callback, findobj does not return handles to the objects when called from the
command windows. Hidden handles do not appear in list of children. However, when the
property is said to callback these handles can be found during the execution of a callback.

4.3 Selecting Objects with the mouse

The gco command returns the handle of the current object which is the last object clicked on
with the mouse. When a mouse click is made near the intersection of more than one object,
MTALAB uses rules to determine which object becomes the current object. Each object has the
selection region associated with it. A mouse click within this region selects the object. For line
objects, the selection regions include the line and all of the area within a 5-pixel distance from
the line. The region of axes objects is the axes box itself plus the areas where labels and titles
appear. Objects within axes such as lines and surfaces are higher in stacking order and clicking
on them selects the associated object rather than the axes. Selecting an area outside of the axes
selection region selects the figure itself.

EVENT QUEUE:
GUI execution is based on the concept of an event queue. That is, a GUI is presented to the user.
The user intern interacts with the GUI in an essentially arbitrary way over time, with interaction
creating an event that is placed in the event queue. In addition, other commands that involve
Figure window input or output generate callbacks, waitfor and waitforbuttonpress functions, and
that redraw graphics such as drawnow, figure, getframe or pause. MATLAB acts on all these
events in which they appear in the queue. MATLAB manages its event queue in a default
manner that is, appropriate in most cases. However, the common handle graphics object
properties Interpretable and BusyAction can be used to specify particular actions.
In all cases, a callback executes until it reaches a wait for, drawnow, waitforbuttonpress,
getframe, pause or figure command. CALLBACKS that do not contain any of these commands
cannot be interrupted. When one of these special commands is reached, MATLAB suspends the
execution of the callback and examines each of the pending events in event queue. If the
INTERRUPTIBLE property of the object with the suspended callback is said to on which is its
difficult value, all pending events are processed before the suspended callback is resumed. If the
INTERRUPTIBLE PROPERTY is said to off then only pending screen update events are
processed. At the same time BusyAction property of the object with the suspended callback is set
to cancel the interrupting callback events are discarded. Even if the executing callback is not
interruptible pending screen-update events are still processed when the callback reaches a
waitfor, waitforbuttonpress, drawnow,figure,gateframe or pause command.

CALLBACKS:
All handle graphics objects have the properties buttonDownfcn, createfcn and Deletefcn.
Also closedRequestFcn, Keypressed, WindowbuttondownFcn, windowbuttonmotionfcn
and windowbuttonupfcn and the user interface functions have a property callback. The
properties names associated with each of these properties are called callbacks. These callbacks
identify code to be executed when the specific user action associated with a property name are
taken. In the simplest case callbacks are character strings that are evaluated by eval in command
window work space. These strings can contain any sequence of valid MATLAB statements. In
most cases callbacks are function calls often to the same function where the callbacks are
defined. The setting of callbacks tells the MATLAB to perform certain tasks in response to
action taken by the user.

>>get(gcf,CloseRequestFcn)
ans=
closereq
>>class(ans)
ans=
char
This string is the name of the function in MATLAB that simply deletes the current figure.

4.4 GUI Object Hierarchy
Graphical user interface creation utilizes a number of MATLAB functions. These functions
create Handle Graphics objects that are below.

Uicontrol: General user interface control object having one of the following styles:
checkbox,edit, frame, listbox, popmenu, pushbutton, radiobutton, slider, text and togglebutton.

Uicontextmenu: User interface contextual menu object. All uicontextmenu objects are children
of figure objects. The handle of a uicontextmenu is placed in UIContextMenu property of the
handle graphics object for which they are to appear. All uicontextmenu objects have child
uimenu objects that define their menu items.

Checkbox: They consist of buttons with a label and a small square box to the left of the label
text. When activated the control is toggled between checked and cleared. They are typically used
to indicate the state of a portion or attribute.

Edit: They display text boxes display in a box so that you can modify or replace the text string
dynamically, just as you would by using a text editor or word processor. A single line editable
text box accepts one of the line of text. Multi line editable text boxes accepts more than one line
of text. Single line text entry is terminated by pressing the RETURN key and CONTROL-
RETURN for multiline text entry.

Frame: Frame uicontrol objects are simply opaque, shaded, rectangular regions with a border.
They are analogous to the separator, property of uimenu objects, in the sense that they provide
visual separation. Frames are typically used to logically group radiobuttons or uicontro objects.
Frame should be defined before other objects are placed within them else the frame may cover
the other uicontrols.

Popmenu: Popmenus are used to present a list of mutually exclusive choices to the user. When
closed a popmenu appears as a rectangle or button containing a label of current selection with a
small raised rectangle or downward-pointing arrow, beside the label to indicate that the object is
a popmenu. When the pointer is positioned over a pop control and the mouse button is pressed,
other choices appear.

Pushbutton: They are sometimes called command buttons or just buttons are small rectangular
screen objects that usually contain a text label. Selecting a pushbutton with the mouse by moving
the pointer over the object and clicking the mouse button causes MATLAB to perform the action
defined by the objects callback strings. Immediately after a pushbutton is pressed it returns to its
default up state. They are typically used to perform an action rather than change a state or set an
attribute.

RadioButton: They consists of buttons containing a label and a small circle or diamond to the
left of label text. When selected the circle or diamond is filled and when unselected the indicator
is cleared. They are typically used to select one of a group of mutually exclusive options.

Slider: They are scroll bars, consist of three distinct parts: the trough, or the rectangular area
representing the range of valid object values, the indicator within the trough representing the
current value of the slider, and arrows at each end of the trough. They are typically used to select
a value from a range of values.

Text: Static text boxes are controls that simply display a text string. They are typically used to
display labels, user information or current values. They are static in the sense that the user cannot
dynamically change the text displayed.

ToggleButton: These are identical to push buttons except that they toggle between two states, up
and down when repeatedly pushed by clicking on them with the mouse pointer.

4.5 Creating Graphical User

A GUI (graphical user interface) allows users to perform tasks interactively through controls
such as buttons and sliders. Within MATLAB, GUI tools enable you to perform tasks such as
creating and customizing plots (plottools), fitting curves and surfaces (cftools), and analyzing
and filtering signals (sptool). You can also create custom GUIs for others to use either by
running them in MATLAB or as standalone applications.

4.6 Creating a MATLAB GUI Interactively
GUIDE (GUI development environment) provides tools for designing and programming GUIs.
Using the GUIDE Layout Editor, you can graphically design your GUI. GUIDE then
automatically generates the MATLAB code that defines all component properties and establishes
a framework for GUI callbacks (routines that execute when a user interacts with a GUI
component).
4.7 Creating a MATLAB GUI Programmatically
For more control over design and development, you can also create MATLAB code that defines
all component properties and behaviors. MATLAB contains built-in functionality to help you
create your GUI programmatically. These include dialog boxes, user interface controls (such as
push buttons and sliders), containers (such as panels and button groups), and ActiveX controls
for Windows users.
4.8 How does GUI works?
In the GUI, the user selects a data set from the pop-up menu, and then clicks one of the plot type
buttons. The mouse click invokes a function that plots the selected data in the axes.
Most GUIs wait for their user to manipulate a control, and then respond to each action in turn.
Each control, and the GUI itself, has one or more user-written routines (executable
MATLAB

code) known as callbacks, named for the fact that they "call back" to MATLAB to
ask it to do things. The execution of each callback is triggered by a particular user action such as
pressing a screen button, clicking a mouse button, selecting a menu item, typing a string or a
numeric value, or passing the cursor over a component. The GUI then responds to these events.
You, as the creator of the GUI, provide callbacks which define what the components do to
handle events.
This kind of programming is often referred to as event-driven programming. In the example, a
button click is one such event. In event-driven programming, callback execution
is asynchronous, that is, it is triggered by events external to the software. In the case of
MATLAB GUIs, most events are user interactions with the GUI, but the GUI can respond to
other kinds of events as well, for example, the creation of a file or connecting a device to the
computer.




You can code callbacks in two distinct ways:
As MATLAB language functions stored in files
As strings containing MATLAB expressions or commands (such as 'c = sqrt(a*a +
b*b);'or 'print')

Using functions stored in code files as callbacks is preferable to using strings, as functions have
access to arguments and are more powerful and flexible. MATLAB scripts (sequences of
statements stored in code files that do not define functions) cannot be used as callbacks.
Although you can provide a callback with certain data and make it do anything you want, you
cannot control when callbacks will execute. That is, when your GUI is being used, you have no
control over the sequence of events that trigger particular callbacks or what other callbacks might
still be running at those times. This distinguishes event-driven programming from other types of
control flow, for example, processing sequential data files.
4.9 Files generated by GUIDE.
4.9.1Code Files and FIG-Files
By default, the first time you save or run a GUI, GUIDE stores the GUI in two files:
A FIG-file, with extension .fig, that contains a complete description of the GUI layout and each
GUI component, such as push buttons, axes, panels, menus, and so on. The FIG-file is a binary
file and you cannot modify it except by changing the layout in GUIDE. FIG-files are
specializations of MAT-files.
A code file, with extension .m, that initially contains initialization code and templates for some
callbacks that control GUI behavior. You generally add callbacks you write for your GUI
components to this file. As the callbacks are functions, the GUI code file can never be a
MATLAB

script.
When you save your GUI the first time, GUIDE automatically opens the code file in your default
editor.
The FIG-file and the code file must have the same name. These two files usually reside in the
same folder, and correspond to the tasks of laying out and programming the GUI. When you lay
out the GUI in the Layout Editor, your components and layout is stored in the FIG-file. When
you program the GUI, your code is stored in the corresponding code file.If your GUI includes
ActiveX

components, GUIDE also generates a file for each ActiveX component.
4.9.2 GUI Code File Structure
The GUI code file that GUIDE generates is a function file. The name of the main function is the
same as the name of the code file. For example, if the name of the code file is mygui.m, then the
name of the main function is mygui. Each callback in the file is a local function of that main
function.
When GUIDE generates a code file, it automatically includes templates for the most commonly
used callbacks for each component. The code file also contains initialization code, as well as an
opening function callback and an output function callback. It is your job to add code to the
component callbacks for your GUI to work as you want. You can also add code to the opening
function callback and the output function callback. The GUI code file orders functions as shown
in the following table.
Section Description
Comments Displayed at the command line in response to the help command. Edit comments
as necessary for your GUI.
Initialization GUIDE initialization tasks. Do not edit this code.
Opening function Performs your initialization tasks before the GUI user has access to the GUI.
Output function Returns outputs to the MATLAB command line after the opening function
returns control and before control returns to the command line.
Component and figure
callbacks
Control the behavior of the GUI figure and of individual components.
MATLAB software calls a callback in response to a particular event for a
component or for the figure itself.
Utility/helper functions Perform miscellaneous functions not directly associated with an event for the
figure or a component.
Table 4.1: GUI code functions

4.9.3 Adding Callback Templates to an Existing GUI Code File
When you save the GUI, GUIDE automatically adds templates for some callbacks to the code
file. If you want to add other callbacks to the file, you can easily do so.
Within GUIDE, you can add a local callback function template to the code in any of the
following ways. Select the component for which you want to add the callback, and then:
Right-click the mouse button, and from the View callbacks submenu, select the desired callback.
From View > View Callbacks, select the desired callback.
Double-click a component to show its properties in the Property Inspector. In the Property
Inspector, click the pencil-and-paper icon next to the name of the callback you want to
install in the code file.
For toolbar buttons, in the Toolbar Editor, click the View button next to Clicked Callback (for
Push Tool buttons) or On Callback, or Off Callback (for Toggle Tools).
When you perform any of these actions, GUIDE adds the callback template to the GUI code file,
saves it, and opens it for editing at the callback you just added. If you select a callback that
currently exists in the GUI code file, GUIDE adds no callback, but saves the file and opens it for
editing at the callback you select.
4.9.4 About GUIDE-Generated Callbacks
Callbacks created by GUIDE for GUI components are similar to callbacks created
programmatically, with certain differences.
GUIDE generates callbacks as function templates within the GUI code file, which GUI
components call via function handles.
GUIDE names callbacks based on the callback type and the component Tag property. For
example, togglebutton1_Callback is such a default callback name. If you change a
component Tag, GUIDE renames all its callbacks in the code file to contain the new tag. You can
change the name of a callback, replace it with another function, or remove it entirely using the
Property Inspector.
GUIDE provides three arguments to callbacks, always named the same.
You can append arguments to GUIDE-generated callbacks, but never alter or remove the ones
that GUIDE places there.
You can rename a GUIDE-generated callback by editing its name or by changing the
component Tag.
You can delete a callback from a component by clearing it from the Property Inspector; this
action does not remove anything from the code file.
You can specify the same callback function for multiple components to enable them to share
code.
After you delete a component in GUIDE, all callbacks it had remain in the code file. If you are
sure that no other component uses the callbacks, you can then remove the callback code
manually.

4.10 Selecting GUI template:
GUIDE provides several templates that you can modify to create your own GUIs. The templates
are fully functional GUIs; they are already programmed.
Access the Templates
You can access the templates in two ways:
Start GUIDE.
If the Layout Editor is already open, select File > New.
In either case, GUIDE displays the GUIDE Quick Start dialog box with the Create New
GUI tab selected as shown in the following figure. This tab contains a list of the available
templates.



Figure 4.2: GUIDE quick start dialog box
To use a template:
1. Select a template in the left pane. A preview displays in the right pane.
2. Optionally, name your GUI now by selecting Save new figure as and typing the name in the
field to the right. GUIDE saves the GUI before opening it in the Layout Editor. If you choose
not to name the GUI at this point, GUIDE prompts you to save it and give it a name the first
time you run the GUI.
3. Click OK to open the GUI template in the Layout Editor.






4.11 GUIDE tools summary:
The GUIDE tools are available from the Layout Editor shown in the figure below. The tools are
called out in the figure and described briefly below. Subsequent sections show you how to use
them.



Fig 4.3: GUIDE tools

Anda mungkin juga menyukai