118 4. LINEAR TIME-INVARIANT SYSTEMS AND CONVOLUTION
Java_com_dsp_matlab_Filters_compute(JNIEnv
*env, jobject thiz,
jfloatArray input, jint Fs, jint choice,
jint frameSize)
is allows one to pass values from Java to the MATLAB C code.
4. Add the new variable as a parameter to the LR4_4 function call.
LR4_4(_in, x_size, Fs, choice, y);
e variable y will now hold the output of the choice selected. Update the initialize and ter-
minate functions to reflect the new lab number. In the file Filter.java, pass the new choice to the
compute function as follows:
currentFrame.setFiltered(Filters.compute(currentFrame.getFloats(),
Settings.Fs, Settings.choice, Settings.blockSize));
5. And, lastly, the file Filters.java updates the interface to MatlabNative.c. Update it by adding
the new parameter,
public static native float[] compute(float[] in,
int Fs, int choice,
int framesize);
ese are the typical files that will change from lab to lab. Compile the code and select different
outputs.
4.7.2 iOS STEPS
e iOS steps in order to add the plot selection are covered here. Instead of copying the LR4_3
Xcode project, it is better to create a new project. e project initialization was covered previ-
ously. After the initialization is done, copy the Main.storyboard, ViewController, and Audio-
Controller files from the previous project to the current. is can be done in either Xcode or
in the Finder app. is allows modifying the LR4_3 code to the LR4_4 requirements. Again,
update all the references of LR4_3 to LR4_4. Add the Native Code” group and add the .c and
.h files from MATLAB. Also, add the Audio Files” group with the included set of .caf files.
One can continue to add new picker view option.
1. Add the pickerView from the storyboard view. Some item may have to be re-arranged to
fit the new item.
4.7. REAL-TIME LABS 119
2. Add the code that references the new picker view and also a method that returns the index
of the current selection. In ViewController.h, add within the @interface definition.
@property (weak, nonatomic) IBOutlet UIPickerView *plotPickerView;
-(NSInteger) getPlotPickerIndex;
3. Add the code to ViewController.m. Within the @interface definition, add the following:
@property NSArray* plotPickerData;
en, within the viewDidLoad() method, add this plot text to be displayed.
_plotPickerView.delegate = self;
_plotPickerView.dataSource = self;
_plotPickerData = @[@''(h1*x)*h2'',
@''(h2*x)*h1'',
@''(x*h1)*h2'',
@''(h1*h2)*x'',
@''x*(h1+h2)'',
@''(x*h1)+(x*h2)''];
e above block of code enables _plotPickerView to call on the ViewController class in order
to know how to populate itself and behave when acted upon. is requires defining a few meth-
ods which _plotPickerView will call. e numberOfComponentsInPickerView method
has already been created and will work as is. is method tells pickerView how many columns
of data to expect. In our case, just 1 is used for both pickers. Modify numberOfRowsInMethod
to return the correct value based on the component as specified below.
-(long)pickerView:(UIPickerView*)pickerView
numberOfRowsInComponet:(NSInteger)component
{
if( pickerView == _filePickerVIew )
{
return _pickerData.count;
} else {
return _plotPickerData.count;
}
}
120 4. LINEAR TIME-INVARIANT SYSTEMS AND CONVOLUTION
Consequently, the number of elements in the array created above is returned. Next, when the
picker view populates, it needs to know the text for each row. is is done by updating the
titleForRow method. When called upon, the item from the array is returned for a given row:
-(NSString*)pickerView:(UIPickerView*)pckerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
if( pickerView == _filePickerView ) {
return _pickerData[row];
} else {
return _plotPickerData[row];
}
Also in ViewConroller.m, create the method that returns the current index selected. Au-
dioController will use this to know what plot to generate:
-(NSInteger) getPlotPickerIndex
{
return [_plotPickerView selectedRowInComponent:0];
}
4. Last, reference the GUI picker view with the _plotPickerView object in the code. is
is done in the storyboard view.
Display the Connections inspector, right most view in the right properties bar. Click and
drag from the empty circle to the right of “New Referencing Outlet to the view controller. A
small popup will display three options. Choose the plotPickerView. Figure 4.57 illustrates this.
Next, build and run the app.
4.7. REAL-TIME LABS 121
Figure 4.57: Reference the pickerView with an object.
5. AudioController will need to know which plot one wishes to generate. is value needs to
be obtained from the ViewController and passed to the MATLAB function LR4_4(). In
AudioController.h, add the method in the @protocol audioUIDelegate as noted below.
@protocol audioUIDelegate
...
-(NSinteger) getPlotPickerIndex;
...
@end
Also add a variable to store the value. Within the @interface AudioController section,
add the following:
@property float plotIndex;
..................Content has been hidden....................

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