-
Notifications
You must be signed in to change notification settings - Fork 0
/
myUCOResponse.m
108 lines (100 loc) · 2.6 KB
/
myUCOResponse.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function [RR, u] = myUCOResponse(t, baselineRR, deltaResponseRR, ucoDuration, restDuration, tauResponse, tauRelax, dbSNR)
% myUCOResponse generates the response of an exponential response to a
% square wave.
%
% INPUT:
% t: time vector (s).
% baselineRR: average baseline RR (ms).
% deltaResponseRR: maximum change in RR (ms).
% ucoDuration: duration (s).
% restDuration: rest duration, between two UCOs (s).
% tauResponse: time constant to the UCO response.
% tauRelax: time constant when UCO finishes.
% dbSNR: Signal-to-Noise ratio in db.
%
% OUTPUT:
% RR: interbeat interval time series (ms).
% u: UCO signal.
%
% EXAMPLE:
% ucoDuration = 60;
% restDuration = 60;
% baselineRR = 400;
% deltaRRresponse = 400;
% dbSNR = 10;
% tauResponse = 5;
% tauRelax = 20;
% t = (0:baselineRR/1000:10*60);
% [RR, u] = myUCOResponse(t, baselineRR, deltaRRresponse, ucoDuration, restDuration, tauResponse, tauRelax, dbSNR);
% subplot(2, 1, 1)
% plot(t, u);
% xlabel('Time (s)');
% ylabel('Amplitude');
% title('UCO');
% ylim([-0.5, 1.5]);
% subplot(2, 1, 2)
% plot(t, RR);
% xlabel('Time (s)');
% ylabel('RR (ms)');
%
% VERSION:
% 1.0.0 First release.
%
% LAST UPDATE:
% 02/09/2019
param(1) = tauResponse;
param(2) = tauRelax;
param(3) = ucoDuration;
param(4) = restDuration;
x0 = 0;
solution = ode23(@(tt, x) myUCODerivative(tt, x, param), [t(1), t(end)], x0);
data = deval(solution, t);
max_Y = max(data);
min_Y = min(data);
data = (data - min_Y)/(max_Y - min_Y)*deltaResponseRR + baselineRR;
stdNoise = sqrt(var(data)/10^(dbSNR/10));
RR = data + stdNoise*randn(size(t));
if(nargout == 2)
u = myUCO(t, ucoDuration, restDuration);
end
end
function dydt = myUCODerivative(t, y, param)
% myUCODerivative defines the ODE for an exponential response to a square
% wave.
%
% INPUT:
% t: time vector (unit ut).
% y: variable value (unit uy).
% param: 1x4 vector of parameters
% param(1) = tauResponse (ut)
% param(2) = tauRelax (ut)
% param(3) = ucoDuration (ut)
% param(4) = restDuration (ut)
%
% OUTPUT:
% dydt: derivative of y with respect to t (uy/ut).
%
% EXAMPLE:
% t = 0:1/1000:10*60; % (s).
% param(1) = 5;
% param(2) = 10;
% param(3) = 60; % (s).
% param(4) = 30; % (s).
% y = randn(size(t));
% dydt = myUCOResponse(t, y, param);
% plot(t, dydt);
% xlabel('Time (s)');
% ylabel('dy/dt');
%
% VERSION:
% 1.0.0 First release.
%
% LAST UPDATE:
% 02/09/2019
tau1 = param(1);
tau2 = param(2);
ucoDuration = param(3);
restDuration = param(4);
u = myUCO(t, ucoDuration, restDuration);
dydt = -(1/tau2)*y - (1/tau1 - 1/tau2)*(u.*y) + u/tau1;
end