[Introduction]  [Signal arithmetic]  [Signals and noise]   [Smoothing]   [Differentiation]  [Peak Sharpening]  [Harmonic analysis]   [Fourier convolution]  [Fourier deconvolution]  [Fourier filter]  [Wavelets]   [Peak area measurement]  [Linear Least Squares]  [Multicomponent Spectroscopy]  [Iterative Curve Fitting]  [Hyperlinear quantitative absorption spectrophotometry] [Appendix and Case Studies]  [Peak Finding and Measurement]  [iPeak]   [iSignal]  [Peak Fitters]   [iFilter]  [iPower]  [List of downloadable software]  [Interactive tools]


Appendix AF. Developing Matlab Apps

The usual way of developing programs in Matlab is to write scripts or functions, developed and used in a screen environment similar to the screen images of Matlab that I have shown before. In these environments, you can change the values of parameters by typing them into the editor window or the command line. Then, you save the modified script or function and re-run it. But there is another development path that results in programs that use a much more contemporary graphical user interface (GUI) employing drop-down menus, number wheels, tap-and-drag sliders, and such to support more intuitive user interactivity. There are examples of such apps in the toolboxes that are included in your version of Matlab (or can be optionally purchased from Matlab); type "ver" at the command line to see which ones are included in yours. The process of development your own apps is rather more complex than coding the mathematically equivalent script or function. But fortunately, Matlab has a built-in drag-and-drop environment to build user interfaces; just click on the APPS button at the top left. This brings up several app-related buttons as well as a list of apps already installed.

Clicking the Design App button, or typing “appdesigner” at the command prompt, brings up the App Designer screen, which has two main modes, selected by buttons on the right: the Design View and the Code View. In the Design View, you build your user interface - the "look" of your app - which might include menus, buttons, controls, tables, graphs, etc. You do this by selecting from a large list of components (displayed on the left), dragging and dropping the ones your need onto the blank layout on the right, and arranging them as you wish. Each of these is automatically accompanied by the computer code for its own operation. For example, if you add a Drop Down menu, it already knows how to operate itself, that is, to animate the menu dropping down and your mouse pointer selecting an item. Of course, what happens when you make a selec tion depends on the purpose of  your app, and so naturally you must provide that code, which is called a "callback function". The same goes for all those components. All this code is shown when you click the "Code View" button, both the code that is automatically generated when you add components to your design (shown with a grey background), which you cannot mod ify directly, and the code that you can type in to perform the desired calculations (shown with a white background).


Rather than detail all the required steps here, I will defer to the many excellent tutorials and YouTube videos already available. For example, there is a video tutorial titled "Getting Started and Hello World app" at https://www.youtube.com/watch?v=iga-YS6VbyE. "Hello World" refers to very first simple example often used for learning a new programming language, which simply writes that phrase on the display.

A more pertinent example is shown on the right. "Create and Run a Simple App Using App Designer" displays a waveform whose amplitude you can interactively control with a slider. There are many such examples that are built into the App Designer. When you click "New" in the Designer mode, you'll get a display (shown below) of several examples that are already constructed. You can learn a lot by studying these.


The advantage of apps, compared to scripts and functions, is that they are easier to use, especially for users who are not programmers. The disadvantage is that they are more complex for the programmer. In fact, the amount of code and of coding time and effort that goes into the user interface design and interactivity usually far exceeds the code that is required for the actual mathematical computations.

 I will give one final example that compares the operation and coding of a Matlab app to that of a Matlab script that does the same thing mathematically. The Matlab script is "GaussianSelfDeconvDemo3.m" and the app is called "SelfDeconvolutionDemo" which you can run by downloading and double-clicking. Both demonstrate the Fourier deconvolution of a pair overlapping peaks with a 1:2 height ratio, with the aim of increasing the resolution of the peaks. The sequence of operations is:
(1) create the simulated signal with two peaks and random noise,
(2) create a zero-centered convolution function of the same shape and with variable width,
(3) add an adjustable constant to the Fourier transform of the convolution function,
(4) divide the Fourier transform of the simulated signal by the modified Fourier transform of the convolution function,
(5) inverse transform that result, and
(6) apply Fourier filtering to reduce noise.
The script itself takes only about 40 lines of code, most of which deals with plotting and labeling, plus two external user functions. To experiment with different peak shapes, separations, etc., you would have to edit the script, save it, and re-run it. The Matlab app, on the other hand, has sliders for each of these variables, which allows those variables (and only those) to be adjusted simply by sliding the pointers. Each slider has a numerical range that you can set to be in a "reasonable range" for that variable. Moreover, the app has a pull-down menu to choose the peak shape (in this example, just two shapes: Gaussian and Lorentzian). Each time one any of these controls is changed, the app recalculates and updates the plots. You must add the specific programming for the mathematical calculations, which you type into the white space in the Code View, but you can call any functions that you are previously written and have saved in the Matlab path. You can also package any Matlab app you create into a single file, including any functions that you have called, so it can be easily shared with others.



The coding required to get all this to work is more complex and a simple script, but the app is easier and more fool-proof for a non-Matlab programmer to operate and it is a quicker to explore the several interacting variables in an app such as this, compared to editing, saving, and re-running a script.

 Unfortunately, Octave and Python do not have built-in mobile development capabilities, but there are packages you can use to create mobile applications in Python, like Kivy, PyQt, or Beeware's Toga library. These libraries are all major players in the Python mobile space.

This page is part of "A Pragmatic Introduction to Signal Processing", created and maintained by Prof. Tom O'Haver , Department of Chemistry and Biochemistry, The University of Maryland at College Park. Comments, suggestions and questions should be directed to Prof. O'Haver at toh@umd.edu. Updated July, 2022.