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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
function test_failed = test_pebfun
test_failed = 0;
%-*- texinfo -*-
%@deftypefn {Function} test_pebfun
%@verbatim
% First, just test if functions run with various input parameters
%@end verbatim
%@strong{Url}: @url{http://ltfat.github.io/doc/testing/test_pebfun.html}
%@end deftypefn
% Copyright (C) 2005-2016 Peter L. Soendergaard <peter@sonderport.dk>.
% This file is part of LTFAT version 2.2.0
%
% 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
% (at your option) 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/>.
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
|