Skip to content

Commit 5504b04

Browse files
Merge pull request #43 from emersonkeenan/master
Version v1.3-alpha - Add asymmetric volume conductor modeling code
2 parents 25a0d09 + 570bcb7 commit 5504b04

File tree

1,703 files changed

+257935
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,703 files changed

+257935
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
GUI/*.mat
77
_site/
88
testset/
9+
data/anatomic_models/
10+
data/temp/

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ There are many ways to contribute to the _FECGSYN_:
99

1010
* **Fork it** Feel free to fork the repository on the project's main page
1111
+ **Create a pull request** We welcome novel algorithms and improvements to the <em>FECGSYN</em> toolbox. We strongly believe that open-source is the way to go with NI-FECG analysis.
12-
+ **Eeww bugs!** In case you in encounter a bug and cannot figure out the solution, please have a look on the opened issues before creating a new bug issue
12+
+ **Eeww bugs!** In case you encounter a bug and cannot figure out the solution, please have a look on the opened issues before creating a new bug issue
1313
+ **Pitch in your new ideas** for future releases by suggesting an enhancement
1414

1515

@@ -37,6 +37,9 @@ The current version of the <em>FECGSYN</em> was developed thanks to the followin
3737
- Mohsan Alvi
3838
- Reza Sameni
3939
- Sebastian Zaunseder
40+
- Emerson Keenan
41+
- Chandan Karmakar
42+
- Marimuthu Palaniswami
4043

4144

4245

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![license](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](./LICENSE)
22

3-
# _FECGSYN_ toolbox, version 1.2, March 2017
3+
# _FECGSYN_ toolbox, version 1.3-alpha, August 2019
44

55
### Open-source platform for reproducible NI-FECG research
66

@@ -13,12 +13,15 @@
1313

1414
## Authors
1515

16-
_FECGSYN_ is the product of a collaboration between the Department of Engineering Science, University of Oxford (DES-OX), the Institute of Biomedical Engineering, TU Dresden (IBMT-TUD) and the Biomedical Engineering Faculty at the Technion Israel Institute of Technology (BME-IIT). The authors are:
16+
_FECGSYN_ is the product of a collaboration between the Department of Engineering Science, University of Oxford (DES-OX), the Institute of Biomedical Engineering, TU Dresden (IBMT-TUD), the Department of Electrical and Electronic Engineering, University of Melbourne (EEE-UOM) and the Biomedical Engineering Faculty at the Technion Israel Institute of Technology (BME-IIT). The authors are:
1717
- Joachim Behar
1818
- Fernando Andreotti
1919
- Julien Oster
2020
- Sebastian Zaunseder
2121
- Gari D. Clifford
22+
- Emerson Keenan
23+
- Chandan Karmakar
24+
- Marimuthu Palaniswami
2225

2326

2427
@@ -44,14 +47,17 @@ maternal and foetal ECG signals. EURASIP Journal on Advances in Signal Processin
4447
## References
4548

4649

47-
When using the _FECGSYN_ please refer to:
50+
When using _FECGSYN_ please reference at least one of the following articles:
4851

49-
Behar, Joachim, Fernando Andreotti, Sebastian Zaunseder, Qiao Li, Julien Oster, and Gari D Clifford. 2014.
50-
"An ECG Model for Simulating Maternal-Foetal Activity Mixtures on Abdominal ECG Recordings." _Physiol Meas_ **35(8)**, pp.1537-50, 2014.
52+
1. Behar, Joachim, Fernando Andreotti, Sebastian Zaunseder, Qiao Li, Julien Oster, and Gari D Clifford. 2014. "An ECG Model for Simulating Maternal-Foetal Activity Mixtures on Abdominal ECG Recordings." _Physiol Meas_ **35(8)**, pp.1537-50, 2014.
5153

52-
Andreotti F., Behar J., Zaunseder S.,Oster J. and Clifford G D., An Open-Source Framework for Stress-Testing Non-Invasive Foetal ECG Extraction Algorithms. _Physiol Meas_ **37(5)**, pp. 627-648, 2016.
54+
and/or
5355

56+
2. Andreotti F., Behar J., Zaunseder S.,Oster J. and Clifford G D., An Open-Source Framework for Stress-Testing Non-Invasive Foetal ECG Extraction Algorithms. _Physiol Meas_ **37(5)**, pp. 627-648, 2016.
5457

58+
If you are using _FECGSYN's_ asymmetric volume conductor modeling capability, please reference the following article:
59+
60+
3. Keenan E., Karmakar C K. and Palaniswami M., The effects of asymmetric volume conductor modeling on non-invasive fetal ECG extraction. _Physiol Meas_ **39(10)**, pp. 105013, 2018.
5561

5662
## License
5763

@@ -85,6 +91,9 @@ This toolbox makes use of several other pre-existing open source algorithms list
8591
- _arrow.m_, by Dr. Erik A. Johnson, [available here](https://uk.mathworks.com/matlabcentral/fileexchange/278-arrow), (BSD license)
8692
- _fwhm.m_, v1.2, by Patrick Egan, [available here](http://uk.mathworks.com/matlabcentral/fileexchange/10590-fwhm), (BSD license)
8793
- _pcorr2.m_, by Peter Rydesäter, [available here](https://uk.mathworks.com/matlabcentral/fileexchange/4012-prcorr2-10-times-faster-correlation-coef) (BSD license)
94+
- _FieldTrip: The MATLAB toolbox for MEG and EEG analysis_, v20190828, by Robert Oostenveld, Pascal Fries, Eric Maris, and Jan-Mathijs Schoffelen, [available here](https://github.com/fieldtrip/fieldtrip) (licensed under GNU GPL 2.0)
95+
- _Iso2Mesh_, v1.9.0-1, Qianqian Fang, [available here](https://github.com/fangq/iso2mesh) (licensed under GNU GPL 2.0)
8896

8997
Not provided with package, ocasionally required, see [install instructions](http://fernandoandreotti.github.io/fecgsyn/pages/install.html):
9098
- **WFDB Toolbox for MATLAB and Octave**, v.0.9.9, by Dr. Ikaro Silva, [available here](https://www.physionet.org/physiotools/matlab/wfdb-app-matlab/) (licensed under GNU GPL 2.0)
99+
- **Pre-processed anatomic models**, by Emerson Keenan, [available here](https://github.com/emersonkeenan/fecgsyn-anatomic-models) (licensed under CC BY-NC-SA 2.0 FR)

cinc_animation.mp4

-22 MB
Binary file not shown.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
function model = calculate_lead_field(model)
2+
% function model = calculate_lead_field(model)
3+
% Calculate lead field matrix from input model
4+
%
5+
% inputs:
6+
% model: Struct of anatomic model
7+
% model.header = information on anatomic model type
8+
% model.compartments = struct array of model compartments
9+
% model.variants = struct array of model variants
10+
% model.folder = folder of anatomic model
11+
% model.name = name of anatomic model
12+
% model.sources = name of sources file
13+
% model.sensors = name of sensors file
14+
% model.fem = finite element mesh ready for solver
15+
%
16+
% outputs:
17+
% model: Struct of anatomic model
18+
% model.header = information on anatomic model type
19+
% model.compartments = struct array of model compartments
20+
% model.variants = struct array of model variants
21+
% model.folder = folder of anatomic model
22+
% model.name = name of anatomic model
23+
% model.sources = name of sources file
24+
% model.sensors = name of sensors file
25+
% model.fem = finite element mesh ready for solver
26+
% model.leadfield = struct array of maternal and fetal lead field matrices
27+
%
28+
%
29+
% --
30+
% fecgsyn toolbox, version 1.3-alpha, August 2019
31+
% Released under the GNU General Public License
32+
%
33+
% Copyright (C) 2019 Emerson Keenan
34+
% Department of Electrical and Electronic Engineering, University of
35+
% Melbourne
36+
37+
%
38+
% For more information visit: http://www.fecgsyn.com
39+
%
40+
% Referencing this work
41+
%
42+
% Keenan E., Karmakar C K. and Palaniswami M., The effects of asymmetric volume conductor modeling on non-invasive fetal ECG extraction.
43+
% Physiol Meas 39(10), pp. 105013, 2018.
44+
%
45+
%
46+
% Last updated : 05-09-2019
47+
%
48+
% This program is free software: you can redistribute it and/or modify
49+
% it under the terms of the GNU General Public License as published by
50+
% the Free Software Foundation, either version 3 of the License, or
51+
% (at your option) any later version.
52+
%
53+
% This program is distributed in the hope that it will be useful,
54+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
55+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56+
% GNU General Public License for more details.
57+
%
58+
% You should have received a copy of the GNU General Public License
59+
% along with this program. If not, see <http://www.gnu.org/licenses/>.
60+
%
61+
62+
% Write variables to temporary storage
63+
sensors = model.fem.sensors;
64+
sources = model.fem.sources;
65+
conductivity = model.fem.conductivity;
66+
ft_sources = [sources.maternal; sources.fetal];
67+
68+
% Create a set of electrodes at chosen sensor positions
69+
sens.elecpos = sensors;
70+
sens.label = {};
71+
nsens = size(sens.elecpos,1);
72+
sens.unit = 'mm';
73+
74+
for ii=1:nsens
75+
sens.label{ii} = sprintf('vertex%03d', ii);
76+
end
77+
78+
% Remove fields from model before passing to solver
79+
model.fem = rmfield(model.fem,'sensors');
80+
model.fem = rmfield(model.fem,'sources');
81+
model.fem = rmfield(model.fem,'conductivity');
82+
83+
% Pass model to FieldTrip-Simbio solver
84+
headmodel = ft_headmodel_simbio(model.fem,'conductivity',conductivity);
85+
headmodel.unit = 'mm';
86+
[headmodel, ~] = ft_prepare_vol_sens(headmodel,sens);
87+
lf = ft_compute_leadfield(ft_sources,sens,headmodel);
88+
89+
% Add fields to model after returning from solver
90+
model.fem.sensors = sensors;
91+
model.fem.sources = sources;
92+
model.fem.conductivity = conductivity;
93+
model.leadfield = struct('maternal',lf(:,1:3),'fetal',lf(:,4:6));
94+
95+
end
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
function model = generate_fe_mesh(model)
2+
% function model = generate_fe_mesh(model)
3+
% Generate finite element mesh from input model
4+
%
5+
% inputs:
6+
% model: Struct of anatomic model
7+
% model.header = information on anatomic model type
8+
% model.compartments = struct array of model compartments
9+
% model.variants = struct array of model variants
10+
% model.folder = folder of anatomic model
11+
% model.name = name of anatomic model
12+
% model.sources = name of sources file
13+
% model.sensors = name of sensors file
14+
%
15+
% outputs:
16+
% model: Struct of anatomic model
17+
% model.header = information on anatomic model type
18+
% model.compartments = struct array of model compartments
19+
% model.variants = struct array of model variants
20+
% model.folder = folder of anatomic model
21+
% model.name = name of anatomic model
22+
% model.sources = name of sources file
23+
% model.sensors = name of sensors file
24+
% model.fem = finite element mesh ready for solver
25+
%
26+
% --
27+
% fecgsyn toolbox, version 1.3-alpha, August 2019
28+
% Released under the GNU General Public License
29+
%
30+
% Copyright (C) 2019 Emerson Keenan
31+
% Department of Electrical and Electronic Engineering, University of
32+
% Melbourne
33+
34+
%
35+
% For more information visit: http://www.fecgsyn.com
36+
%
37+
% Referencing this work
38+
%
39+
% Keenan E., Karmakar C K. and Palaniswami M., The effects of asymmetric volume conductor modeling on non-invasive fetal ECG extraction.
40+
% Physiol Meas 39(10), pp. 105013, 2018.
41+
%
42+
%
43+
% Last updated : 05-09-2019
44+
%
45+
% This program is free software: you can redistribute it and/or modify
46+
% it under the terms of the GNU General Public License as published by
47+
% the Free Software Foundation, either version 3 of the License, or
48+
% (at your option) any later version.
49+
%
50+
% This program is distributed in the hope that it will be useful,
51+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
52+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53+
% GNU General Public License for more details.
54+
%
55+
% You should have received a copy of the GNU General Public License
56+
% along with this program. If not, see <http://www.gnu.org/licenses/>.
57+
%
58+
59+
conf = FECGSYN_check_platform();
60+
61+
if ispc
62+
clear tempdir
63+
setenv('TEMP',char(strcat(conf.fecgsynpath, 'data', conf.slashchar, 'temp', conf.slashchar, model.name, conf.slashchar)));
64+
elseif isunix
65+
clear tempdir
66+
setenv('TMP',char(strcat(conf.fecgsynpath, 'data', conf.slashchar, 'temp', conf.slashchar, model.name, conf.slashchar)));
67+
else
68+
error('Platform not supported');
69+
end
70+
71+
%% Read in models, sources and sensors
72+
[fetusPos, fetusTri] = FECGSYN_read_off(strcat(model.folder, conf.slashchar, model.name, conf.slashchar, model.name, '_', model.compartments.fetus.mesh.tri, '.off'));
73+
[amnioticPos, amnioticTri] = FECGSYN_read_off(strcat(model.folder, conf.slashchar, model.name, conf.slashchar, model.name, '_', model.compartments.amniotic_fluid.mesh.tri, '.off'));
74+
[abdoPos, abdoTri] = FECGSYN_read_off(strcat(model.folder, conf.slashchar, model.name, conf.slashchar, model.name, '_', model.compartments.maternal_abdomen.mesh.tri, '.off'));
75+
76+
[maternalSource, fetalSource] = FECGSYN_read_sources(strcat(model.folder, conf.slashchar, model.name, conf.slashchar, model.name, '_', model.sources, '.sources'));
77+
sensors = FECGSYN_read_sensors(strcat(model.folder, conf.slashchar, model.name, conf.slashchar, model.name, '_', model.sensors, '.sensors'));
78+
sources = struct('fetal',fetalSource,'maternal',maternalSource);
79+
80+
%% Define conductivities for each region
81+
% c(1) = Fetus
82+
% c(2) = Vernix Caseosa
83+
% c(3) = Amniotic Fluid
84+
% c(4) = Maternal abdomen
85+
c = [];
86+
c(1) = model.compartments.fetus.conductivity;
87+
c(2) = model.compartments.vernix.conductivity;
88+
c(3) = model.compartments.amniotic_fluid.conductivity;
89+
c(4) = model.compartments.maternal_abdomen.conductivity;
90+
91+
%% Define internal point for each region (columns 1-3) and maxvol (column 4)
92+
pFetus = [model.compartments.fetus.mesh.innerpoint model.compartments.fetus.meshsize];
93+
pAmniotic = [model.compartments.amniotic_fluid.mesh.innerpoint model.compartments.amniotic_fluid.meshsize];
94+
pAbdo = [model.compartments.maternal_abdomen.mesh.innerpoint model.compartments.maternal_abdomen.meshsize];
95+
96+
%% Check if vernix is present
97+
if isempty(model.compartments.vernix.mesh.tri) % No vernix present
98+
c = [c(1) c(3) c(3) c(4)];
99+
regions = [pFetus; pAmniotic; pAbdo];
100+
[fullV,fullF] = mergemesh(fetusPos,fetusTri,amnioticPos,amnioticTri,abdoPos,abdoTri);
101+
else % Vernix present
102+
[vernixPos, vernixTri] = FECGSYN_read_off(strcat(model.folder, conf.slashchar, model.name, conf.slashchar, model.name, '_vernix_', model.compartments.vernix.mesh.tri, '.off'));
103+
pVernix = [model.compartments.vernix.mesh.innerpoint model.compartments.vernix.meshsize];
104+
regions = [pFetus; pVernix; pAmniotic; pAbdo];
105+
[fetusAndVernixPos,fetusAndVernixTri]= FECGSYN_join_nodes(fetusPos,fetusTri,vernixPos,vernixTri);
106+
[fullV,fullF]=mergemesh(fetusAndVernixPos,fetusAndVernixTri,amnioticPos,amnioticTri,abdoPos,abdoTri);
107+
end
108+
109+
%% Compute tetrahedralization using iso2mesh
110+
[node,elem, ~]=surf2mesh(fullV,fullF,[],[],1,[],regions,[]);
111+
faceRegions = elem(:,5);
112+
113+
%% Fix region labels for no vernix case
114+
if isempty(model.compartments.vernix.mesh.tri) % No vernix present
115+
for i=1:length(faceRegions)
116+
if faceRegions(i) > 1
117+
faceRegions(i) = faceRegions(i)+1;
118+
end
119+
end
120+
end
121+
122+
elem=meshreorient(node,elem(:,1:4)); % Ensure all elements are oriented
123+
% consistently
124+
elem = [elem faceRegions];
125+
abdoIndex = sensors(:,2);
126+
abdoSensors = abdoPos(abdoIndex,:);
127+
128+
%% Create output finite element mesh structure
129+
model.fem = struct();
130+
model.fem.pos = node;
131+
model.fem.tet = elem(:,1:4);
132+
model.fem.tissuelabel = {'fetus','vernix','amniotic', 'abdomen'};
133+
model.fem.tissue = faceRegions;
134+
model.fem.sensors = abdoSensors;
135+
model.fem.sources = sources;
136+
model.fem.conductivity = c;
137+
138+
end

0 commit comments

Comments
 (0)