1function test_failed=test_constructphase 2%-*- texinfo -*- 3%@deftypefn {Function} test_constructphase 4%@verbatim 5%TEST_CONSTRUCTPHASE 6% 7%@end verbatim 8%@strong{Url}: @url{http://ltfat.github.io/doc/testing/test_constructphase.html} 9%@end deftypefn 10 11% Copyright (C) 2005-2016 Peter L. Soendergaard <peter@sonderport.dk>. 12% This file is part of LTFAT version 2.3.1 13% 14% This program is free software: you can redistribute it and/or modify 15% it under the terms of the GNU General Public License as published by 16% the Free Software Foundation, either version 3 of the License, or 17% (at your option) any later version. 18% 19% This program is distributed in the hope that it will be useful, 20% but WITHOUT ANY WARRANTY; without even the implied warranty of 21% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22% GNU General Public License for more details. 23% 24% You should have received a copy of the GNU General Public License 25% along with this program. If not, see <http://www.gnu.org/licenses/>. 26test_failed = 0; 27 28disp(' =================== TEST_CONSTRUCTPHASE ====================== '); 29 30forig = greasy; 31g = 'gauss'; 32a = 16; 33M = 1024; 34 35tolcell = {1e-10,[1e-1 1e-10],[1e-1 1e-3 1e-10]}; 36Warray = [1, 3]; 37 38for W=Warray 39 f = repmat(forig,1,W); 40 f = bsxfun(@times,f,[1:W]); 41 42 global LTFAT_TEST_TYPE; 43 if strcmpi(LTFAT_TEST_TYPE,'single') 44 f = cast(f,'single'); 45 end 46 47 for pcId = 1:2 48 % Complex case 49 phaseconv = getat({'timeinv','freqinv'},pcId); 50 51 for tId = 1:numel(tolcell) 52 tol = getat(tolcell,tId); 53 tolstr = sprintf('%.2e, ',tol); 54 tolstr = tolstr(1:end-2); 55 56 57 tra = @(f) dgt(f,g,a,M,phaseconv); 58 itra = @(c) idgt(c,{'dual',g},a,phaseconv); 59 proj = @(c) tra(itra(c)); 60 c = tra(f); 61 s = abs(c); 62 63 64 % Normal call 65 chat = constructphase(s,g,a,tol,phaseconv); 66 67 E = comperr(s,proj(chat)); 68 69 fail = ''; 70 if E>-19 71 test_failed = test_failed + 1; 72 fail = 'FAILED'; 73 end 74 75 fprintf('CONSTRUCTPHASE %s tol=[%s] W=%d E=%.2f %s\n',phaseconv,tolstr,W,E,fail); 76 77 % Known part 78 mask = zeros(size(s)); 79 mask(:,1:floor(size(s,2)/2),:) = 1; 80 chat = constructphase(s,g,a,tol,mask,angle(c),phaseconv); 81 E = comperr(s,proj(chat)); 82 chat2 = constructphase(c,g,a,tol,mask,phaseconv); 83 E2 = comperr(s,proj(chat2)); 84 85 fail = ''; 86 if E>-19 || abs(E-E2) > 0.1 87 test_failed = test_failed + 1; 88 fail = 'FAILED'; 89 end 90 91 fprintf('CONSTRUCTPHASE MASK %s tol=[%s] W=%d E=%.2f %s\n',phaseconv,tolstr,W,E,fail); 92 93 94 tra = @(f) dgtreal(f,g,a,M,phaseconv); 95 itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 96 proj = @(c) tra(itra(c)); 97 c = tra(f); 98 s = abs(c); 99 100 chat = constructphasereal(s,g,a,M,tol,phaseconv); 101 102 E = comperr(s,proj(chat)); 103 104 fail = ''; 105 if E>-18 106 test_failed = test_failed + 1; 107 fail = 'FAILED'; 108 end 109 110 fprintf('CONSTRUCTPHASEREAL %s tol=[%s] W=%d E=%.2f %s\n',phaseconv,tolstr,W,E,fail); 111 112 113 % Known part 114 mask = zeros(size(s)); 115 mask(:,1:floor(size(s,2)/2),:) = 1; 116 chat = constructphasereal(s,g,a,M,tol,mask,angle(c),phaseconv); 117 E = comperr(s,proj(chat)); 118 chat2 = constructphasereal(c,g,a,M,tol,mask,phaseconv); 119 E2 = comperr(s,proj(chat2)); 120 121 fail = ''; 122 if E>-19 || abs(E-E2) > 0.1 123 test_failed = test_failed + 1; 124 fail = 'FAILED'; 125 end 126 127 fprintf('CONSTRUCTPHASEREAL MASK %s tol=[%s] W=%d E=%.2f %s\n',phaseconv,tolstr,W,E,fail); 128 end 129 end 130end 131 132 133function el = getat(collection,id) 134if iscell(collection) 135 el = collection{id}; 136else 137 el = collection(id); 138end 139 140 141function E = comperr(s,c) 142 143 144E = 20*log10(norm(abs(s(:))-abs(c(:)),'fro')/norm(abs(s(:)),'fro')); 145 146 147 148