converting txt file to mat file; ads1298ecgafe-pdk

20 visualizaciones (últimos 30 días)
Elzbieta
Elzbieta el 19 de Sept. de 2024
Comentada: William Rose el 3 de Nov. de 2024 a las 2:23
Hello,
I used ADS1298ECGFE-PDK to capture data from both volonteer patients and multiparameter simulator. As far as I noticed in the data file there are 8 channels recording ECG signal.
In the case of volontueer patients I used 7-input 15-output signal. In the case of multiparameter simulator I used 10-input 15-output cable.
I am trying to convert this 8 channels data to matlab file. How to assign the appropriate channels to specific leads. How to convert to to mat format.
I include the data sample:
Record #: 3
Notes :
normal sinus rhythm
100 BPM
2024-08-2115:26:53Record #: 3
Notes :
normal sinus rhythm
100 BPM
2024-08-2115:26:53
Volts Data
CH1 CH2 CH3 CH4 CH5 CH6 CH7 CH8
-109,386444E-6 567,817688E-6 56,791306E-6 141,954422E-6 330,257416E-6 -61,225891E-6 375,652313E-6 -273,323059E-6
-97,560883E-6 574,731827E-6 62,847137E-6 146,675110E-6 333,023071E-6 -57,744980E-6 380,516052E-6 -268,077850E-6
-116,157532E-6 572,299957E-6 62,561035E-6 116,968155E-6 300,979614E-6 -89,931488E-6 353,384018E-6 -298,929214E-6
-142,574310E-6 572,919846E-6 54,168701E-6 96,273422E-6 285,196304E-6 -107,336044E-6 341,033936E-6 -318,717957E-6
-127,124786E-6 578,546524E-6 55,503845E-6 120,735168E-6 311,803818E-6 -80,060959E-6 364,971161E-6 -292,682648E-6
-114,154816E-6 572,109222E-6 56,123734E-6 135,135651E-6 324,773788E-6 -66,089630E-6 376,653671E-6 -279,045105E-6
-127,410889E-6 563,287735E-6 48,828125E-6 130,081177E-6 322,818756E-6 -69,427490E-6 373,888016E-6 -282,526016E-6
-108,814240E-6 569,248199E-6 50,163269E-6 161,123276E-6 355,148315E-6 -36,144257E-6 400,066376E-6 -249,576569E-6
-88,214874E-6 574,398041E-6 57,458878E-6 174,427032E-6 364,828110E-6 -26,702881E-6 405,120850E-6 -238,609314E-6
-104,761124E-6 574,636459E-6 60,033798E-6 150,871277E-6 339,221954E-6 -51,879883E-6 381,135941E-6 -264,930725E-6
-108,623505E-6 580,310822E-6 65,088272E-6 145,101547E-6 336,027145E-6 -55,980682E-6 379,94

Respuesta aceptada

William Rose
William Rose el 17 de Oct. de 2024
Editada: William Rose el 17 de Oct. de 2024
[Edit: Spelling. No changes to code.]
The numeric data in your text file includes only 10 rows. Assuming each row is one time point, that means only 10 time points. The raw EKG recording should have thousands of time points: multiple seconds of data (10 seconds for a standard rhythm strip), sampled at 500 Hz or faster. Ten rows is not enough to be useful.
Do you know the sampling rate of this recording?
I assume the commas in the text file represent the decimal separator. If I make that assumption, then the voltages are on the order of tens to hundreds of microvolts, which is reasonable, for a short recording that does not include the QRS complex.
rawData = readmatrix('RawData.txt','NumHeaderLines',11,'DecimalSeparator',',');
disp(rawData(1,:)) % display row 1 of the data
1.0e-03 * -0.1094 0.5678 0.0568 0.1420 0.3303 -0.0612 0.3757 -0.2733
[nR,nC]=size(rawData);
fprintf('Raw data has %d rows and %d columns.\n',nR,nC);
Raw data has 10 rows and 8 columns.
% I assume the ADS1298 text file channels are (see your comment above):
% V6, I, II, V2, V3, V4, V5, V1
% Therefore
leadI=rawData(:,2);
leadII=rawData(:,3);
% The augmented vector leads and lead III are derived as
% III=II-I; aVR=-(I+II)/2; aVL=I-II/2; aVF=II-I/2
leadIII=leadII-leadI;
aVR=-(leadI+leadII)/2;
aVL=leadI-leadII/2;
aVF=leadII-leadI/2;
% Re-order the 12 lead data to the following (standard) column order:
% I, II, III, aVR, aVL, aVF, V1, V2, V3, V4, V5, V6
dataTwelve=[leadI,leadII,leadIII,aVR,aVL,aVF,rawData(:,[8,4,5,6,7,1])];
% disp(size(dataTwelve))
% save 12 lead data as .mat file
save('ecg_data.mat', 'dataTwelve');
Check my work to make sure there are no errors. Good luck with your work.
  3 comentarios
Elzbieta
Elzbieta el 2 de Nov. de 2024 a las 12:23
Thank you for the answer. At the moment I would like to ask how to create a structure based on the key words included in the comments. For instance if I have a file starting with:
Record #: 21
Notes :
Kuba
1000
2024-07-2118:23:40Record #: 21
Notes :
Kuba
1000
2024-07-2118:23:40
Volts Data
CH1 CH2 CH3 CH4 CH5 CH6 CH7 CH8
399,999952E-3 6,416750E-3 -11,598396E-3 1,235390E-3 399,999952E-3 399,999952E-3 -14,708805E-3 -11,244154E-3
399,999952E-3 6,417227E-3 -11,614990E-3 1,229000E-3 399,999952E-3 399,999952E-3 -14,724588E-3 -11,263895E-3
399,999952E-3 6,417799E-3 -11,617184E-3 1,229143E-3 399,999952E-3 399,999952E-3 -14,722395E-3 -11,262560E-3
399,999952E-3 6,411505E-3 -11,615038E-3 1,223040E-3 399,999952E-3 399,999952E-3 -14,723635E-3 -11,263609E-3
399,999952E-3 6,407166E-3 -11,617088E-3 1,212740E-3 399,999952E-3 399,999952E-3 -14,733028E-3 -11,275101E-3
399,999952E-3 6,407881E-3 -11,614799E-3 1,221228E-3 399,999952E-3 399,999952E-3 -14,724541E-3 -11,266375E-3
399,999952E-3 6,409168E-3 -11,610222E-3 1,236963E-3 399,999952E-3 399,999952E-3 -14,709568E-3 -11,248589E-3
399,999952E-3 6,411791E-3 -11,610603E-3 1,239681E-3 399,999952E-3 399,999952E-3 -14,708519E-3 -11,245871E-3
399,999952E-3 6,410503E-3 -11,605740E-3 1,239252E-3 399,999952E-3 399,999952E-3 -14,705658E-3 -11,241055E-3
399,999952E-3 6,415510E-3 -11,605358E-3 1,244831E-3 399,999952E-3 399,999952E-3 -14,704990E-3 -11,239052E-3
399,999952E-3 6,426048E-3 -11,613274E-3 1,241398E-3 399,999952E-3 399,999952E-3 -14,721680E-3 -11,257172E-3
399,999952E-3 6,426525E-3 -11,624002E-3 1,240063E-3 399,999952E-3 399,999952E-3 -14,732790E-3 -11,268091E-3
399,999952E-3 6,418753E-3 -11,632299E-3 1,228380E-3 399,999952E-3 399,999952E-3 -14,744329E-3 -11,278677E-3
399,999952E-3 6,417084E-3 -11,634731E-3 1,224422E-3 399,999952E-3 399,999952E-3 -14,747667E-3 -11,286259E-3
399,999952E-3 6,415701E-3 -11,638260E-3 1,220751E-3 399,999952E-3 399,999952E-3 -14,753866E-3 -11,293745E-3
399,999952E-3 6,419468E-3 -11,635971E-3 1,233768E-3 399,999952E-3 399,999952E-3 -14,741278E-3 -11,280632E-3
399,999952E-3 6,418228E-3 -11,629772E-3 1,258707E-3 399,999952E-3 399,999952E-3 -14,712429E-3 -11,248684E-3
399,999952E-3 6,408930E-3 -11,635113E-3 1,260757E-3 399,999952E-3 399,999952E-3 -14,711809E-3 -11,247206E-3
399,999952E-3 6,408739E-3 -11,637878E-3 1,254225E-3 399,999952E-3 399,999952E-3 -14,720106E-3 -11,256552E-3
how could I create a structure: s.kuba.sitting.1000 which would contain array or structure composed of these 8 channels?
Thank you
Elzbieta
William Rose
William Rose el 3 de Nov. de 2024 a las 2:23
Your original question was
I am trying to convert this 8 channels data to matlab file. How to assign the appropriate channels to specific leads. How to convert to to mat format.
That quesiton was answered above.
Please start a new thread for your new, different question. Thank you.

Iniciar sesión para comentar.

Más respuestas (1)

Umeshraja
Umeshraja el 19 de Sept. de 2024
I understand that you're working with ECG data from the ADS1298ECGFE-PDK device and trying to convert it to MATLAB format while assigning the appropriate channels to specific ECG leads.
I assume that the data samples are provided in form of text file (.TXT format). Another assumption is that mapping for the ECG leads to the channels in your setup. The ‘save’ function can be used to save variable from workspace to file
The MATLAB script below script organizes the data into a structured format (ecgData) with fields for each ECG lead.
% Read the data from the text file as strings
opts = delimitedTextImportOptions('NumVariables', 8, 'Delimiter',' ', 'DataLines', 12);
rawData = readmatrix('RawData.txt', opts);
% Function to convert the string format to two numbers
function [num1, num2] = convertToNumbers(str)
parts = strsplit(str, ',');
num1 = str2double(parts{1});
num2 = str2double(parts{2});
end
% Convert the cell array to a numeric array
voltageData = zeros(size(rawData, 1), size(rawData, 2) * 2);
for i = 1:size(rawData, 1)
for j = 1:size(rawData, 2)
[num1, num2] = convertToNumbers(rawData{i,j});
voltageData(i, j*2-1) = num1;
voltageData(i, j*2) = num2;
end
end
% Create a structure to hold the ECG data
ecgData = struct();
% Assign channels to leads based on our assumed mapping
ecgData.leadI = voltageData(:, 1:2);
ecgData.leadII = voltageData(:, 3:4);
ecgData.leadIII = voltageData(:, 5:6);
ecgData.leadAVR = voltageData(:, 7:8);
ecgData.leadAVL = voltageData(:, 9:10);
ecgData.leadAVF = voltageData(:, 11:12);
ecgData.leadV1 = voltageData(:, 13:14);
ecgData.leadV2 = voltageData(:, 15:16);
% Save the data as a .mat file
save('ecg_data.mat', 'ecgData');
To know more on the ‘save’ function, please refer to the following documentation:
  1 comentario
Elzbieta
Elzbieta el 19 de Sept. de 2024
Thank you a lot. Let me present you channels to leads assignment:

Iniciar sesión para comentar.

Categorías

Más información sobre ECG / EKG en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by