-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_phase.m
More file actions
executable file
·38 lines (32 loc) · 837 Bytes
/
calc_phase.m
File metadata and controls
executable file
·38 lines (32 loc) · 837 Bytes
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
function signal_phase = calc_phase(signal)
% calc_phase.m
%
% Calculates the instantaneous node phases
%
% Input: signal : signal [NxT]
%
% Output: signal_phase : instantaneous phases [NxT]
%
% Original: James Roberts
% Edited: James Pang, QIMR Berghofer, 2020
%%
if size(signal,2) > size(signal,1)
flip = 1;
signal = signal';
end
if length(signal)<200000
% short but inefficient with memory
% calculate phase
signal_phase = unwrap(angle(hilbert(bsxfun(@minus,signal,mean(signal)))));
else
% inelegant but uses less memory
signal_phase = zeros(size(signal));
nn = size(signal,2);
for jj=1:nn
y = signal(:,jj);
signal_phase(:,jj) = unwrap(angle(hilbert(y-mean(y))));
end
end
if flip
signal_phase = signal_phase';
end