Skip to content

Commit

Permalink
v1.1.3
Browse files Browse the repository at this point in the history
See Changelog for v1.1.3.  Added ability to read new ECG file formats including SCP-ECG, EDF, Claris ASCII, and Physionet .csv.  Improvements to loading DICOM files.  Minor bug fixes
  • Loading branch information
BIVectors committed Apr 3, 2024
1 parent 1901cd9 commit fd90b60
Show file tree
Hide file tree
Showing 23 changed files with 14,878 additions and 41 deletions.
2 changes: 1 addition & 1 deletion AnnoResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
obj.missing_lead = num2cell(missing_lead);

% VERSION MANUALLY UPDATED HERE
obj.version = {'1.1.2'};
obj.version = {'1.1.3'};

end
end
Expand Down
26 changes: 21 additions & 5 deletions ECG12.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@
case 'cardiosoft_xml'
[obj.hz, obj.I, obj.II, obj.III, obj.avR, obj.avF, obj.avL, ...
obj.V1, obj.V2, obj.V3, obj.V4, obj.V5, obj.V6] = load_cardiosoftxml(filename);

case 'scp_ecg'
[obj.hz, obj.I, obj.II, obj.III, obj.avR, obj.avF, obj.avL, ...
obj.V1, obj.V2, obj.V3, obj.V4, obj.V5, obj.V6] = load_scpecg(filename);

case 'edf'
[obj.hz, obj.I, obj.II, obj.III, obj.avR, obj.avF, obj.avL, ...
obj.V1, obj.V2, obj.V3, obj.V4, obj.V5, obj.V6] = load_edf(filename);

case 'claris'
[obj.hz, obj.I, obj.II, obj.III, obj.avR, obj.avF, obj.avL, ...
obj.V1, obj.V2, obj.V3, obj.V4, obj.V5, obj.V6] = load_claris(filename);

case 'physionet_csv'
[obj.hz, obj.I, obj.II, obj.III, obj.avR, obj.avF, obj.avL, ...
obj.V1, obj.V2, obj.V3, obj.V4, obj.V5, obj.V6] = load_physionet_csv(filename);

otherwise
error('unknown format %s', format);
Expand Down Expand Up @@ -184,7 +200,7 @@

end

function c = write(obj, file, format, freq)
function c = write(obj, file, format)
[fid, err] = fopen(file, 'w');
if fid == -1; error('opening %s for writing: %s', file, err); end
switch format % Note: doesn't account for differences in gain between input and output formats
Expand All @@ -201,10 +217,10 @@
case 'unformatted'
u = 1;
c = fprintf(fid, '%f %f %f %f %f %f %f %f %f %f %f %f\n', ...
[[freq; u*obj.I] [freq; u*obj.II] [freq; u*obj.III] ...
[freq; u*obj.avR] [freq; u*obj.avF] [freq; u*obj.avL] ...
[freq; u*obj.V1] [freq; u*obj.V2] [freq; u*obj.V3] ...
[freq; u*obj.V4] [freq; u*obj.V5] [freq; u*obj.V6]]');
[[obj.hz; u*obj.I] [obj.hz; u*obj.II] [obj.hz; u*obj.III] ...
[obj.hz; u*obj.avR] [obj.hz; u*obj.avF] [obj.hz; u*obj.avL] ...
[obj.hz; u*obj.V1] [obj.hz; u*obj.V2] [obj.hz; u*obj.V3] ...
[obj.hz; u*obj.V4] [obj.hz; u*obj.V5] [obj.hz; u*obj.V6]]');
% case 'muse_xml' % Not ready yet
% u = 205; % 4.88 uV resolution
% xml = write_muse_xml_file(obj);
Expand Down
279 changes: 279 additions & 0 deletions biosig_str2double.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
function [num,status,strarray] = biosig_str2double(s,cdelim,rdelim,ddelim)
%% STR2DOUBLE converts strings into numeric values
%% [NUM, STATUS,STRARRAY] = STR2DOUBLE(STR)
%%
%% Because of a name space conflict, this function is renamed to
%% BIOSIG_STR2DOUBLE(...). An alternative is STR2ARRAY from the NaN-toolbox.
%%
%% STR2DOUBLE can replace STR2NUM, but avoids the insecure use of EVAL
%% on unknown data [1].
%%
%% STR can be the form '[+-]d[.]dd[[eE][+-]ddd]'
%% d can be any of digit from 0 to 9, [] indicate optional elements
%% NUM is the corresponding numeric value.
%% if the conversion fails, status is -1 and NUM is NaN.
%% STATUS = 0: conversion was successful
%% STATUS = -1: couldnot convert string into numeric value
%% STRARRAY is a cell array of strings.
%%
%% Elements which are not defined or not valid return NaN and
%% the STATUS becomes -1
%% STR can be also a character array or a cell array of strings.
%% Then, NUM and STATUS return matrices of appropriate size.
%%
%% STR can also contain multiple elements.
%% default row-delimiters are:
%% NEWLINE, CARRIAGE RETURN and SEMICOLON i.e. ASCII 10, 13 and 59.
%% default column-delimiters are:
%% TAB, SPACE and COMMA i.e. ASCII 9, 32, and 44.
%% default decimal delimiter is '.' char(46), sometimes (e.g in
%% Tab-delimited text files generated by Excel export in Europe)
%% might used ',' as decimal delimiter.
%%
%% [NUM, STATUS] = STR2DOUBLE(STR,CDELIM,RDELIM,DDELIM)
%% CDELIM .. [OPTIONAL] user-specified column delimiter
%% RDELIM .. [OPTIONAL] user-specified row delimiter
%% DDELIM .. [OPTIONAL] user-specified decimal delimiter
%% CDELIM, RDELIM and DDELIM must contain only
%% NULL, NEWLINE, CARRIAGE RETURN, SEMICOLON, COLON, SLASH, TAB, SPACE, COMMA, or ()[]{}
%% i.e. ASCII 0,9,10,11,12,13,14,32,33,34,40,41,44,47,58,59,91,93,123,124,125
%%
%% Examples:
%% str2double('-.1e-5')
%% ans = -1.0000e-006
%%
%% str2double('.314e1, 44.44e-1, .7; -1e+1')
%% ans =
%% 3.1400 4.4440 0.7000
%% -10.0000 NaN NaN
%%
%% line ='200,300,400,NaN,-inf,cd,yes,no,999,maybe,NaN';
%% [x,status]=str2double(line)
%% x =
%% 200 300 400 NaN -Inf NaN NaN NaN 999 NaN NaN
%% status =
%% 0 0 0 0 0 -1 -1 -1 0 -1 0
%%
%% Reference(s):
%% [1] David A. Wheeler, Secure Programming for Linux and Unix HOWTO.
%% http://en.tldp.org/HOWTO/Secure-Programs-HOWTO/

%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; either version 2
%% of the License, or (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

%% Copyright (C) 2004,2008,2020 by Alois Schloegl <alois.schloegl@gmail.com>
%% This function is part of Biosig https://biosig.sourceforge.io

FLAG_OCTAVE = exist('OCTAVE_VERSION','builtin');
VER = version;

% valid_char = '0123456789eE+-.nNaAiIfF'; % digits, sign, exponent,NaN,Inf
valid_delim = char(sort([0,9:14,32:34,abs('()[]{},;:"|/')])); % valid delimiter
if nargin < 1,
error('missing input argument.')
end;
if nargin < 2,
cdelim = char([9,32,abs(',')]); % column delimiter
else
% make unique cdelim
cdelim = char(sort(cdelim(:)));
tmp = [1;1+find(diff(abs(cdelim))>0)];
cdelim = cdelim(tmp)';
end;
if nargin < 3,
rdelim = char([0,10,13,abs(';')]); % row delimiter
else
% make unique rdelim
rdelim = char(sort(rdelim(:)));
tmp = [1;1+find(diff(abs(rdelim))>0)];
rdelim = rdelim(tmp)';
end;
if nargin<4,
ddelim = '.';
elseif length(ddelim)~=1,
error('decimal delimiter must be exactly one character.');
end;

% check if RDELIM and CDELIM are distinct
delim = sort(abs([cdelim,rdelim,ddelim]));
tmp = [1; 1 + find(diff(delim')>0)]';
delim = delim(tmp);
%[length(delim),length(cdelim),length(rdelim)]
if length(delim) < (length(cdelim)+length(rdelim))+1, % length(ddelim) must be one.
error('row, column and decimal delimiter are not distinct.');
end;

% check if delimiters are valid
tmp = sort(abs([cdelim,rdelim]));
flag = zeros(size(tmp));
k1 = 1;
k2 = 1;
while (k1 <= length(tmp)) && (k2 <= length(valid_delim)),
if tmp(k1) == valid_delim(k2),
flag(k1) = 1;
k1 = k1 + 1;
elseif tmp(k1) < valid_delim(k2),
k1 = k1 + 1;
elseif tmp(k1) > valid_delim(k2),
k2 = k2 + 1;
end;
end;
if ~all(flag),
error('Invalid delimiters!');
end;

%%%%% various input parameters
if isnumeric(s)
if all(s<256) && all(s>=0)
s = char(s);
else
error('STR2DOUBLE: input variable must be a string')
end;
end;

num = [];
status = 0;
strarray = {};
if isempty(s),
return;

elseif iscell(s),
strarray = s;

elseif ischar(s)
if all(size(s)>1), %% char array transformed into a string.
for k = 1:size(s,1),
tmp = find(~isspace(s(k,:)));
strarray{k,1} = s(k,min(tmp):max(tmp));
end;

else %if isschar(s),
num = [];
status = 0;
strarray = {};

s(end+1) = rdelim(1); % add stop sign; makes sure last digit is not skipped

RD = zeros(size(s));
for k = 1:length(rdelim),
RD = RD | (s==rdelim(k));
end;
CD = RD;
for k = 1:length(cdelim),
CD = CD | (s==cdelim(k));
end;

k1 = 1; % current row
k2 = 0; % current column
k3 = 0; % current element

sl = length(s);
ix = 1;
%while (ix < sl) & any(abs(s(ix))==[rdelim,cdelim]),
while (ix < sl) && CD(ix),
ix = ix + 1;
end;
ta = ix; te = [];
while ix <= sl;
if (ix == sl),
te = sl;
end;
%if any(abs(s(ix))==[cdelim(1),rdelim(1)]),
if CD(ix),
te = ix - 1;
end;
if ~isempty(te),
k2 = k2 + 1;
k3 = k3 + 1;
if te<ta,
strarray{k1,k2} = [];
else
strarray{k1,k2} = s(ta:te);
end;
%strarray{k1,k2} = [ta,te];

flag = 0;
%while any(abs(s(ix))==[cdelim(1),rdelim(1)]) & (ix < sl),
while CD(ix) && (ix < sl),
flag = flag | RD(ix);
ix = ix + 1;
end;

if flag,
k2 = 0;
k1 = k1 + 1;
end;
ta = ix;
te = [];
end;
ix = ix + 1;
end;
end;
else
error('STR2DOUBLE: invalid input argument');
end;

[nr,nc]= size(strarray);
status = zeros(nr,nc);
num = repmat(NaN,nr,nc);

for k1 = 1:nr,
for k2 = 1:nc,
t = strarray{k1,k2};
if (length(t)==0),
status(k1,k2) = -1; %% return error code
num(k1,k2) = NaN;
else
%% get mantisse
g = 0;
v = 1;
if t(1)=='-',
v = -1;
l = min(2,length(t));
elseif t(1)=='+',
l = min(2,length(t));
else
l = 1;
end;

if strcmp(lower(t(l:end)),'inf')
num(k1,k2) = v*inf;

elseif strcmp(lower(t(l:end)),'nan');
num(k1,k2) = NaN;

else
if ddelim=='.',
t(t==ddelim)='.';
end;
if FLAG_OCTAVE, %% Octave
[v,tmp2,c] = sscanf(char(t),'%f %s','C');
elseif all(VER(1:2)=='3.') && any(VER(3)=='567'); %% FreeMat 3.5, 3.6, 3.7
[v,c,em] = sscanf(char(t),'%f %s');
c = 1;
else %% Matlab
[v,c,em,ni] = sscanf(char(t),'%f %s');
c = c * (ni>length(t));
end;
if (c==1),
num(k1,k2) = v;
else
num(k1,k2) = NaN;
status(k1,k2) = -1;
end
end
end;
end;
end;

25 changes: 17 additions & 8 deletions braveheart_batch_windows.prj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<deployment-project plugin="plugin.ezdeploy" plugin-version="1.0">
<configuration build-checksum="2704465841" file="C:\Users\jwaks\Documents\GitHub\BRAVEHEART_DEV\braveheart_batch_windows.prj" location="C:\Users\jwaks\Documents\GitHub\BRAVEHEART_DEV" name="braveheart_batch_windows" preferred-package-location="C:\Users\jwaks\Documents\GitHub\BRAVEHEART_DEV\braveheart_batch_windows\for_redistribution" preferred-package-type="package.type.exe" target="target.ezdeploy.standalone" target-name="Application Compiler">
<configuration build-checksum="4249213498" file="C:\Users\jwaks\Documents\GitHub\BRAVEHEART_DEV\braveheart_batch_windows.prj" location="C:\Users\jwaks\Documents\GitHub\BRAVEHEART_DEV" name="braveheart_batch_windows" preferred-package-location="C:\Users\jwaks\Documents\GitHub\BRAVEHEART_DEV\braveheart_batch_windows\for_redistribution" preferred-package-type="package.type.exe" target="target.ezdeploy.standalone" target-name="Application Compiler">
<param.appname>braveheart_batch</param.appname>
<param.icon>${PROJECT_ROOT}\braveheart_batch_windows_resources\icon.ico</param.icon>
<param.icons>
Expand All @@ -8,13 +8,13 @@
<file>${PROJECT_ROOT}\braveheart_batch_windows_resources\icon_24.png</file>
<file>${PROJECT_ROOT}\braveheart_batch_windows_resources\icon_16.png</file>
</param.icons>
<param.version>1.1.2</param.version>
<param.version>1.1.3</param.version>
<param.authnamewatermark>Hans F. Stabenau and Jonathan W. Waks</param.authnamewatermark>
<param.email>braveheart.ecg@gmail.com</param.email>
<param.company />
<param.summary />
<param.description>BRAVHEART ECG/VCG Analysis Software -- Command Line Version
Version 1.1.2</param.description>
Version 1.1.3</param.description>
<param.screenshot>${PROJECT_ROOT}\braveheart_splash.png</param.screenshot>
<param.guid />
<param.installpath.string>\braveheart_batch\</param.installpath.string>
Expand Down Expand Up @@ -50,7 +50,7 @@ Version 1.1.2</param.description>
varargin input arguments
Description
BRAVHEART ECG/VCG Analysis Software -- Command Line Version
Version 1.1.2</param.help.text>
Version 1.1.3</param.help.text>
<unset>
<param.company />
<param.summary />
Expand Down Expand Up @@ -82,16 +82,25 @@ Version 1.1.2</param.help.text>
<file>${PROJECT_ROOT}\braveheart_batch.m</file>
</fileset.main>
<fileset.resources>
<file>${PROJECT_ROOT}\anglesfig.pdf</file>
<file>${PROJECT_ROOT}\braveheart_equations.pdf</file>
<file>${PROJECT_ROOT}\braveheart_firstpass.pdf</file>
<file>${PROJECT_ROOT}\braveheart_variables.pdf</file>
<file>${PROJECT_ROOT}\biosig_str2double.m</file>
<file>${PROJECT_ROOT}\ecg_axis.m</file>
<file>${PROJECT_ROOT}\elecpos.mat</file>
<file>${PROJECT_ROOT}\findHighpassLvl.m</file>
<file>${PROJECT_ROOT}\getfiletype.m</file>
<file>${PROJECT_ROOT}\leadidcodexyz.m</file>
<file>${PROJECT_ROOT}\leadidtable_scpecg.mat</file>
<file>${PROJECT_ROOT}\load_cardiosoftxml.m</file>
<file>${PROJECT_ROOT}\load_claris.m</file>
<file>${PROJECT_ROOT}\load_edf.m</file>
<file>${PROJECT_ROOT}\load_physionet_csv.m</file>
<file>${PROJECT_ROOT}\load_scpecg.m</file>
<file>${PROJECT_ROOT}\open_ext_pdf.m</file>
<file>${PROJECT_ROOT}\parse_claris_txt.m</file>
<file>${PROJECT_ROOT}\physicalunits.m</file>
<file>${PROJECT_ROOT}\Qualparams.m</file>
<file>${PROJECT_ROOT}\resamp_loc.m</file>
<file>${PROJECT_ROOT}\scpopen.m</file>
<file>${PROJECT_ROOT}\sopen.m</file>
</fileset.resources>
<fileset.package>
<file>${PROJECT_ROOT}\Annoparams.csv</file>
Expand Down
Binary file modified braveheart_gui.fig
Binary file not shown.
Loading

0 comments on commit fd90b60

Please sign in to comment.