MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
Create the audio player object and set the sample rate to the same rate as the input data.

audioOut = audioDeviceWriter('SampleRate',audioIn.SampleRate);

Assemble Components Into System


Connecting System Objects

After you have determined the components you need and have created and configured
your System objects, assemble your system. You use the System objects like other
MATLAB variables and include them in MATLAB code. You can pass MATLAB variables
into and out of System objects.

The main difference between using System objects and using functions is that System
objects use a two-step process. First you create the object and set its parameters and
then, you run the object. Running the object initializes it and controls the data flow and
state management of your system. You typically call a System object within a code loop.

You use the output from an object as the input to another object. For some System
objects, you can use properties of those objects to change the inputs or outputs. To verify
that the appropriate number of inputs and outputs are being used, you can use nargin
and nargout on any System object. For information on all available System object
functions, see “System Object Functions” on page 34-4.

Connect Components in a System

This section shows how to connect the components together to read, filter, and play a file
of audio data. The while loop uses the isDone function to read through the entire file.

while ~isDone(audioIn)
audio = audioIn(); % Read audio source file
y = filtLP(audio); % Filter the data
audioOut(y); % Play the filtered data
end

Run Your System


Run your code by either typing directly at the command line or running a file containing
your program. When you run the code for your system, data is processed through your
objects.

34 System object Usage and Authoring

Free download pdf