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.
The IIO System Object is based on the MATLAB System Objects™ specification. It is designed to exchange data over Ethernet with an ADI hardware system connected to a FPGA/SoC platform running the ADI Linux distribution.
The IIO System Object is available in both MATLAB and Simulink:
The IIO System Object is built upon the libiio library and enables a MATLAB or Simulink model to:
Below is presented a top level diagram showing the architecture of a system.
For more information about System objects, please refer to the MathWorks documentation on how to do Stream Processing in MATLAB.
The configuration file for a device has the .cfg extension and the name must match the device name set in the block's configuration dialog. It is a text file containing a set of fields that define the Linux drivers for the target device and the configuration channels that will be exposed by the Simulink block or MATLAB script. Entries in the configuration file can be commented by placing # at the begining of a line. The following entries can be found in a configuration file:
Below is presented a configuration file example for the AD9361.
data_in_device = cf-ad9361-dds-core-lpc data_out_device = cf-ad9361-lpc ctrl_device = ad9361-phy channel = RX_LO_FREQ,IN,out_altvoltage0_RX_LO_frequency, channel = RX_SAMPLING_FREQ,IN,in_voltage_sampling_frequency, channel = RX_RF_BANDWIDTH,IN,in_voltage_rf_bandwidth, channel = RX1_GAIN_MODE,IN,in_voltage0_gain_control_mode, channel = RX1_GAIN,IN,in_voltage0_hardwaregain, channel = RX1_RSSI,OUT,in_voltage0_rssi, channel = RX2_GAIN_MODE,IN,in_voltage1_gain_control_mode, channel = RX2_GAIN,IN,in_voltage1_hardwaregain, channel = RX2_RSSI,OUT,in_voltage1_rssi, channel = TX_LO_FREQ,IN,out_altvoltage1_TX_LO_frequency, channel = TX_SAMPLING_FREQ,IN,out_voltage_sampling_frequency, channel = TX_RF_BANDWIDTH,IN,out_voltage_rf_bandwidth,
The input and output ports of the Simulink block corresponding to an IIO System Object are defined through the properties dialog of the object's block as well as through a configuration file that is specific to the targeted ADI device. The input and output ports are categorized as data and control ports. The data ports are used to receive/transmit buffers of continuous data from/to the target system in a frame based processing mode, while the control ports are used to configure and monitor different target system parameters. The number and size of the data ports are configured from the block's configuration dialog while the control ports are defined in the configuration file.
Below is presented an example of how an IIO System Object Simulink block looks like for the AD9361 device and what options can be configured from the block's properties dialog.
The block's properties dialog contains the following parameters:
In order to use the IIO System Object, your MATLAB license needs to include the following component:
If you would like to use it in Simulink, your MATLAB license needs to include the following component:
Besides, you need to have two things ready on your PC:
Before using the IIO System Object, the libiio library must be installed in the system. The installer for Windows can be found here:
Windows libiio installer:
Libiio source code:
The IIO System object source code and example models can be found here:
The example models need to have either the source code of the IIO system object copied to the folder where the model resides or to have the path to the IIO System Object source code added to the MATLAB path.
In order to establish the connection between the host PC and the target, there are several steps you need to follow on both sides.
Starting with MATLAB R2018b, ADI is transitioning to a new system object infrastructure based on collaboration with MathWorks Inc. When installing the latest board support package, it also induces documentation.
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:
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.
In this section, we will show an example of data streaming using Simulink libiio block. Download the Simulink model ad9361_sim.slx from GitHub and open the model from Simulink:
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:
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.
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.
Download the Simulink model ad9361_sim.slx from GitHub and open the model from Simulink:
In this Simulink model, you will find the Rx block on the top and the Tx block on the bottom, as shown below:
In this GitHub directory, along with the Simulink model, you will find two cfg files: ad9361_tx.cfg and ad9361_rx.cfg, which includes the attributes related to Tx and Rx.
Using these two cfg files and the two blocks provided in the Simulink model, you can now make an independent Tx model and an independent Rx model.