-
Notifications
You must be signed in to change notification settings - Fork 3
/
filterbank.m
70 lines (63 loc) · 2.06 KB
/
filterbank.m
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
function M = filterbank(B,A,X,N,SQ,T)
% M = filterbank(B,A,X,N,SQ,T) Apply an IIR filterbank to a signal.
% Takes the filterbank defined by B and A, where each row is
% the coefficients to an IIR filter, and applies each to X,
% generating a matrix output M whose each row is a filtered
% version of X using a different filter. If N is specified
% and greater than zero, the outputs are rectified. If it is
% greater than 1, the (rectified) outputs are smoothed and
% subsampled by that factor. If SQ is present and nonzero, and N>0
% perform the smoothing on the squared outputs, then root again.
% T, if present, is a vector of *delays* for each filter, which
% are to be compensated-out by discarding the first few samples
% of the corresponding channel.
% dpwe 1994jun21. Uses subsmooth.m (and built-in 'filter')
RECT = 1;
if((nargin<4) | (N==0)) N = 1; RECT=0; end
if(nargin<5) SQ = 0; end
if(nargin<6) T = 0; end
% recover number of filters
s = size(A);
bands = s(1); % number of rows in A
if(vsize(T)<bands)
T = T(1) * ones(1, bands);
end
% find size of X
xsize = max(size(X));
% initialize output array to full size
% transpose domain - avoids quite so much swapping during inner loop
M = zeros(floor((xsize+N-1)/N),bands);
% normal domain
%M = zeros(bands,floor((xsize+N-1)/N));
% calculate each row
for filt = 1:bands
% disp(['band ' int2str(filt)]);
% get filter parameters
a = A(filt, :);
b = B(filt, :);
t = round(T(filt)); % samples to shift must be an integer
% pad t zeros on the end, since we're going to chop from tail
y = filter(b,a,[X,zeros(1,t)]);
ly = vsize(y);
% shift the output to discard the first <t> samples
y = y([(t+1):ly]);
if RECT > 0
if SQ == 0
% rectify the signal before smoothing it
y = max(y,0);
if(N>1)
y = subsmooth(y, N, 2*N+1);
end
else % SQ nonzero so do in squared domain
y = y.*y;
if(N>1)
y = subsmooth(y, N, 2*N+1);
end
y = sqrt(y);
end;
end;
% M(filt,:) = y;
M(:,filt) = y';
end
% if transpose domain
M=M';