122 4. LINEAR TIME-INVARIANT SYSTEMS AND CONVOLUTION
en in AudioController.m, get this value when an action is taken and pass it to the MATLAB
function.
Within the function toggleMicrophone , add the following near the top:
_plotIndex = [_delegate getPlotPickerIndex];
In the filterData method, update the function to use the new values. Since the MATLAB
code expects the plot index to start at 1, 1 needs to be added to the index. Compile and run the
app.
LR4_4(x,_sampleRate,_plotIndex, (_plotIndex+1), con);
LR4_5 Real-time lab LR4_5 simulates a real-time RC circuit by using known signals as input
or by using live signals from the microphone. e MATLAB code implements the convolution
of the input with either Equation (4.13) or (4.15) depending on which selection is made.
4.7.3 ANDROID STEPS
Use LR4_4 as a guide to implement this lab. Remember to update the CMakeLists.txt file to
use the appropriate MATLAB code generated for this lab and update codes using the LR4_5
methods.
To change the items to plot, replace the entries defined in the file
app/src/main/res/values/arrays.xml. It needs to appear like the following when finished:
<resources>
...
<string-array name=''systemOptions''>
<item>RL Circuit</item>
<item>RC Circuit</item>
</string-array>
<string-array name=''systemValues''>
<item>1</item>
<item>2</item>
</string-array>
</resources>
4.7.4 iOS STEPS
Starting from the LR4_4 lab, a few updates will need to be made. To allow inputs from the user
for the resistance, capacitance, and induction values, new GUI elements, variables to store their
4.7. REAL-TIME LABS 123
values, and a way to retrieve the elements from the GUI are needed. Accessing GUI values are
briefly mentioned next.
To start, add the GUI elements. One will be able to select which system to plot by mod-
ifying the values in the array created in the last lab.
1. Replace the _plotPickerData elements with @”RC Circuit and @”RL Circuit”. e
rest of the picker view code will work as is. is is modified in the ViewController.m file
and the viewDidLoad method.
2. To allow the AudioController to access GUI values, add the following lines to ViewCon-
troller.h within the @interface section.
@property (nonatomic, weak)
IBOutlet UITextField *RInput;
@property (nonatomic, weak)
IBOutlet UITextField *LInput;
@property (nonatomic, weak)
IBOutlet UITextField *CInput;
- (float) getRValue;
- (float) getLValue;
- (float) getCValue;
e UITextField pointers allow one to access the text field properties. e get{R,L,C} Value
methods allow the AudioController to retrieve the data as floats.
3. Populate the get{R,L,C} Value methods in ViewController.m. ese methods pull text
values entered, parse the string to a float, then return that value. ere is no other error
checking.
- (float) getRValue
{
NSString *strVal = _RInput.text;
return [[NSDecimalNumber decimalNumberWithString:(strVal)]
floatValue];
}
- (float) getLValue;
{
NSString *strVal = _LInput.text;
return [[NSDecimalNumber decimalNumberWithString:(strVal)]
floatValue];
}
124 4. LINEAR TIME-INVARIANT SYSTEMS AND CONVOLUTION
- (float) getCValue;
{
NSString *strVal = _CInput.text;
return [[NSDecimalNumber decimalNumberWithString:(strVal)]
floatValue];
}
4. In the Main.Storyboard, move up the elements to fit Labels and text inputs for the R, L, C
values. Some convenient values to set are the keyboard type= Decimal Pad, correction=no,
spell checking=no. As noted before, add the references to appropriate objects as shown in
Figure 4.57.
5. Define the member variables and interface methods in AudioController.h. Within the
audioUIDelegate protocol section, add these get methods:
- (float) getRValue;
- (float) getLValue;
- (float) getCValue;
e ViewController is acting as delegate for the AudioController and these methods define the
protocol that is needed to be created. Within the @interface section, add these lines to create
variables for the R, L, and C values:
@property (readwrite) float R;
@property (readwrite) float L;
@property (readwrite) float C;
6. Next, edit AudioController.m to complete the implementation. As before, edit all the
LR4_4 functions to use the LR4_5 functions. In viewDidLoad, initialize the R, L, C
variables.
_R = 15.0;
_L = 10.0;
_C = 10.0;
In the togglePlaybackOutput, add these lines to retrieve the current R, L, C values
from the GUI:
_plotIndex = [_delegate getPlotPickerIndex];
..................Content has been hidden....................

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