-
Notifications
You must be signed in to change notification settings - Fork 0
/
hilbert_extraction.m
46 lines (38 loc) · 981 Bytes
/
hilbert_extraction.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
function [ AM, FM ] = hilbert_extraction( D, fs, varargin )
% [ AM, FM ] = HILBERT_EXTRACTION( D, fs, thres )
% AM and FM extraction of D (sampling frequency fs) with Hilbert
% transform. thres is an optional argument for artifact rejection
% (consider FM only in regions where AM>thres).
%
% Leo Varnet 2016 - last modified 11/10/2018
nbch = size(D,1);
if length(varargin)==0
thres = 0;
elseif length(varargin)==1
thres = varargin{1};
elseif length(varargin)>1
error('too many arguments in function hilbert_extraction')
end
t=(1:length(D))/fs;
if isreal(D)
hilbert_responses = hilbert(D);
else
hilbert_responses = D;
end
% AM extraction
for k=1:nbch,
AM(k,:)=abs(hilbert_responses(k,:));
end
if nargout>1
% FM extraction
for k=1:nbch
TFS(k,:) = unwrap(angle(hilbert_responses(k,:)));
FM(k,:) = (1/(2*pi))*gradient(TFS(k,:),t);
end
end
for k=1:nbch,
if thres>0
FM(k,AM(k,:)<thres)=NaN;
end
end
end