# Analog Devices Wiki

This version (25 Jan 2021 13:36) was approved by Mihai Ionut Suciu.The Previously approved version (09 Jan 2021 00:57) is available.

MATLAB and Simulink support is currently provided from ADI and through the MathWorks. However, implementations and board support will differ between these sources. Official MathWork support is for:

ADI maintains support for all FMComms, ADALM-PLUTO, and ADRV board variants, as well as devices that support libiio. If your board has official support from MathWorks we would recommend starting with their implementations linked above.

# Data Streaming Example in MATLAB

In this section, we will show an example of data streaming using MATLAB libiio. Download the example ad9361_matlab.m from GitHub and open it in MATLAB:

In this example, input defines two sine waves (one for I channel, and the other for Q channel) streaming from MATLAB to target, as well as all the attributes of the device configuration channels. output is used to capture the streamed data from target, as well as to record all the attributes of the device monitoring channels, which is RSSI in this example.

There are two other parameters of the AD9361 you can set according to your modeling requirement:

1. Channel size: This is the number of samples buffered at the target before they are sent out together at each time. This number applies to both I and Q channels.
2. Number of data channels: This can be either 2 or 4. If it is 2, it will enable one IQ channel. Otherwise, it will enable two IQ channels.

Since we are streaming two sine waves to the target, we will also receive two sine waves back in MATLAB. This is what you should be able to get in the end:

Besides the two sine waves in the plot, we also see the RSSI indicator for both channel 1 and channel 2 in the workspace.

# Data Streaming Example in Simulink

## Tx and Rx in One Block

In this model, DATA_IN1 to DATA_IN4 are four pins used to stream two sine waves (one for I channel, and the other for Q channel) from Simulink to target, and DATA_OUT1 to DATA_OUT4 are four pins used to observe the time-domain streamed data from target in a Time Scope, as highlighted below. The other pins all represent certain settings you can find from ADI IIO Scope.

There are two other parameters of the Ad9361 Simulink block you can set according to your modeling requirement:

1. Channel size: This is the number of samples buffered at the target before they are sent out together at each time. This number applies to both I and Q channels.
2. Number of data channels: This can be either 2 or 4. If it is 2, it will enable one IQ channel. Otherwise, it will enable two IQ channels.

Make sure:

• RX LO Frequency = TX LO Frequency
• DDS Mode = DAC Buffer Output

Since we are streaming two sine waves to the target, we will also see two sine waves in the Time Scope. This is what you should be able to observe:

Besides the two sine waves in the Time Scope, we also see the RSSI indicator for both channel 1 and channel 2.

## Separate Tx and Rx Blocks

In the example above, we use one block for both Tx and Rx settings. You also have the option to have Tx and Rx in two separate blocks. All you have to do is to provide two configuration (.cfg) files.