Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Commit [931198] Maximize Restore History

filterbankdual/tigh/bounds show now work for the painless case

Peter L. Søndergaard Peter L. Søndergaard 2013-06-10

1 2 > >> (Page 1 of 2)
removed deprecated/scalardistribute.m
removed filterbank/filterbankframediag.m
changed Contents.m
changed comp
changed comp/comp_fourierwindow.m
changed comp/comp_transferfunction.m
changed demos
changed demos/demo_nextfastfft.m
changed deprecated
changed filterbank
changed filterbank/filterbankbounds.m
changed filterbank/filterbankdual.m
changed filterbank/filterbankrealbounds.m
changed filterbank/filterbankrealdual.m
changed filterbank/filterbankrealtight.m
changed filterbank/filterbankresponse.m
changed filterbank/filterbanktight.m
changed filterbank/filterbankwin.m
changed filterbank/ifilterbank.m
changed fourier
changed fourier/blfilter.m
changed fourier/firfilter.m
changed fourier/magresp.m
changed fourier/pfilt.m
changed nonstatgab
changed nonstatgab/nsgabframebounds.m
changed reference
changed reference/ref_ufilterbank.m
copied comp/assert_filterbankinput.m -> scalardistribute.m
deprecated/scalardistribute.m
File was removed.
Contents.m Diff Switch to side-by-side view
Loading...
comp
Directory.
comp/comp_fourierwindow.m Diff Switch to side-by-side view
Loading...
comp/comp_transferfunction.m Diff Switch to side-by-side view
Loading...
demos
Directory.
demos/demo_nextfastfft.m Diff Switch to side-by-side view
Loading...
deprecated
Directory.
filterbank
Directory.
filterbank/filterbankbounds.m Diff Switch to side-by-side view
Loading...
filterbank/filterbankdual.m Diff Switch to side-by-side view
Loading...
filterbank/filterbankrealbounds.m Diff Switch to side-by-side view
Loading...
filterbank/filterbankrealdual.m Diff Switch to side-by-side view
Loading...
filterbank/filterbankrealtight.m Diff Switch to side-by-side view
Loading...
filterbank/filterbankresponse.m Diff Switch to side-by-side view
Loading...
filterbank/filterbanktight.m Diff Switch to side-by-side view
Loading...
filterbank/filterbankwin.m Diff Switch to side-by-side view
Loading...
filterbank/ifilterbank.m Diff Switch to side-by-side view
Loading...
fourier
Directory.
fourier/blfilter.m Diff Switch to side-by-side view
Loading...
fourier/firfilter.m Diff Switch to side-by-side view
Loading...
fourier/magresp.m Diff Switch to side-by-side view
Loading...
fourier/pfilt.m Diff Switch to side-by-side view
Loading...
nonstatgab
Directory.
nonstatgab/nsgabframebounds.m Diff Switch to side-by-side view
Loading...
reference
Directory.
reference/ref_ufilterbank.m Diff Switch to side-by-side view
Loading...
comp/assert_filterbankinput.m to scalardistribute.m
--- a/comp/assert_filterbankinput.m
+++ b/scalardistribute.m
@@ -1,53 +1,76 @@
-function [a,M,longestfilter,lcm_a]=assert_filterbankinput(g,a,mustbeuniform);
+function varargout=scalardistribute(varargin)
+%SCALARDISTRIBUTE  Copy scalar to array shape for parameter handling
+%   Usage:  [...] = scalardistribute(...);
+%
+%   `[...]=scalardistribute(...)` copies the input parameters to the
+%   output parameters.
+%
+%   * If one of the input parameters is an array, all the output parameters
+%     will be column vectors containing the same number of elements. If one
+%     of the other input parameters is a scalar, it will be replicated to
+%     the correct length. This allows a scalar value to be repeated for
+%     all conditions.
+%
+%   * If two or more input parameters are arrays, the must have the exact
+%     same size. They will be converted to vectors and returned in the
+%     output parameters. This allows two arrays to co-vary at the same time.
+%
+%   This operator is usefull for sanitizing input parameters: The user is
+%   allowed to enter scalars or arrays as input paremeters. These input
+%   are in turn passed to `scalardistribute`, which makes sure that the
+%   arrays have the same shape, and that scalars are replicated. The user
+%   of `scalardistibute` can now generate conditions based on all the
+%   parameters, and be sure the have the right sizes.
+%
+%   As an example, consider:::
+%
+%     [a,b,c]=scalardistribute(1,[2,3],[4,5])
 %
   
-  if nargin<3
-    mustbeuniform=0;
+  npars=length(varargin);
+  
+  scalartest=zeros(npars,1);
+  for ii=1:npars
+    if ~isnumeric(varargin{ii})
+      error('%s: Input no. %i must be numerical.',upper(mfilename),ii);
+    end;
+    if isempty(varargin{ii})
+      error('%s: Input no. %i is empty.',upper(mfilename),ii);
+    end;
+
+    scalartest(ii)=isscalar(varargin{ii});
+  end;
+
+  idx=find(scalartest==0);
+  
+  % Tjeck that all non-scalars have the same shape
+  for jj=1:numel(idx)
+    ref_size  = size(varargin{idx(1)});
+    this_size = size(varargin{idx(jj)});
+    if any((ref_size-this_size)~=0)
+      error('%s: Input no. %i and no. %i must have the same shape.',upper(mfilename),idx(1),idx(jj));
+    end;
+  end;  
+
+  if numel(idx)==0
+    % All arguments are scalar, so this is just a dummy, but it must
+    % still be defined for the code not to fail.
+    shape=1;
+  else
+    shape=ones(numel(varargin{idx(1)}),1);
   end;
   
-  f=dbstack;  
-  callfun=f(2).name;
-
-  if ~iscell(g)
-    error('%s: g must be a cell-array.',upper(callfun));
-  end;
-
-  M=numel(g);
-  
-  if ~isnumeric(a)
-    error('%s: a must be numeric.',upper(callfun));
+  varargout=cell(1,npars);
+  for ii=1:npars
+    if scalartest(ii)
+      % Replicate scalar
+      varargout{ii}=shape*varargin{ii};
+    else
+      % Copy input and turn it into a vector. This would be a one-liner
+      % in Octave.
+      tmp=varargin{ii};
+      varargout{ii}=tmp(:);
+    end;
   end;
   
-  if mustbeuniform
-    if ~isscalar(a) || a<=0
-      error('%s: "a" must be a positive scalar.',upper(callfun));
-    end;
-    
-    lcm_a=a;
-  
-  else
-
-    if ~isvector(a) || any(a<=0)
-      error('%s: "a" must be a vector of positive numbers.',upper(callfun));
-    end;
-
-    if length(a)>1 
-      if  length(a)~=M
-        error(['%s: The number of entries in "a" must match the number of ' ...
-               'filters.'],upper(callfun));
-      end;
-    else
-      a=a*ones(M,1);
-    end;
-    
-    % This code works in Octave, but not in Matlab, so we have to iterate
-    % through "a" to calculate the lcm.
-    %lcm_a=lcm(num2cell(a){:});
-    lcm_a=a(1);
-    for m=2:M
-      lcm_a=lcm(lcm_a,a(m));
-    end;
-  end;
-    
-  longestfilter=max(cellfun(@numel,g));
-
+  
1 2 > >> (Page 1 of 2)