forked from jcollfont/inverseecg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splineInverse.m
37 lines (27 loc) · 1.45 KB
/
splineInverse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [EGM_sol] = splineInverse(A, ECG, RegMtrx, vec_lambda, underdetermined)
%% PARAMETERS
% curve interpolation
NumberOfKnots=12; % number of knots
InterpolationDensity=100; % interpolation density
ProjectionInterpolationDensity=200; % final projection density
minderivcostreduction=500; % minimum reconstruct err for deriv
minoverallcostreduction= 1e-6; % minimum reconstr err total
%% FIT CURVE
% Solve for initial derivatives
fprintf('Fitting first and last curve derivatives...\n')
CurveParams = initializeCurveParamsFromTimeSeries( ECG, NumberOfKnots);
CurveParams = minimizeDistanceToCurve( CurveParams, ECG, InterpolationDensity, minderivcostreduction, 'JustDerivatives');
% Solve for all parameters
fprintf('Fitting all curve parameters...\n')
CurveParams = minimizeDistanceToCurve( CurveParams, ECG, InterpolationDensity, minoverallcostreduction);
% Project the data to the curve; obtain first time warp
[Yproj, ProjInds] = ProjectDataPointsToCurve( CurveParams, ECG, ProjectionInterpolationDensity);
Ywarp = InterpolateCurve( CurveParams, ProjectionInterpolationDensity);
%% CALCULATE INVERSE
fprintf('Computing Inverse...\n');
[Xcurveparams] = tikhonov_jcf(A, RegMtrx, [], CurveParams, vec_lambda, underdetermined, true);
%% RECONSTRUCT TIME SERIES
fprintf('Reconstructing time signal...\n');
Xwarp = InterpolateCurve(Xcurveparams,ProjectionInterpolationDensity);
EGM_sol = Xwarp(:,ProjInds);
end