forked from ltfat/ltfat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pebfun.m
167 lines (146 loc) · 4.38 KB
/
test_pebfun.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function test_failed = test_pebfun
test_failed = 0;
% First, just test if functions run with various input parameters
M = 10;
a = 8;
L = 120;
incrange = 0:4:80;
g = pebfun(L,[1,-1]);
g = pebfun(L,[1,-1,9]);
%g = ptpfun(L,[1,-1,9],'inf');
gd = pebfundual([1,-1],a,M,L);
gd = pebfundual([1,-1],a,M,L,10);
gd = pebfundual({[1,-1],10},a,M,L);
gd = pebfundual({[1,-1],5},a,M,L,10);
%
% [gd,nlen] = ptpfundual([1,-1],a,M,L,'inf');
%
% [gd,nlen] = ptpfundual([1,-1],a,M,L,'inf','matchscale');
% This should fail, but be caught by some of the input checks.
% We will test if the error message starts with function name in allcaps
% followed by a colon e.g. PTPFUN:
% Too short w
try
g = pebfun(L,[1]);
gd = pebfundual([1],a,M,L);
% We should have failed in g
test_failed = test_failed + 1;
failstr = 'FAILED';
catch
err = lasterror;
[test_failed,failstr]=dititfailedcorrectly(err.message,'pebfun',test_failed);
end
fprintf('PEBFUN Too short w test %s\n',failstr);
% This has been dealt with
% % Only pos weights
% try
% g = ptpfun(L,[1,1]);
% gd = ptpfundual(L,[1,1],a,M);
% % We should have failed in g
% test_failed = test_failed + 1;
% failstr = 'FAILED';
% catch
% err = lasterror;
% [test_failed,failstr]=dititfailedcorrectly(err.message,'ptpfun',test_failed);
% end
% fprintf('PTPFUN Only positive w test %s\n',failstr);
%
% % Only neg weights
% try
% g = ptpfun(L,[-1,-1]);
% gd = ptpfundual(L,[-1,-1],a,M);
% % We should have failed in g
% test_failed = test_failed + 1;
% failstr = 'FAILED';
% catch
% err = lasterror;
% [test_failed,failstr]=dititfailedcorrectly(err.message,'ptpfun',test_failed);
% end
% fprintf('PTPFUN Only negative w test %s\n',failstr);
% One zero in weights
try
g = pebfun(L,[-1,0,1]);
gd = pebfundual([-1,0,1],a,M,L);
% We should have failed in g
test_failed = test_failed + 1;
failstr = 'FAILED';
catch
err = lasterror;
[test_failed,failstr]=dititfailedcorrectly(err.message,'pebfun',test_failed);
end
fprintf('PEBFUN Zero in w test %s\n',failstr);
% Test if ptpfun and ptpfundual indeed fulfill the Waxler-Raz conditions
% (are dual windoes up to scaling) for a range of inc parameter
wcell = {[-1,1],[1,-1,3,4],[-1,-1],[1,1]};
for w = wcell
for inc =incrange
g = pebfun(L,w{1});
gd = pebfundual(w{1},a,M,L);
[~,err] = gabdualnorm(g,gd,a,M,L);
[test_failed,fail]=ltfatdiditfail(err,test_failed);
fprintf('PEBFUN IS DUAL L=%i,a=%i,M=%i, inc=%i %s\n',L,a,M,inc,fail);
end
end
% Test ptpfun and ptpfundual individually (each uses canonical dual window)
f = tester_crand(L,1);
for w = wcell
g = pebfun(L,w{1});
c = dgt(f,g,a,M);
fhat = idgt(c,{'dual',g},a);
res = norm(f-fhat);
[test_failed,fail]=ltfatdiditfail(res,test_failed);
fprintf('PEBFUN REC L=%i,a=%i,M=%i, %s\n',L,a,M,fail);
end
for w = wcell
g = pebfundual(w{1},a,M,L);
c = dgt(f,g,a,M);
fhat = idgt(c,{'dual',g},a);
res = norm(f-fhat);
[test_failed,fail]=ltfatdiditfail(res,test_failed);
fprintf('PEBFUNDUAL REC L=%i,a=%i,M=%i, %s\n',L,a,M,fail);
end
% Test ptpfun and ptpfundual properly scaled
for w = wcell
for inc =incrange
g = pebfun(L,w{1});
gd = pebfundual(w{1},a,M,L,inc);
c = dgt(f,g,a,M);
fhat = idgt(c,gd,a);
res = norm(f-fhat);
[test_failed,fail]=ltfatdiditfail(res,test_failed);
fprintf('PEBFUN PEBFUNDUAL REC L=%i,a=%i,M=%i, inc=%i %s\n',L,a,M,inc,fail);
end
end
% Disabled for now
% for w = wcell
% for inc =incrange
% g = ptpfun(L,w{1},'inf');
% gd = ptpfundual(w{1},a,M,L,inc,'matchscale','inf');
% c = dgt(f,g,a,M);
% fhat = idgt(c,gd,a);
% res = norm(f-fhat);
% [test_failed,fail]=ltfatdiditfail(res,test_failed);
% fprintf('PTPFUN PTPFUNDUAL REC PEAK L=%i,a=%i,M=%i, inc=%i %s\n',L,a,M,inc,fail);
% end
% end
%
% % Test using FIR duals
% wcell = {[-0.5,0.5]};
% for w = wcell
% for inc =incrange
% g = ptpfun(L,w{1});
% [gd,nlen] = ptpfundual(w{1},a,M,L,inc,'matchscale');
% c = dgt(f,g,a,M);
% fhat = idgt(c,middlepad(gd,nlen),a);
% res = norm(f-fhat);
% [test_failed,fail]=ltfatdiditfail(res,test_failed);
% fprintf('PTPFUN PTPFUNDUAL REC FIR L=%i,a=%i,M=%i, inc=%i %s\n',L,a,M,inc,fail);
% end
% end
function [test_failed,failstr]=dititfailedcorrectly(errmsg,fname,test_failed)
if isempty(strfind(errmsg,strcat(upper(fname),':')))
test_failed = test_failed + 1;
failstr = 'FAILED';
else
failstr = '';
end