-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShannonSmoothEnvelope.m
68 lines (62 loc) · 2.05 KB
/
ShannonSmoothEnvelope.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
function [ShEn] = ShannonSmoothEnvelope(x,th,Fs)
%===================================================================
% ____ _
% / ___|| |__ __ _ _ __ _ __ ___ _ __ ___
% \___ \| '_ \ / _` | '_ \| '_ \ / _ \| '_ \/ __|
% ___) | | | | (_| | | | | | | | (_) | | | \__ \
% |____/|_| |_|\__,_|_| |_|_| |_|\___/|_| |_|___/
%
% _____ _
% | ____|_ ____ _____| | ___ _ __ ___
% | _| | '_ \ \ / / _ \ |/ _ \| '_ \ / _ \
% | |___| | | \ V / __/ | (_) | |_) | __/
% |_____|_| |_|\_/ \___|_|\___/| .__/ \___|
% |_|
% ____ _ _ _ _
% / ___|__ _| | ___ _ _| | __ _| |_(_) ___ _ __
% | | / _` | |/ __| | | | |/ _` | __| |/ _ \| '_ \
% | |__| (_| | | (__| |_| | | (_| | |_| | (_) | | | |
% \____\__,_|_|\___|\__,_|_|\__,_|\__|_|\___/|_| |_|
%
% Function based on [1]:
% [1] Varghees, V. N., & Ramachandran, K. I. (2017).
% Effective Heart Sound Segmentation and Murmur Classification Using
% Empirical Wavelet Transform and Instantaneous Phase for
% Electronic Stethoscope. IEEE Sensors Journal, 17(12), 3861-3872.
% Created by: Roilhi Frajo Ibarra Hernandez, May 2018
% 1) Adaptive Amplitude Tresholding
N = length(x);
L = 0.03*Fs; % Window length of 30ms
DL = buffer(x,L); %Signal windowing in non-overlaping frames (columns)
muL = mean(DL,2);
% Adaptive noise-level tresholding
eta_n = median(muL)/0.6745;
eta_n = eta_n+0.01;
xTh = zeros(size(x));
for k=1:N
if abs(x(k))>eta_n
xTh(k) = abs(x(k));
else
xTh(k) = 0;
end
end
% Shannons entropy calculation
ShPrEn = -xTh.*log(xTh);
ShPrEn(isnan(ShPrEn))=0;
% Zero-phase smoothing filter
% Creating the impulse response (rectangular pulse)
h_k = [zeros(1,0.090*Fs) ones(1,0.060*Fs)];
% Filtering to smooth the entropy and getting the envelope
ShEn = filtfilt(h_k,1,ShPrEn);
ShEn = ShEn/max(ShEn);
%sigma = std(Sm);
sigma = th;
% Envelope tresholding
for r = 1:length(ShEn)
if ShEn(r) > sigma
ShEn(r)=ShEn(r);
else
ShEn(r)=0;
end
end