ECG Data Streaming¶
Available at
This example is located in the folder named ecg_data, and consists of three Simulink Model files, named ECG_stream2analog_1port_v1.slx, ECG_stream2analog_4ports_v1.slx and ECG_stream2analog_12ports_v1.slx, for a design able to transmit a few seconds of a signal from the host computer to analog ports through a Stream interface.
The first version is made to read a single signal, while the second one can read four signals at the same time, and the third twelve signals. The data used here comes from a matrix included in the folder as well, named A0001.mat, and containing ECG signals.
→ See Continuous ECG Data Streaming for a design that streams the whole signal continuously
Info
They were developped for the Eclipse Z7 board (except for the 12 ports version, which was made for the Noa Arch 1), but may be used on NOA Arch 1 as well.
Data¶
The data comes from PhysioNet, a platform for biomedical research, on which are published, among other ressources, biomedical data. The data used here contains 12-lead ECG signals, and was taken from a 2020 Cardiology challenge organised by the platform. More precisely, the matrix A0001.mat contains a 15 seconds signal, comes from the China Physiological Signal Challenge of 2018, and can be found on the page referenced above in the folder: training/cpsc_2018.
Another matrix named I0023.mat, that can be used to test the following designs, is also available in the folder. It comes from the St Petersburg INCART 12-lead Arrhythmia Database, can be found on the Physionet page in the folder training/st_petersburg_incart, and lasts 30 minutes.
Structure of the data
Header files named A0001.hea and I0023.hea, are also included: they contain informations on the signals in the .mat files. It is structured in the following way.
For the A0001.hea file for example, from the first line, we see that the recording number is A0001, and the recording file is A0001.mat. The recording has 12 leads, each recorded at 500 Hz sample frequency, and contains 7500 samples.
From the next 12 lines, we see that each signal was written at 16 bits with an offset of 24 bits, 1000 units equal to 1 mV (so 1 unit equals to 1 µV), the resolution of the analog-to-digital converter (ADC) used to digitize the signal is 16 bits, and the baseline value corresponding to 0 physical units is 0. The first value of the signal, the checksum, and the lead name are included for each signal.
From the final 6 lines, we see that the patient is a 74-year-old male with a diagnosis (Dx) of 426783006. The medical prescription (Rx), history (Hx), and symptom or surgery (Sx) are unknown.
All of these informations can be found on the PhysioNet page linked above.
ECG Data Streaming 1 port version: ECG_stream2analog_1port_v1¶
This design has two input ports. The first one is linked to a Stream Interface, so that it can receive the signal put in the StreamWrite block: at the beginning the enable port of the StreamWrite block is held at zero, so nothing goes through the Stream interface, and when the enable port goes up to one, the signal goes through the interface to the board. The second input port controls the sampling frequency of the signal. Finally you can read the signal on the two output ports: the DAQ Channel and the analogic output.

To write the signal at the proper sampling frequency, which is 500Hz for the data included in the repository, a FIFO memory is used in the "Stream Buffer" subsystem, in between the input and outputs. It indeed receives the values from the Stream interface and stores them. A counter is then used to produce a signal held at one at the frequency indicated at the designated port, to enable the reading of one value to the next at the proper period. The FIFO here is sized to contain 1024 values maximum. The output signal of the FIFO is then redirected to the outputs of the design.
Another important detail is that to manipulate more easily the scaling of the signals at the outputs, the values are normalized before going through the Stream: they're divided by a factor K, which you can set at 4000 for exemple, as the maximum value in the matrix is 1296. The goal is to have values inside the design between -1 and 1.
On the DAQ channel output, the signal is then multiplied by K, to denormalize it, but you can delete the gain to keep the normalized signal, if needed.
For the analog port, an AnalogOut block is used to scale the input signal to the output voltage. The input signal is in a -1 to 1 range and the output voltage is between -4V and 4V. The amplitude of the original data is divided by 1000, which gives an amplitude resolution of 1 mV instead of 1µV, but allows to view more easily the signals on a small oscilloscope.
This voltage range can of course be modified later through the interface, in the "Analog Outputs" tab of the IOs Setup.


ECG Data Streaming 4 ports version: ECG_stream2analog_4ports_v1¶
This design is similar to the first one. It has two input ports, that have the same role as before. The difference between this version and the first one, is that it is made to read four signals instead of one. In the StreamWrite block, four rows of the matrix are taken, instead of one. There are eight outputs, two for each signal: one analog output and one DAQ channel.

As in the first version, we use a FIFO to contain the values and a counter to output them at the wanted frequency. The FIFO here is sized to contain 4096 values maximum (1024 values for each of the four signals).
The difference with the first version is that the values of the different signals need to be redirected to the proper output port, as they're stored together. They're received an put in the FIFO in the following order: first value of signal 1, then of signal 2, signal 3, then second value of signal 1, etc... A subsystem named "Stream Splitter" splits the values from the output of the FIFO into four separate signals and they're then redirected to the proper ports.
Additionaly, to synchronize the signals, the counter mentionned above has a greater frequency: the chosen frequency at the designated input port is multiplied by 4. It is used to split the signals and synchronize them, on top of enabling the FIFO output. Indeed it controls another counter, and makes it go from 0, to 1, then 2, then 3, and back to zero. This enables four registers that will store alternatively the values, and split them into four different outputs. They're synchronized and written at the proper sampling frequency (500Hz here by default), thanks to a second row of registers, that are enabled only when the fourth value has been received, hence every four cycles of frequency 500*4=2000Hz, so at a frequency of 500Hz.
The normalization is designed the same way as in the 1-port version, as is the analog ports scaling.



ECG Data Streaming 12 ports version: ECG_stream2analog_12ports_v1¶
This design is very similar to the second one. It has two input ports, that have the same role as before. The only difference between this version and the second one, is that it is made to read twelve signals instead of four. In the StreamWrite block, twelve rows of the matrix are taken, instead of four. There are twenty-four outputs, two for each signal: one analog output and one DAQ channel.
It works exactly in the same way as the four-ports version, the things that are different are simply accomodating for the additional eight signals. For example, the FIFO here is sized to contain 12288 values maximum (1024 values for each of the four signals), and the "Stream Splitter" subsystem splits the values on twelve outputs instead of four. Similarly the counter has a frequency of 500*12=6000Hz, to output twelve values at a frequency of 500Hz.
Ports¶
| Port | Direction | Interface Type | Description |
|---|---|---|---|
stream_in |
input | Stream Input | the signal received from the computer through a Stream (ufix33) |
sampling_freq |
input | AXI4-Lite | value of the sampling frequency of the output signal; default is 500Hz (uint32) |
analog_out |
output | Analog Output 0 | the output ECG signal, redirected to an analog port (sfix32_En31) |
signal |
output | DAQ Channel 0 | the output ECG signal, redirected to the host computer (sfix32_En30) |
| Port | Direction | Interface Type | Description |
|---|---|---|---|
stream_in |
input | Stream Input | the signal received from the computer through a Stream (ufix33) |
sampling_freq |
input | AXI4-Lite | value of the sampling frequency of the output signal; default is 500Hz (uint32) |
signal_1_analog |
output | Analog Output 0 | the first output ECG signal, redirected to an analog port (sfix32_En31) |
signal_1 |
output | DAQ Channel 0 | the first output ECG signal, redirected to the host computer (sfix32_En30) |
signal_2_analog |
output | Analog Output 1 | the second output ECG signal, redirected to an analog port (sfix32_En31) |
signal_2 |
output | DAQ Channel 1 | the second output ECG signal, redirected to the host computer (sfix32_En30) |
signal_3_analog |
output | Analog Output 2 | the third output ECG signal, redirected to an analog port (sfix32_En31) |
signal_3 |
output | DAQ Channel 2 | the third output ECG signal, redirected to the host computer (sfix32_En30) |
signal_4_analog |
output | Analog Output 3 | the fourth output ECG signal, redirected to an analog port(sfix32_En31) |
signal_4 |
output | DAQ Channel 3 | the fourth output ECG signal, redirected to the host computer (sfix32_En30) |
| Port | Direction | Interface Type | Description |
|---|---|---|---|
stream_in |
input | Stream Input | the signal received from the computer through a Stream (ufix33) |
sampling_freq |
input | AXI4-Lite | value of the sampling frequency of the output signal; default is 500Hz (uint32) |
signal_1_analog |
output | Analog Output 0 | the first output ECG signal, redirected to an analog port (sfix32_En31) |
signal_1 |
output | DAQ Channel 0 | the first output ECG signal, redirected to the host computer (sfix32_En30) |
signal_2_analog |
output | Analog Output 1 | the second output ECG signal, redirected to an analog port (sfix32_En31) |
signal_2 |
output | DAQ Channel 1 | the second output ECG signal, redirected to the host computer (sfix32_En30) |
signal_3_analog |
output | Analog Output 2 | the third output ECG signal, redirected to an analog port (sfix32_En31) |
signal_3 |
output | DAQ Channel 2 | the third output ECG signal, redirected to the host computer (sfix32_En30) |
signal_4_analog |
output | Analog Output 3 | the fourth output ECG signal, redirected to an analog port(sfix32_En31) |
signal_4 |
output | DAQ Channel 3 | the fourth output ECG signal, redirected to the host computer (sfix32_En30) |
signal_5_analog |
output | Analog Output 4 | the fifth output ECG signal, redirected to an analog port (sfix32_En31) |
signal_5 |
output | DAQ Channel 4 | the fifth output ECG signal, redirected to the host computer (sfix32_En30) |
signal_6_analog |
output | Analog Output 5 | the sixth output ECG signal, redirected to an analog port (sfix32_En31) |
signal_6 |
output | DAQ Channel 5 | the sixth output ECG signal, redirected to the host computer (sfix32_En30) |
signal_7_analog |
output | Analog Output 6 | the seventh output ECG signal, redirected to an analog port (sfix32_En31) |
signal_7 |
output | DAQ Channel 6 | the seventh output ECG signal, redirected to the host computer (sfix32_En30) |
signal_8_analog |
output | Analog Output 7 | the eighth output ECG signal, redirected to an analog port(sfix32_En31) |
signal_8 |
output | DAQ Channel 7 | the eighth output ECG signal, redirected to the host computer (sfix32_En30) |
signal_9_analog |
output | Analog Output 8 | the ninth output ECG signal, redirected to an analog port (sfix32_En31) |
signal_9 |
output | DAQ Channel 8 | the ninth output ECG signal, redirected to the host computer (sfix32_En30) |
signal_10_analog |
output | Analog Output 9 | the tenth output ECG signal, redirected to an analog port (sfix32_En31) |
signal_10 |
output | DAQ Channel 9 | the tenth output ECG signal, redirected to the host computer (sfix32_En30) |
signal_11_analog |
output | Analog Output 10 | the eleventh output ECG signal, redirected to an analog port (sfix32_En31) |
signal_11 |
output | DAQ Channel 10 | the eleventh output ECG signal, redirected to the host computer (sfix32_En30) |
signal_12_analog |
output | Analog Output 11 | the twelfth output ECG signal, redirected to an analog port(sfix32_En31) |
signal_12 |
output | DAQ Channel 11 | the twelfth output ECG signal, redirected to the host computer (sfix32_En30) |
Simulink Interface¶
First, in the Matlab command window write period = num, where num is the working period corresponding the frequency set later in step 1.4 of the Generation of the Bitstream file process. The blocks in the design work at the period named "period", so it is necessary, to have the design work at the proper frequency.
To implement this design on hardware, you'll also need to load the matrix in your Matlab workspace, by typing the following code in the command window:
load("A0001.mat")
The content of the matrix should appear in your workspace under the name "val".
Do not forget to set the value you want for the constant K, used to normalize the data.
Then you'll need to follow the steps in the Generation of the Bitstream file page, to generate the bitstream file and the interface.
Once this is done, the Simulink interface will look like this:


Follow the steps presented on the Connection to the device page, and you will be able to visualize in live on the scope (on the right of the interface), the signals produced on your board (do not forget the settings for the scope, and the IOs). You will also be able to visualize them on an oscilloscope, connected to the analog ports of your device, as shown below.
You can start the streaming of the signal, indicated in the StreamWrite block, from the host computer to your board, by changing the value of the constant block on the left from 0 to 1. Modifying the constant block below on the left will change directly the sampling frequency of the output.
Note
You may change the signal produced by simply modifying the content of the StreamWrite block in the models shown above: in int(fi(val(1,1:1024)/K,1,32,30)) (version 1), int(fi(val(1:4,1:1024)/K,1,32,30)) (version 2), or int(fi(val(1:12,1:1024)/K,1,32,30)) (version 3), replace val(1,1:1024), val(1:4,1:1024) or val(1:12,1:1024). Do not change the rest!
You can for example view the other signals of the matrix, or signals from another array of ECG data.

This is the signal that can be seen on the first analog port.

These are the four signals that can be seen on the first, second, third and fourth analog ports, from top to bottom.

These are the first four signals that can be seen on the first, second, third and fourth analog ports, from top to bottom.

These are the next four signals that can be seen on the fifth, sixth, seventh an eighth analog ports, from top to bottom.

These are the last four signals that can be seen on the ninth, tenth, eleventh an twelfth analog ports, from top to bottom.