Data Acquisition Toolbox
  Function/Property:
    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 the addchannel function.

where:

Note:
Adding channels to a sound card involves certain device-specific restrictions. These restrictions are explained in the example on page 3-7.

The collection of channels contained by the device object is referred to as a channel group. Channel group members must all reside on the same hardware device and the channels are all sampled at the same rate. It is important to remember that when you add channels to an object, you are mapping physical hardware channels on your analog input hardware device to MATLAB indices. This mapping allows a certain amount of flexibility in terms of ordering the channels as described by these rules:

If no indices are specified with 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 object ai for a National Instruments board having a device ID of 1.

To perform any data acquisition task, you must add hardware channels to the device object. Many National Instruments E-series boards have 16 single-ended input channels that can be added. To add the first 8 channels to ai:

These channels are automatically assigned the MATLAB indices 1-8. You can now add the remaining 8 hardware channels to ai.

These channels are automatically assigned the MATLAB indices 9-16. You can also use one call to addchannel to add all 16 channels.

The channel scanning order is given by the MATLAB indices. Therefore, hardware channel 0 is sampled first, hardware channel 1 is sampled second, and so on.

Example: Adding Channels for a Sound Card

Suppose you create the analog input object ai for a sound card.

To perform any data acquisition task, you must add hardware channels to the device object. Most sound cards have just two hardware channels that can be accessed. If one channel is added, the sound card is said to be in mono mode. If two channels are added, the sound card is said to be in stereo mode. However, the rules for adding these two channels differ from those of other data acquisition devices. These rules are described below.

Mono Mode.    If you add one channel to ai, then the sound card is in mono mode. Additionally, the channel added must be channel 1.

At the toolbox level, a mono acquisition means that data is acquired from channel 1. Channel 1 is called the 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 to addchannel.

In the latter case, channel 1 must be specified as the first element of the hardware ID vector.

A stereo acquisition means that data is acquired from both hardware channels. Channel 1 is called the 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.



[ Previous | Help Desk | Next ]