File: test_pfilt.m

package info (click to toggle)
octave-ltfat 2.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,256 kB
  • ctags: 3,340
  • sloc: ansic: 13,629; cpp: 6,764; java: 1,499; objc: 345; makefile: 177; python: 103; sh: 18
file content (174 lines) | stat: -rw-r--r-- 4,603 bytes parent folder | download
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
function test_failed=test_pfilt
Lr =[27,100,213];
%-*- texinfo -*-
%@deftypefn {Function} test_pfilt
%@verbatim
% 
%@end verbatim
%@strong{Url}: @url{http://ltfat.github.io/doc/testing/test_pfilt.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/>.
 gr{1}=randn(20,1);
 gr{2}=randn(21,1);
 gr{3}=firfilter('hanning',19);
 gr{4}=firfilter('hanning',20);
 gr{5}=randn(4,1);
 gr{6}=firfilter('hanning',20,'causal');
 gr{7}=firfilter('hanning',20,'delay',13); 
 gr{8}=firfilter('hanning',20,'delay',-13); 
 gr{7}=firfilter('hanning',20,'delay',14); 
 gr{8}=firfilter('hanning',20,'delay',-14); 
 gr{9}=firfilter('hamming',19,.3); 
 gr{10}=firfilter('hamming',19,.3,'real');
 gr{11}=blfilter('hanning',.19);
 gr{12}=blfilter('hanning',.2);
 gr{13}=blfilter('hanning',.132304);
 gr{14}=blfilter('hanning',.23,'delay',13);
 gr{15}=blfilter('hamming',.23,.3);
 gr{16}=blfilter('hamming',.23,.3,'real');
 % (almost) Allpass filter
 gr{17}=blfilter('hanning',2);
 gr{18}=blfilter('hanning',1);
 gr{19}=blfilter('hanning',2,1);
 gr{20}=blfilter('hanning',1,-1);
 gr{21}=blfilter('hamming',.1,-.3);
 gr{22}=blfilter('hanning',1.7);



% REMARK: modcent is applied to fc

test_failed=0;

disp(' ===============  TEST_PFILT ==============');

disp('--- Used subroutines ---');
which comp_filterbank_td
which comp_filterbank_fft
which comp_filterbank_fftbl
which comp_filterbank

disp('--- Regular subsampling ---');
for ii=1:numel(gr)
  % Skip empry fields in gr
  g=gr{ii};
  if isempty(g)
      continue;
  end


  for a=1:3
      for jj=1:length(Lr)
          % Create input signal of proper length
          L=ceil(Lr(jj)/a)*a;
      
          for W=1:3
              
              for rtype=1:2
                  if rtype==1
                      rname='REAL ';	
                      f=tester_rand(L,W);
                  else
                      rname='CMPLX';	
                      f=tester_crand(L,W);
                  end;
                  
                                   
                  h2=ref_pfilt(f,g,a);
                  h1=pfilt(f,g,a);
				  
                   res=norm(h1-h2);
                  [test_failed,fail]=ltfatdiditfail(res,test_failed);        
                  s=sprintf('PFILT %3s  filtno:%3i L:%3i W:%3i a:%3i %0.5g %s',rname,ii,L,W,a,res,fail);
                  disp(s);
              end;
          end;
      end;
      
  end;
  
end;

disp('--- Fractional subsampling ---');

% Pick just bl filters
idx = cellfun(@(grEl) isfield(grEl,'H'),gr);
tmpRange = 1:numel(gr);
tmpRange = tmpRange(idx);


for ii=tmpRange
  g = gr{ii};
  for jj=1:length(Lr)
    L = Lr(jj);
    % Find support and offset of the filter
    tmpH = g.H(L);
    if numel(tmpH) == L
        % this is no longer a band pass filter
    end
        
    foff = g.foff(L);
    
    Nmin = numel(tmpH);
    
    for Nalt=[-3,-7,3,0];
        % Nalt==0 painless
        % Nalt>0 painless 
        % Nalt<0 not painless
        if Nmin + Nalt <=0
            a = [L,1];
        elseif Nmin + Nalt >= L
            % This is no longer fractional subsampling
            a = [L,L];    
        else
            a = [L,Nmin+Nalt];
        end
        
        
    for W=1:3
        for rtype=1:2
              if rtype==1
                  rname='REAL ';	
                  f=tester_rand(L,W);
              else
                  rname='CMPLX';	
                  f=tester_crand(L,W);
              end;
              
              
                  h2=ref_pfilt(f,g,a);
                  h1=pfilt(f,g,a);
				  
                   res=norm(h1-h2);
                  [test_failed,fail]=ltfatdiditfail(res,test_failed);        
                  s=sprintf('PFILT %3s  filtno:%3i L:%3i W:%3i a:[%3i,%3i], fb: %i, %0.5g %s',...
                            rname,ii,L,W,a(1),a(2),Nmin,res,fail);
                  disp(s);
              
        end
    end
    end
  end
  
end