proj1 ieee

Upload: efanie

Post on 10-Mar-2016

221 views

Category:

Documents


0 download

DESCRIPTION

ece 329 project 1 electronic document

TRANSCRIPT

Paper Title (use style: paper title)

GUI in MATLABInteractive Signal Plotter

Borgonia, Ma. Rica Stephanie L.Department of Electrical and Electronics EngineeringCebu City, [email protected]

Abstract This paper gives light on how graphical user interface is incorporated in MATLAB. As implemented in making an interactive signal plotter.Index TermsGUI, guide, matlab, fig, functions, set, get. (key words)Introduction Humans dearly value convenience, hence, the birth of technology. Instant or fast, accurate and reliable, different inventions and innovations were created to suit their needs. Since each individual possess their own strengths and weaknesses, these man-made discoveries aide them in their endeavors to overcome their weaknesses. It is not wrong to say that majority of the population does not love mathematics even though it is greatly part of life. In order to make up for this, some brilliant minds came to the idea of making an application that would help humans in dealing with math. Matlab helps evaluate simple to complex equations and can even plot these into graph, may it be two dimensional or three dimensional. It helps in performing analytical and/or numerical equations faster and more accurate. And through its plot function, aides in visualizing on how a graph looks like.But to even make this learning a great experience, graphical user interface or GUI may be incorporated as to make plotting graphs interactive and fun.Hence, this paper discusses about GUI and how it was built and used as an interactive graph plotter.

MatlabBrief History"The founders of The MathWorks recognized the need among engineers and scientists for more powerful and productive computation environments beyond those provided by languages such as Fortran and C. In response to that need, the founders combined their expertise in mathematics, engineering, and computer science to develop MATLAB, a high-performance technical computing environment. MATLAB combines comprehensive math and graphics functions with a powerful high-level language" (MathWorks Inc.). [1]It may be clich to say but necessity is the mother of inventions. And MATLAB is not an exception. As stated in the first paragraph, MATLAB was invented because the founders, one of which is Cleve Moler, felt the need for more powerful and productive computation environments beyond those provided by languages such as Fortran and C.

MATLAB is short for matrix laboratory. It is a fourth-generation programming language for technical computing and it integrates a lot of functions, i.e computation, visualization, and programming, in an easy-to-use environment where problems and solutions are expressed in familiar, easy-to-understand mathematical notation. Because MATLAB is an interactive system and its basic data element is an array that does not rmandate dimensioning, it allows users to solve many technical computing problems, especially those with matrix and vector formulations, with alacrity.

MATLAB has evolved and is continuing to develop over a period of years with input from many users. From 80 functions which include a simple matrix calculator and portable machine graphics, it has now grown with over 8000 functions and is still continuing its growth with every yearly updates.

Features and Applications

MATLAB generally permits matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, Fortran and Python. With over 8000 functions, it has a wide-range of applications and with its different toolboxes, it possess extensibility. Typical uses include but not limited to:Mathematics and computation, Algorithm development,DAQ(data acquisition), modeling, simulation, and prototyping, Data exploration, analysis, and visualization Scientific and engineering graphics Application development, including graphical user interface (GUI) building [2]

In university environments, it has become the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, it is the tool of choice for high productivity research, development, and analysis. Indeed, the founders vision in making MATLAB was realized.

GUIGraphical User Interface, or commonly known with its abbreviation GUI, is a program interface that makes use of the computers graphics in order to make the program easier to use. [4] It allows users to interact with electronic devices through the use of icons, buttons or other visual indicators rather than only using text through the use of the command line. [3] It is generally preferred because it allows the user to perform certain task without having to know the programming language needed to execute the task, thereby, allowing a user-friendly environment.

GUI in MATLABThe guide, or the graphical user interface development environment, in MATLAB creates the graphical user interface. It generated two file the .fig file and the .m file.

a. .fig file

The .fig file is the layout file. This is where the wireframe can be edited to suit the needs of the program and to aesthetically design the environment.

To open a GUI, go to menu>new>graphical user interface. A dialog box opens as shown in Fig 1. One may choose to open a blank GUI or an existing one. But if one has not yet created any, choose the blank GUI which is shown in fig 2.

Fig 1. GUI dialog box

Fig 2. Blank GUI

Since a signal plotter is to be made, the components to be used are: Axes where the plotted graph is shown. Sliders in order to adjust the amplitude, frequency, theta, time shifting, time scaling, alpha, width, and samples. One slider for each. Checkboxes for enabling and disabling. It is used for continuous time, discrete time, time reversal, time shift, and time scale. Edit texts so that the user may input values for the maximum, minimum and current values of amplitude, frequency, samples, theta, alpha, and width. These are integrated with the sliders. Static texts where the equations are to be shown and for title or labels of components. Pop-up menu where the user chooses if the signal to be shown is that of a sine, cosine, exponential, unit step, impulse, unit ramp, or a rectangular pulse. Panels in order to group functions such as signal transformations and type of signals.

Fig 3. Component Palette

Placing these components, and designing the wireframe, the output shown in fig 4 would be realized.

Fig 4. The final wireframe for the GUI

In order to change the properties of the components, the property inspector is used. Properties shown in the inspector differs for each component.

The only property manipulated in the figure is Color and Name. The Name must be the same with the file name of the .fig file.

Fig 5. Property inspector of figure

For static texts that is used for labels, background color, string, tag and visible were changed. The string manipulates the word displayed on the text box, whilst tag is the name of the component. This helps differ one static text to other static texts. For convention, tags are normally named as component_use or use_component. For example, text_Max or Max_text. Sometimes the label isnt needed for that use, thereby there is the need for it to be hidden. The property responsible for hiding the component is the visible. While for those used for the equations, background color, foreground color, font name, font size, string, and tag were edited. The foreground color determines the color of the text. The font name is changed from San Serif to Mathematica. Font size is changed from 8 to the desired size in order to emphasize the equation. Strings are being manipulated in the code which is to be discussed in a later chapter.Fig 6. Property inspector of static text

For the pop-up menu, the string was edited with the list of signals to be displayed.Fig 7. Property inspector of pop-up menu

For the panels, color and title were manipulated. Fig 8. Property inspector of panel

For checkboxes, background color, string, and tag were changed.Fig 9. Property inspector of checkbox

For edit texts, only the string and tag is changed. The string property is also manipulated in the code.

Fig 10. Property inspector of edit text

For sliders, the background color, min, max, string, tag, and visible were changed. There are sliders that needs their values to include negative values, e.g frequency, time shift, alpha, and theta. Whilst there are also those that doesnt include negative values, e.g amplitude, time scale, width and samples. Hence, the significance of changing the min value of the slider. Fig 11. Property inspector of slider

Changes made here in the Property Inspector serves as the default setting for the GUI. These properties may still be manipulated during the execution. This is possible because we can create codes that would do this.

b. .m fileThe .m file is the file where the implementation code is seen and edited. It is composed of a lot of functions that the visual indicators would execute. The callback functions of all components are manipulated in here.If a user clicks or drags or types on a user interface control or ui control, MATLAB executes the controls callback function. Hence, the importance of the .m file.The functions used in the implementation code are get, set, handles, num2str, str2num, and strcat. A function was also created I order to simplify the code. Comments were not erased in the .m file to help the user in analyzing the purpose of the function.

Since the code for the GUI is too long to be posted, excerpts would be shown as to fully understand on how the code works.

a. get, set, handlesThese functions are the most commonly used functions in the code. These allows for the interconnection between the sliders and the edit texts. The get function gets the corresponding value of the property of the component. While the set function sets the property of the component. The handles structure is used to share the data within the GUI. It served as the messenger for it is responsible for passing data between functions.Example codes are shown below.Fig 12. Call back code for edit_timeScaleFig 13. Call back code for edit_timeShift

Fig 14. Code for the visibility of Time Scale slider

b. num2str, str2num, strcatThese functions are also used because the type of the values taken from the properties of the component are not compatible to the property where it is to be assigned.

For example, the value taken by the get function from the value property of the slider is an integer and this valued is to be assigned by the set function to the string property of the edit text. String property only accepts strings, hence, the need to convert the integer or number to string. This is done by the num2str function.

Same goes for the str2num but it converts string to number. This is used in assigning the value property of the slider by the data taken, of the get function, from the string property of the edit text. This is because the value property only accepts numbers.

The strcat is used in the static text for the equation is composed of different inputs, vis but not limited to, the amplitude, time shift, and time scale. And in order to connect these series of strings, strcat is used for it concatenates these strings and make the whole equation.

The following are example codes.

Fig 15. Code for the static test equation

Fig 16. Code for the slider_freq

The Signal PlotterThe following would be snapshots on how the GUI works. The photos shown would range from a normal signal to a time shifted one, a time scaled one, amplitude is changed and other changes that may be manipulated with the use of the visual indicators in the GUI.

Sine Signal

Fig 17. CT Sine Signal

Fig 18. DT Sine SignalFig 19. Overlaid CT and DT Sine Signal

Fig 20. Time - scaled Sine Signal

Fig. 21. Time-shifted Sine Signal

Fig 22. Time reversed Sine Signal

Fig. 23. Sine Signal with f=10Hz, A=2

Fig 24. Sine Signal with 20 samples per cycle, A=5

Cosine SignalFig. 25. CT Cosine Signal

Fig 26. DT Cosine Signal

Fig 27. Overlaid CT and DT Cosine Signal

Fig 28. Time - scaled Cosine Signal

Fig 29. Time shifted Cosine Signal

Fig 30. Time reversed Cosine SignalFig 31. Cosine Signal with f=10Hz, A=2

Fig 32. Cosine Signal with 15 samples per cycle, A=5

Exponential SignalFig. 33. CT Exponential Signal

Fig 34. DT Exponential Signal

Fig 35. Overlaid CT and DT Exponential Signal

Fig 36. Time - scaled Exponential Signal

Fig 37. Time shifted Exponential Signal

Fig 38. Time reversed Exponential Signal

Fig 39. Exponential Signal with alpha = 2, A=2

Fig 40. Exponential Signal with 15 samples per cycle, A=5

Unit Step SignalFig. 41. CT Unit Step Signal

Fig 42. DT Unit Step Signal

Fig. 43.Overlaid CT and DT Unit Step Signal

Fig 44. Time-Shifted Unit Step Signal with 15 samples per cycle, A=3

4

Impulse SignalFig. 45. CT Impulse Signal

Fig 46. DT Impulse Signal

Fig. 47.Overlaid CT and DT Impulse Signal

Fig 48. Time-Shifted Impulse Signal with 15 samples per cycle, f=10 Hz, A=3

Ramp SignalFig. 49. CT Ramp Signal

Fig 50. DT Ramp Signal

Fig. 51.Overlaid CT and DT Ramp Signal

Fig 52. Time-Shifted Ramp Signal with 15 samples per cycle

Rectangular Pulse SignalFig. 53. CT Rectangular Pulse Signal

Fig 54. DT Rectangular Pulse Signal

Fig. 55.Overlaid CT and DT Rectangular Pulse Signal

Fig 56. Time-Shifted Rectangular Pulse Signal with 15 samples per cycle, A=3, width=1.89

ConclusionThis paper does not enable you to experience the user-friendliness of the Interactive Signal Plotter but the author greatly hopes you are able to gain knowledge on how to make one. It may be complicated at first but once you get to be familiarize with the functions, making it wouldnt be much of a challenge anymore. GUIs are indeed of great help because it enables one to not type codes anymore but to just use the visual indicators, i.e sliders, pop-up menu, checkboxes and edit texts in manipulating the graph of a specific signal.

RecommmendationsThe GUI made is somehow lacking. The author suggests to add unto its features the ability for the user to edit the equation itself, thereby changing the static text to an edit text. Another is to add a hold on function where the previous graph is maintained in order to really see the difference or changes. And also the reset button that sets the interface into its default settings. The author also challenges you to add a 3D feature where you can plot volume or surface graphs.

AcknowledgmentThe author would love to thank SAL for the matlab software and for the amenities that aided her in making this project, her parents, friends and classmates for the moral support, for Engr. Warren for giving this project, that even though it is very stressful, the author learned a lot in using matlab and its features. And most importantly, to God for the gift of knowledge, patience, capability and everything else that helped made this project to its completion.

ReferencesJ. Doke, (not specified). Creating a GUI with GUIDE [Online]. Available: http://www.mathworks.com/videos/creating-a-gui-with-guide-68979.htmlNot provided. Features [Online] Available: http://www.mathworks.com/products/matlab/features.htmlNot provided. GUI [Online]. Available: http://www.computerhope.com/jargon/g/gui.htmV. Beal, (not specified). GUIGraphical User Interface [Online]. Available: http://www.webopedia.com/TERM/G/Graphical_User_Interface_GUI.htmlNot provided. MATLAB [Online]. Available: https://en.wikipedia.org/wiki/MATLABNot provided. MATLAB Programming [Online]. Available: http://groups.engin.umd.umich.edu/CIS/course.des/cis400/matlab/matlab.html#acknowlNot provided. MATLAB [Online]. Available: http://pages.csam.montclair.edu/~cio/REU11/Files/MATLAB.pdf