[797cbb]: blockproc / blockana.m  Maximize  Restore  History

Download this file

173 lines (152 with data), 5.2 kB

  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
function [c, fola] = blockana(F, f, fola)
%BLOCKANA Blockwise analysis interface
% Usage: c=blockana(F, f)
%
% Input parameters:
% Fa : Analysis frame object.
% f : Block of signal.
% fola : Explicitly defined overlap
% Output parameters:
% c : Block coefficients.
% fola : Stored overlap
%
% `c=blockana(Fa,f)` calculates the coefficients *c* of the signal block *f* using
% the frame defined by *F*. The block overlaps are handled according to the
% `F.blokalg`. Assuming |blockana| is called in the loop only once, *fola*
% can be omitted and the overlaps are handled in the background
% automatically.
%
% See also: block, blocksyn, blockplay
if nargin<2
error('%s: Too few input parameters.',upper(mfilename));
end;
if ~isstruct(F)
error('%s: First agument must be a frame definition structure.',upper(mfilename));
end;
if nargin<3
fola = [];
end
% Block length
Lb = size(f,1);
% Next block index start (from a global point of view, starting with zero)
nextSb = block_interface('getPos');
% Block index start (from a global point of view, starting with zero)
Sb = nextSb-Lb;
if strcmp(F.blokalg,'sliced')
% General processing
% Equal block length assumtion
% Append the previous block
fext = [loadOverlap(Lb,size(f,2),fola);f];
% Save the current block
if nargout>1
fola = storeOverlap(fext,Lb);
else
storeOverlap(fext,Lb);
end
% Multiply by the slicing window (all channels)
fwin = bsxfun(@times,F.sliwin,fext);
fwin = [fwin; zeros(F.L-size(fwin,1),size(fwin,2))];
% Apply transform
c = F.frana(fwin);
elseif strcmp(F.blokalg,'segola')
if ~isfield(F,'winLen')
error('%s: Frame does not have FIR windows.',upper(mfilename));
end
Lw = F.winLen;
switch(F.type)
case 'fwt'
J = F.J;
w = F.g;
m = numel(w.h{1}.h);
a = w.a(1);
if Lb<a^J
error('%s: Minimum block length is %i.',upper(mfilename),a^J);
end
rred = (a^J-1)/(a-1)*(m-a);
Sbolen = rred + mod(Sb,a^J);
nextSbolen = rred + mod(nextSb,a^J);
% Extend from the left side
fext = [loadOverlap(Sbolen,size(f,2),fola);f];
% Save the overlap for the next block
if nargout>1
fola = storeOverlap(fext,nextSbolen);
else
storeOverlap(fext,nextSbolen);
end
c = block_fwt(fext,w,J);
% Uniform window lengths
case {'dgtreal','dgt'}
% if Lb<F.a
% error('%s: Minimum block length is %i.',upper(mfilename),F.a);
% end
a = F.a;
Lwl = floor(Lw/2);
% Overlap length
Sbolen = ceil((Lw-1)/a)*a + mod(Sb,a);
% Next block overlap length
nextSbolen = ceil((Lw-1)/a)*a + mod(nextSb,a);
Lext = Sbolen + Lb - nextSbolen + Lwl;
startc = ceil(Lwl/a)+1;
endc = ceil((Lext)/a);
% Extend from the left side
fext = [loadOverlap(Sbolen,size(f,2),fola);f];
% Save the overlap for the next block
if nargout>1
fola = storeOverlap(fext,nextSbolen);
else
storeOverlap(fext,nextSbolen);
end
% Pad with zeros to comply with the frame requirements
fext = [fext; zeros(F.L-size(fext,1),size(fext,2))];
c = F.frana(fext(1:F.L,:));
% Pick just valid coefficients
cc = F.coef2native(c,size(c));
cc = cc(:,startc:endc,:);
c = F.native2coef(cc);
case {'filterbank','filterbankreal','ufilterbank','ufilterbankreal'}
otherwise
error('%s: Unsupported frame.',upper(mfilename));
end
elseif strcmp(F.blokalg,'naive')
f = [f; zeros(F.L-size(f,1),size(f,2))];
c = F.frana(f);
else
error('%s: Frame was not created with blockaccel.',upper(mfilename));
end
end % BLOCKANA
function overlap = loadOverlap(L,chan,overlap)
%LOADOVERLAP Loads overlap
%
%
if isempty(overlap)
overlap = block_interface('getAnaOverlap');
end
% Supply zeros if it is empty
if isempty(overlap)
overlap = zeros(L,chan,block_interface('getClassId'));
end
Lo = size(overlap,1);
if nargin<1
L = Lo;
end
% If required more than stored, do zero padding
if L>Lo
oTmp = zeros(L,size(overlap,2));
oTmp(end-Lo+1:end) = oTmp(end-Lo+1:end)+overlap;
overlap = oTmp;
else
overlap = overlap(end-L+1:end,:);
end
end % LOADOVERLAP
function overlap = storeOverlap(fext,L)
%STOREOVERLAP Stores overlap
%
%
if L>size(fext,1)
error('%s: Storing more samples than passed.',upper(mfilename));
end
overlap = fext(end-L+1:end,:);
if nargout<1
block_interface('setAnaOverlap',overlap);
end
end % STOREOVERLAP

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks