converting txt file to mat file; ads1298ecgafe-pdk
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
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
[nR,nC]=size(rawData);
fprintf('Raw data has %d rows and %d columns.\n',nR,nC);
% 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
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.
Más respuestas (1)
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:
Ver también
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!