| Data Acquisition Toolbox | Search  Help Desk |
Adding Channels to an Analog Input Object
After creating the analog input object, you must now add channels to it. As shown in the figure on page 2-10, a device object can be thought of as a container for channels. Adding channels to the analog input object is accomplished with theaddchannel function.
chans = addchannel(object, hwch, index, names)
object is the analog input object
hwch are the identifiers (ID's) of the hardware channels you are adding to the analog input object. Any valid MATLAB vector syntax can be used to specify the hardware channels.
index (optional) are the MATLAB indices of the hardware channels.
names (optional) are the descriptive names of the hardware channels.
chans (optional) is a vector containing the analog input channels.
addchannel, then they are automatically defined such that they are monotonically increasing and contains no gaps. Each channel is referenced by its position in the channel group (its index), or optionally by its name if one is defined. Named channels are discussed in "Reference by Channel Name". For detailed information about addchannel, refer to Chapter 6, "Function Reference."
If you are using scanning hardware, the channel indices specify the order in which the hardware channels are sampled. The first hardware channel to be sampled has index "1", the second hardware channel to be sampled has index "2", and so on. You can change the channel scanning order by specifying the MATLAB indices explicitly with the index input argument. Channel reordering is described in "Reordering Channels".
Example: Adding Channels for National Instruments Hardware
Suppose you create the analog input objectai for a National Instruments board having a device ID of 1.
ai = analoginput('nidaq', 1)
ai:
These channels are automatically assigned the MATLAB indices 1-8. You can now add the remaining 8 hardware channels toset(ai, 'InputType', 'SingleEnded')addchannel(ai, 0:7)
ai.
addchannel(ai, 8:15)
addchannel to add all 16 channels.
addchannel(ai, 0:15)
Example: Adding Channels for a Sound Card
Suppose you create the analog input objectai for a sound card.
ai = analoginput('winsound')
ai, then the sound card is in mono mode. Additionally, the channel added must be channel 1.
addchannel(ai, 1)
Mono channel. At the hardware level, you generally cannot determine the actual channel configuration and data can be acquired from channel 1, channel 2, or both depending on your sound card.
Stereo Mode.
If you add two channels to ai, then the sound card is in stereo mode. You can add two channels using two calls to addchannel provided channel 1 is added first.
You can also use one call toaddchannel(ai, 1)addchannel(ai, 2)
addchannel.
addchannel(ai, 1:2)
Left channel and channel 2 is called the Right channel. While in stereo mode, if you want to delete a channel, then that channel must be channel 2. If you try to delete channel 1, an error is returned. For any other type of data acquisition device, you may add or delete channels in any order.