-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwfiltfn.m
89 lines (87 loc) · 3.76 KB
/
wfiltfn.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
% function psihfn = wfiltfn(type, opt)
%
% Wavelet transform function of the wavelet filter in question,
% fourier domain.
%
% Input:
% type: string (see below)
% opt: options structure, e.g. struct('s',1/6,'mu',2)
%
% Output:
% anonymous function @(xi) psihfn(xi)
%
% Filter types Use for synsq? Parameters (default)
%
% gauss yes s (1/6), mu (2)
% mhat no s (1)
% cmhat yes s (1), mu (1)
% morlet yes mu (2*pi)
% shannon no -- (NOT recommended for analysis)
% hshannon yes -- (NOT recommended for analysis)
% hhat no
% hhhat yes mu (5)
% bump yes s (1), mu (5)
%
% Example:
% psihfn = wfiltfn('bump', struct('mu',1,'s',.5));
% plot(psihfn(-5:.01:5));
%
%---------------------------------------------------------------------------------
% Synchrosqueezing Toolbox
% Authors: Eugene Brevdo (http://www.math.princeton.edu/~ebrevdo/)
%---------------------------------------------------------------------------------
function psihfn = wfiltfn(type, opt)
switch type
case 'gauss',
% Similar to morlet, but can control bandwidth
% can be used with synsq for large enough mu/s ratio
if ~isfield(opt,'s'), s = 1/6; else s = opt.s; end
if ~isfield(opt,'mu'), mu = 2; else mu = opt.mu; end
psihfn = @(w) 2.^(-(w-mu).^2/(2*s^2));
case 'mhat', % mexican hat
if ~isfield(opt,'s'), s = 1; else s = opt.s; end
psihfn = @(w) -sqrt(8)*s^(5/2)*pi^(1/4)/sqrt(3)*w.^2.*exp(-s^2*w.^2/2);
case 'cmhat',
% complex mexican hat: hilbert analytic function of sombrero
% can be used with synsq
if ~isfield(opt,'s'), s = 1; else s = opt.s; end
if ~isfield(opt,'mu'), mu = 1; else mu = opt.mu; end
psihfnshift = @(w)2*sqrt(2/3)*pi^(-1/4)*s^(5/2)*w.^2.*exp(-s^2*w.^2/2).*(w>=0);
psihfn = @(w) psihfnshift(w-mu);
case 'morlet',
% can be used with synsq for large enough s (e.g. >5)
if ~isfield(opt,'mu'), mu = 2*pi; else mu = opt.mu; end
cs = (1+exp(-mu^2)-2*exp(-3/4*mu^2)).^(-1/2);
ks = exp(-1/2*mu^2);
psihfn = @(w)cs*pi^(-1/4)*(exp(-1/2*(mu-w).^2)-ks*exp(-1/2*w.^2));
case 'shannon',
psihfn = @(w)exp(-i*w/2).*(abs(w)>=pi & abs(w)<=2*pi);
case 'hshannon',
% hilbert analytic function of shannon transform
% time decay is too slow to be of any use in synsq transform
if ~isfield(opt,'mu'), mu = 0; else mu = opt.mu; end
psihfnshift = @(w)exp(-i*w/2).*(w>=pi & w<=2*pi).*(1+sign(w));
psihfn = @(w) psihfnshift(w-mu);
case 'hhat', % hermitian hat
psihfn = @(w)2/sqrt(5)*pi^(-1/4)*w.*(1+w).*exp(-1/2*w.^2);
case 'hhhat',
% hilbert analytic function of hermitian hat
% can be used with synsq
if ~isfield(opt,'mu'), mu = 5; else mu = opt.mu; end
psihfnshift = @(w)2/sqrt(5)*pi^(-1/4)*(w.*(1+w).*exp(-1/2*w.^2)) .* (1+sign(w));
psihfn = @(w) psihfnshift(w-mu);
case 'bump',
if ~isfield(opt,'mu'), mu = 5; else mu = opt.mu; end
if ~isfield(opt,'s'), s = 1; else s = opt.s; end
psihfnorig = @(w)exp(-1./(1-w.^2)) .* (abs(w)<1);
psihfn = @(w) psihfnorig((w-mu)/s);
case 'mostafa',
load ss
if ~isfield(opt,'mu'), mu = 5; else mu = opt.mu; end
if ~isfield(opt,'s'), s = 1; else s = opt.s; end
psihfnorig = @(w)(0.0720*w.^8)+(0.2746*w.^7)+(0.2225*w.^6)+(-0.2781*w.^5)+(-0.3884*w.^4)+(0.0735*w.^3)+(-0.3354*w.^2)+(-0.0043*w)+(0.3675);
psihfn = @(w) psihfnorig((w-mu)/s);
otherwise
error('Unknown wavelet type: %s', type);
end % switch type
end