6.5. REAL-TIME LABS 207
screen d to this range (10–200 m) as control parameters. Assume the constant of proportionality
is 10
3
, and the electric field strength at the diffraction screen is 1 V/m.
Now replace the slit with two slits, each 0.1 mm in width, separated by 1 mm (center-
to-center), and centered on the optical axis. Plot the intensity of light in the viewing screen by
setting the parameters as controls.
6.5 REAL-TIME LABS
LR6_2 is real-time lab is a noise reduction application. e input signal is modulated with
a tone at fs/5 then noise is added to it. One should be able to choose the output to plot. e
choices are z2, the modulated input signal z3, the modulated input signal with noise y1, the t
of the original signal y2, the t of the modulated signal y3, the t of the modulated signal with
noise y4, the noise removed version of y3 and y4, the noise removed version of y3 and z4, and
the inverse t of the noise removed signal.
6.5.1 ANDROID STEPS
ese steps modify the LR5_2 lab. Copy the LR5_2 directory to LR6_2 and rename the LR5_2
files to LR6_2. Update the project files before updating the codes.
1. Update the applicationId in app/build.gradle to have LR6_2 in the name instead of
LR5_2. Remove the old C code from app/src/main/jni and copy the new MATLAB gen-
erated code into the same directory.
2. Update the MATLAB generated files in the file CMakeLists.txt. e section in the file
should look like the following block of code. e order of the files does not matter.
add_library( # Sets the name of the library.
matlabNative
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/jni/abs.c
src/main/jni/abs.h
src/main/jni/eml_rand_mt19937ar_stateful.c
src/main/jni/eml_rand_mt19937ar_stateful.h
src/main/jni/fft.c
src/main/jni/fft.h
src/main/jni/fftshift.c
208 6. CONTINUOUS-TIME FOURIER TRANSFORM
src/main/jni/fftshift.h
src/main/jni/ipermute.c
src/main/jni/ipermute.h
src/main/jni/LR6_2.c
src/main/jni/LR6_2.h
src/main/jni/LR6_2_data.c
src/main/jni/LR6_2_data.h
src/main/jni/LR6_2_emxAPI.c
src/main/jni/LR6_2_emxAPI.h
src/main/jni/LR6_2_emxutil.c
src/main/jni/LR6_2_emxutil.h
src/main/jni/LR6_2_initialize.c
src/main/jni/LR6_2_initialize.h
src/main/jni/LR6_2_rtwutil.c
src/main/jni/LR6_2_rtwutil.h
src/main/jni/LR6_2_terminate.c
src/main/jni/LR6_2_terminate.h
src/main/jni/LR6_2_types.h
src/main/jni/MatlabNative.c
src/main/jni/rand.c
src/main/jni/rand.h
src/main/jni/rtGetInf.c
src/main/jni/rtGetInf.h
src/main/jni/rtGetNaN.c
src/main/jni/rtGetNaN.h
src/main/jni/rtwtypes.h
src/main/jni/rt_nonfinite.c
src/main/jni/rt_nonfinite.h
)
3. Moving onto app/src/main/AndroidManifest.xml, update the LR5_2 names to LR6_2.
4. e file app/src/main/res/xml/prefs.xml will need to be edited to remove the resistance,
capacitance, frequency, and output settings similar to the previous labs. is time a List-
Preference of the output choice is made:
ListPreference
android:key=''choice1''
android:title=''What to plot?''
6.5. REAL-TIME LABS 209
android:summary=''Default: z2''
android:defaultValue=''0''
android:entries=''@array/choiceOptions''
android:entryValues=''@array/choiceValues'' />
Since the array references, @array/choiceOptions and @array/choiceValues ,
are used, they need to get added to the file app/src/main/res/values/arrays.xml. Remove
systemOptions , systemValues , choiceOptions , and choiceValues .
string-array name=''choiceOptions''>
<item>z2</item>
<item>z3</item>
<item>y1</item>
<item>y2</item>
<item>y3</item>
<item>y4</item>
<item>z4</item>
</string-array>
<string-array name=''choiceValues''>
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
</string-array>
5. Moving on to the code changes, update the file
app/src/main/java/com/dsp/matlab/Filter.java for the function calls by adding resistance,
capacitance, frequency, and display choice,
currentFrame.setFiltered(Filters.compute(currentFrame.getFloats(),
Settings.Fs,
Settings.choice, Settings.blockSize));
6. Now, in the file app/src/main/java/com/dsp/matlab/Filters.java, update the compute
method as follows:
210 6. CONTINUOUS-TIME FOURIER TRANSFORM
public static native float[] compute( float[] in, int Fs,
int choice, int frameSize );
7. To make sure the coefficient input is applied to the settings, update the
updateSettings() method in app/src/main/java/com/dsp/matlab/RealTime.java
and add the following line within. e previous settings for resistance, capacitance,
coefficients, frequency, and system can be removed.
Settings.setChoice(Integer.parseInt(
preferences.getString("choice1","0")));
8. Update app/src/main/java/com/dsp/matlab/Settings.java to store and retrieve the settings
added. Again the resistance, capacitance, coefficients, frequency, and system-related vari-
ables and methods can be removed.
public static float choice = 0;
public static void setChoice(int choice1){choice=choice1;}
9. Finally, update the app/src/main/jni/MatlabNative.c interface file. is file is the interface
from Java to native C. e entire file is listed below.
#include <jni.h>
#include <stdio.h>
#include ''rt_nonfinite.h''
#include ``LR6_2.h''
#include ``LR6_2_terminate.h''
#include ``LR6_2_emxAPI.h''
#include ``LR^_2_intialize.h''
jfloatArray
Java_com_dsp_matlab_Filters_compute(JNIEnv *env, jobject this,
jfloatArray, input, jint Fs, jint choice, jint frameSize)
{
jfloatArray output = (*env)->NewFloatArray(env, frameSize);
float *_in = (*env)->GetFloatArrayElements(env, input, NULL );
//compute
emxArray_real32_T *result;
..................Content has been hidden....................

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