54 3. FROM MATLAB CODER TO SMARTPHONE
Figure 3.5: Function error check.
Once the MATLAB script is checked and passed, a corresponding C source code can
be generated by pressing the Generate button (see Figure 3.6). Although various configuration
settings are available, the default settings are adequate for our purposes. After this step, a folder
named codegen is created in the directory of the MATLAB files.
3.2.3 SOURCE CODE INTEGRATION
e final step to implement an algorithm written in MATLAB on smartphones is to deploy
the generated C code on a suitable target device. For this step, an application shell is provided
here in which the generated C source code needs to be placed. is shell operates in the same
manner as the test bench script stated earlier; that is the two signals (pulse and exponential) are
generated. Figures 3.7 and 3.8 show how the generated C code is placed or integrated into the
Android shell that is provided. e following steps need to be taken.
1. Navigate to the folder named Lab3_1 (MATLAB function name) in the codegen folder;
codegen/lib/Lab3_1. Copy all the files with .h and .c extensions; see Figure 3.7.
2. Place the copied files inside the jni folder of the shell provided. e jni folder appears at
app/src/main/jni; see Figure 3.8.
3. Before building the project, first press Clean Project, as shown in Figure 3.9.
3.2. GENERATING SIGNALS VIA MATLAB ON SMARTPHONES 55
Figure 3.6: C source code generation.
e MATLAB Coder produces C codes with the required include statements and func-
tion calls for using them. One minor modification of a generated C code that may be required
is to ensure having the correct input and output variable data types. In case of array inputs, the
generated code is specified using static array sizes and thus needs to be modified to access array
pointers.
Finally, it is worth stating that the most important consideration when transiting a MAT-
LAB function to smartphones is awareness of input and output data types. A persistent variable
storage needs to be established by declaring a persistent variable and performing a one-time
initialization. After this declaration and initialization, any data may be retained between calls to
the function. With the approach presented in this chapter, practically any signals and systems
algorithm written in MATLAB can be made to run on smartphones.
56 3. FROM MATLAB CODER TO SMARTPHONE
Figure 3.7: Copying files.
Figure 3.8: C source code integration.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.137.164