Page 1 of 1

Slow Arbitrary Output with Matlab

Posted: Mon Aug 30, 2021 3:24 pm
by ToBe
Hi Folks,

i'm trying to simulate an ECG signal by using SCPI and Matlab according to the official example ... -exm4.html. My raw ecg data is 10k points in total length and was sampled with 500 Sps. In my understanding, it should be fine to load the data in with the "SOUR1:TRAC:DATA:DATA" command and set the frequency to 500Hz for the Output.

Here is my Matlab Code:

Code: Select all

%% Define Red Pitaya as TCP/IP object
clear all
close all
IP= '';           % Input IP of your Red Pitaya...
port = 5000;
tcpipObj=tcpip(IP, port);

% Load File with raw ecg data
ecg_file = load('\raw_data\ecgiddb_pers26_1.mat', 'val');
ecg_data = ecg_file.val;
ecg_data_size = size(ecg_data,2);

% create TCP Object
tcpipObj.InputBufferSize = ecg_data_size*64;
tcpipObj.OutputBufferSize = ecg_data_size*64;

%% Open connection with your Red Pitaya and close previous
tcpipObj.Terminator = 'CR/LF';

% get biggest Signal Peak and normalize on it
ecg_peak = max(ecg_data);
ecg_data = ecg_data/max(ecg_data);

% Generating diff Signal
ecg_ch1 = ecg_data;
ecg_ch2 = ecg_data * (-1);      % inverting signal

%% Convert waveforms to string with 5 decimal places accuracy
waveform_ch_1_0 =num2str(ecg_ch1,'%1.5f,');
waveform_ch_2_0 =num2str(ecg_ch2,'%1.5f,');

waveform_ch_1 =waveform_ch_1_0(1,1:length(waveform_ch_1_0)-2);
waveform_ch_2 =waveform_ch_2_0(1,1:length(waveform_ch_2_0)-2);

fprintf(tcpipObj,'GEN:RST')                     % Reset to default settings

fprintf(tcpipObj,'SOUR1:FUNC ARBITRARY');       % Set function of output signal
fprintf(tcpipObj,'SOUR2:FUNC ARBITRARY');       % {sine, square, triangle, sawu, sawd}

fprintf(tcpipObj,['SOUR1:TRAC:DATA:DATA ' waveform_ch_1])  % Send waveforms to Red Pitya
fprintf(tcpipObj,['SOUR2:TRAC:DATA:DATA ' waveform_ch_2])

fprintf(tcpipObj,'SOUR1:VOLT 1');               % Set amplitude of output signal
fprintf(tcpipObj,'SOUR2:VOLT 1');

fprintf(tcpipObj,'SOUR1:FREQ:FIX 500');        % Set frequency of output signal
fprintf(tcpipObj,'SOUR2:FREQ:FIX 500');

fprintf(tcpipObj,'OUTPUT1:STATE ON');
fprintf(tcpipObj,'OUTPUT2:STATE ON');


The signal is generated fine, but with an incredibly high frequency.
Interestingly, when looking at the Signal with an oscilloscope, i can clearly see the "stair-ish" signal steps coming from the output of the RP. Measuring the time fo each of this steps results in a sampling rate of 8.3 MHz. When turning the frequency down to "1" I still measure around 16kHz.

So where is the problem here? Does the "SOUR1:FREQ:FIX 1" really sets the sampling rate in Hz, or is it the repitition rate of the Data-Block given by the :DATA command? Even then, it's totaly off (42 Hz vs. 1 Hz).
Also: when looking at the generated Signal, the signal has an awefull high jitter (~ 5ms with 1 Hz FREQ) - meaning that the characteristical peak in the ECG signal varies by 5ms between the periods. That also seems to be quiet bad...
I also power cycled the RP,.. no difference.

Thank you and kind regards