-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetDWT.m
84 lines (73 loc) · 2.38 KB
/
getDWT.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
% function [cD cA] = getDWT(X,N,Name)
%
% finds the discrete wavelet transform at level N for signal X using the
% wavelet specified by Name.
%
%% Inputs:
% X: the original signal
% N: the decomposition level
% Name: the wavelet name to use
%
%% Outputs:
% cD is a N-row matrix containing the detail coefficients up to N levels
% cA is the same for the approximations
% This code was developed by David Springer for comparison purposes in the
% paper:
% D. Springer et al., "Logistic Regression-HSMM-based Heart Sound
% Segmentation," IEEE Trans. Biomed. Eng., In Press, 2015.
%
%% Copyright (C) 2016 David Springer
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
function [cD cA] = getDWT(X,N,Name)
%No DWT available for Morlet - therefore perform CWT:
if(strcmp(Name,'morl'))
c = cwt(X,1:N,'morl');
cD = c;
cA = c;
else
%Preform wavelet decomposition
[c,l] = wavedec(X,N,Name);
%Reorder the details based on the structure of the wavelet
%decomposition (see help in wavedec.m)
len = length(X);
cD = zeros(N,len);
for k = 1:N
d = detcoef(c,l,k);
d = d(:)';
d = d(ones(1,2^k),:);
cD(k,:) = wkeep1(d(:)',len);
end
cD = cD(:);
%Space cD according to spacing of floating point numbers:
I = find(abs(cD)<sqrt(eps));
cD(I) = zeros(size(I));
cD = reshape(cD,N,len);
% cD = wcodemat(cfd,nbcol,'row');
%Reorder the approximations based on the structure of the wavelet
%decomposition (see help in wavedec.m)
len = length(X);
cA = zeros(N,len);
for k = 1:N
a = appcoef(c,l,Name,k);
a = a(:)';
a = a(ones(1,2^k),:);
cA(k,:) = wkeep1(a(:)',len);
end
cA = cA(:);
I = find(abs(cA)<sqrt(eps));
cA(I) = zeros(size(I));
cA = reshape(cA,N,len);
end