[34f3ea]: filterbank / ifilterbank.m  Maximize  Restore  History

Download this file

132 lines (107 with data), 3.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
function f=ifilterbank(c,g,a,varargin);
%IFILTERBANK Filter bank inversion
% Usage: f=ifilterbank(c,g,a);
%
% `ifilterbank(c,g,a)` synthesizes a signal *f* from the coefficients *c*
% using the filters stored in *g* for a channel subsampling rate of *a* (the
% hop-size). The coefficients has to be in the format returned by
% either |filterbank| or |ufilterbank|.
%
% The filter format for *g* is the same as for |filterbank|.
%
% If perfect reconstruction is desired, the filters must be the duals
% of the filters used to generate the coefficients. See the help on
% |filterbankdual|.
%
% See also: filterbank, ufilterbank, filterbankdual
%
% References: bohlfe02
if nargin<3
error('%s: Too few input parameters.',upper(mfilename));
end;
definput.keyvals.Ls=[];
[flags,kv,Ls]=ltfatarghelper({'Ls'},definput,varargin);
if ~isnumeric(a)
error('%s: a must be numeric.',upper(callfun));
end;
if iscell(c)
Mcoef=numel(c);
W=size(c{1},2);
else
Mcoef=size(c,2);
W=size(c,3);
end;
mustbeuniform=isnumeric(c);
L=filterbanklengthcoef(c,a);
[g,info]=filterbankwin(g,a,L,'normal');
M=info.M;
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;
if ~(M==Mcoef)
error(['Mismatch between the size of the input coefficients and the ' ...
'number of filters.']);
end;
if iscell(c)
f=zeros(L,W,assert_classname(c{1}));
else
a=a(1);
f=zeros(L,W,assert_classname(c));
end;
l=(0:L-1).'/L;
for m=1:M
if isfield(g{m},'h')
g_time=circshift(postpad(g{m}.h,L),g{m}.offset).*...
exp(2*pi*1i*round(g{m}.centre*L/2)*l);
conjG=conj(fft(g_time));
else
conjG=conj(circshift(postpad(g{m}.H(L),L),g{m}.foff(L)).*exp(-2*pi*1i*round(g{m}.delay)*l));
end;
if iscell(c)
for w=1:W
% This repmat cannot be replaced by bsxfun
f(:,w)=f(:,w)+ifft(bsxfun(@times,repmat(fft(c{m}(:,w)),a(m),1),conjG));
end;
else
for w=1:W
% This repmat cannot be replaced by bsxfun
f(:,w)=f(:,w)+ifft(repmat(fft(c(:,m,w)),a,1).*conjG);
end;
end;
end;
% Old stuff from before the struct filters
if 0
if iscell(c)
for m=1:M
for w=1:W
G=fft(fir2long(g{m},L));
% This repmat cannot be replaced by bsxfun
f(:,w)=f(:,w)+ifft(bsxfun(@times,repmat(fft(c{m}(:,w)),a(m),1),conj(G)));
end;
end;
else
a=a(1);
G=zeros(L,M,assert_classname(c,g{1}));
for ii=1:M
G(:,ii)=fft(fir2long(g{ii},L));
end;
f=zeros(L,W,assert_classname(c,g{1}));
for w=1:W
for m=1:M
% This repmat cannot be replaced by bsxfun
f(:,w)=f(:,w)+ifft(repmat(fft(c(:,m,w)),a,1).*conj(G(:,m)));
end;
end;
end;
end;
% Cut or extend f to the correct length, if desired.
if ~isempty(Ls)
f=postpad(f,Ls);
else
Ls=L;
end;