0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % MTXIIRRESP calculate iir resp by matrix product
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % INPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % fil: a miir filter or a vector of filoters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % freq: the frequency vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % fs: sampling frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % bank: filterbank type parameter ('parallel', 'serial' or 'none').
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % If it is left empty, it provide a vector of responses at the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % output.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 function rsp = mtxiirresp(fil,freq,fs,bank)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 T = 1/fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 Nfil = numel(fil);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 if Nfil>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % check for different orders
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 sza = zeros(Nfil,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 szb = zeros(Nfil,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 for jj=1:Nfil
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 sza(jj) = numel(fil(jj).a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 szb(jj) = numel(fil(jj).b);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 Ncl = max([sza;szb]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 sza = numel(fil.a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 szb = numel(fil.b);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 Ncl = max([sza szb]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 % init A and B
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 A = zeros(Nfil,Ncl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 B = zeros(Nfil,Ncl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % get filters coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 if Nfil>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 for ii=1:Nfil
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 A(ii,1:sza(ii)) = fil(ii).a;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 B(ii,1:szb(ii)) = fil(ii).b;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 A(1:sza) = fil.a;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 B(1:szb) = fil.b;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 % build Z matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 Z = ones(size(A,2),numel(freq));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 zz = exp(-2.*pi.*1i.*T.*freq);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 for jj=2:size(Z,1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 Z(jj,:) = zz.^(jj-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 % get numerator and denominator
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 num = A*Z;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 den = B*Z;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % get response
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 rspm = num./den;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 if Nfil>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 switch lower(bank)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 case 'parallel'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 rsp = sum(rspm,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 case 'serial'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 rsp = prod(rspm,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 rsp = rspm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 rsp = rspm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 end |