Diff of /blockproc/blockana.m [a9068d] .. [4530c5] Maximize Restore

  Switch to unified view

a/blockproc/blockana.m b/blockproc/blockana.m
...
...
10
%
10
%
11
%   `c=blockana(Fa,f)` calculates the coefficients *c* of the signal block *f* using 
11
%   `c=blockana(Fa,f)` calculates the coefficients *c* of the signal block *f* using 
12
%   the frame defined by *Fa*.
12
%   the frame defined by *Fa*.
13
%
13
%
14
%   See also: block, blocksyn, blockplay
14
%   See also: block, blocksyn, blockplay
15
    
16
    if nargin<2
17
        error('%s: Too few input parameters.',upper(mfilename));
18
    end;
19
    
20
    if ~isstruct(F)
21
        error('%s: First agument must be a frame definition structure.',upper(mfilename));
22
    end;
23
    
24
    % Block length
25
    Lb = size(f,1);
26
    % Next block index start (from a global point of view, starting with zero)
27
    nextSb = block_interface('getPos');
28
    % Block index start (from a global point of view, starting with zero)
29
    Sb = nextSb-Lb;
30
    
31
    switch(F.type)
32
      case 'fwt'
33
        J = F.J;
34
        w = F.g;
35
        m = numel(w.h{1}.h);
36
        a = w.a(1);
37
        if Lb<a^J
38
            error('%s: Minimum block length is %i.',upper(mfilename),a^J);
39
        end
40
        rred = (a^J-1)/(a-1)*(m-a);
41
        Sbolen = rred + mod(Sb,a^J);
42
        nextSbolen = rred + mod(nextSb,a^J);
43
        fext = [loadOverlap(Sbolen,size(f,2));f];
44
        c = block_fwt(fext,w,J);
45
        storeOverlap(fext,nextSbolen);
46
      otherwise
47
        % General processing
48
        % Equal block length assumtion
49
        % Slicing window
50
        g = fftshift(firwin('hann',2*Lb));
51
        % Append the previous block
52
        fext = [loadOverlap(Lb,size(f,2));f];
53
        % Save the current block
54
        storeOverlap(fext,Lb);
55
        % Multiply by the slicing window (all channels)
56
        fwin = bsxfun(@times,g,fext);
57
        % Apply transform
58
        c = F.frana(fwin);
59
    end
15
60
16
if nargin<2
61
end % BLOCKANA
17
  error('%s: Too few input parameters.',upper(mfilename));
18
end;
19
20
if ~isstruct(F)
21
  error('%s: First agument must be a frame definition structure.',upper(mfilename));
22
end;
23
24
% Block length
25
Lb = size(f,1);
26
% Next block index start (from a global point of view, starting with zero)
27
nextSb = block_interface('getPos');
28
% Block index start (from a global point of view, starting with zero)
29
Sb = nextSb-Lb;
30
31
switch(F.type)
32
   case 'fwt'
33
      J = F.J;
34
      w = F.g;
35
      m = numel(w.h{1}.h);
36
      a = w.a(1);
37
      if Lb<a^J
38
         error('%s: Minimum block length is %i.',upper(mfilename),a^J);
39
      end
40
      rred = (a^J-1)/(a-1)*(m-a);
41
      Sbolen = rred + mod(Sb,a^J);
42
      nextSbolen = rred + mod(nextSb,a^J);
43
      fext = [loadOverlap(Sbolen,size(f,2));f];
44
      c = block_fwt(fext,w,J);
45
      storeOverlap(fext,nextSbolen);
46
   otherwise
47
      % General processing
48
      % Equal block length assumtion
49
      % Slicing window
50
      g = fftshift(firwin('hann',2*Lb));
51
      % Append the previous block
52
      fext = [loadOverlap(Lb,size(f,2));f];
53
      % Save the current block
54
      storeOverlap(fext,Lb);
55
      % Multiply by the slicing window (all channels)
56
      fwin = bsxfun(@times,g,fext);
57
      % Apply transform
58
      c = F.frana(fwin);
59
end
60
62
61
function overlap = loadOverlap(L,chan)
63
function overlap = loadOverlap(L,chan)
62
%LOADOVERLAP Loads overlap
64
%LOADOVERLAP Loads overlap
63
%
65
%
64
%
66
%
65
overlap = block_interface('getAnaOverlap');
67
    overlap = block_interface('getAnaOverlap');
66
% Supply zeros if it is empty
68
    % Supply zeros if it is empty
67
if isempty(overlap)
69
    if isempty(overlap)
68
   overlap = zeros(L,chan,block_interface('getClassId'));
70
        overlap = zeros(L,chan,block_interface('getClassId'));
69
end
71
    end
70
Lo = size(overlap,1);
72
    Lo = size(overlap,1);
71
if nargin<1
73
    if nargin<1
72
   L = Lo;
74
        L = Lo;
73
end
75
    end
74
% If required more than stored, do zero padding
76
    % If required more than stored, do zero padding
75
if L>Lo
77
    if L>Lo
76
   oTmp = zeros(L,size(overlap,2));
78
        oTmp = zeros(L,size(overlap,2));
77
   oTmp(end-Lo+1:end) = oTmp(end-Lo+1:end)+overlap;
79
        oTmp(end-Lo+1:end) = oTmp(end-Lo+1:end)+overlap;
78
   overlap = oTmp;
80
        overlap = oTmp;
79
else
81
    else
80
   overlap = overlap(end-L+1:end,:);
82
        overlap = overlap(end-L+1:end,:);
81
end
83
    end
82
84
    
83
end % LOADOVERLAP
85
end % LOADOVERLAP
84
86
85
function storeOverlap(fext,L)
87
function storeOverlap(fext,L)
86
%STOREOVERLAP Stores overlap
88
%STOREOVERLAP Stores overlap
87
%
89
%
88
%
90
%
89
if L>size(fext,1)
91
    if L>size(fext,1)
90
   error('%s: Storing more samples than passed.',upper(mfilename));
92
        error('%s: Storing more samples than passed.',upper(mfilename));
91
end
93
    end
92
block_interface('setAnaOverlap',fext(end-L+1:end,:)); 
94
    block_interface('setAnaOverlap',fext(end-L+1:end,:)); 
93
end % STOREOVERLAP
95
end % STOREOVERLAP
94
96
95
end % BLOCKANA