Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/pfallps.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % PFALLPS all pass filtering in order to stabilize TF poles and zeros. | |
2 % | |
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4 % DESCRIPTION: | |
5 % | |
6 % All pass filtering in order to stabilize transfer function poles and | |
7 % zeros. It inputs a partial fraction expanded discrete model and | |
8 % outputs a pole-zero minimum phase system | |
9 % | |
10 % CALL: | |
11 % | |
12 % [resp,np] = pfallps(ir,ip,id,mresp,f) | |
13 % [resp,np] = pfallps(ir,ip,id,mresp,f,minphase) | |
14 % [resp,np,nz] = pfallps(ir,ip,id,mresp,f,minphase) | |
15 % | |
16 % INPUTS: | |
17 % | |
18 % ir: are residues | |
19 % ip: are poles | |
20 % id: is direct term | |
21 % f: is the frequancies vector in (Hz) | |
22 % minphase: is a flag assuming true (output a minimum phase system) or | |
23 % false (output a stable non minimum phase system) values. Default, | |
24 % true | |
25 % | |
26 % OUTPUTS: | |
27 % | |
28 % resp: is the minimum phase frequency response | |
29 % np: are new stable poles | |
30 % nz: are new stable zeros, this will be set only if minphase is set to | |
31 % false | |
32 % | |
33 % NOTE: | |
34 % | |
35 % This function make use of signal analysis toolbox functions | |
36 % | |
37 % | |
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
39 % VERSION: $Id: pfallps.m,v 1.7 2008/12/22 18:44:42 luigi Exp $ | |
40 % | |
41 % HISTORY: 12-09-2008 L Ferraioli | |
42 % Creation | |
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
44 function varargout = pfallps(ir,ip,id,mresp,f,varargin) | |
45 | |
46 % Reshaping | |
47 [a,b] = size(ir); | |
48 if a<b | |
49 ir = ir.'; % reshape as a column vector | |
50 end | |
51 | |
52 [a,b] = size(ip); | |
53 if a<b | |
54 ip = ip.'; % reshape as a column vector | |
55 end | |
56 | |
57 [a,b] = size(f); | |
58 if a<b | |
59 f = f.'; % reshape as a column vector | |
60 end | |
61 | |
62 [a,b] = size(id); | |
63 if a > b | |
64 id = id.'; % reshape as a row | |
65 id = id(1,:); % taking the first row (the function can handle only simple constant direct terms) | |
66 end | |
67 | |
68 if nargin == 6 | |
69 minphase = varargin{1}; | |
70 else | |
71 minphase = false; | |
72 end | |
73 | |
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
75 | |
76 % stabilizing poles | |
77 sp = p; | |
78 unst = real(sp) > 0; | |
79 sp(unst) = -1*conj(sp(unst)); | |
80 | |
81 [Na,Nb] = size(r); | |
82 for nn = 1:Nb | |
83 | |
84 s = 1i.*2.*pi.*f; | |
85 pp = p(unst); | |
86 psp = sp(unst); | |
87 for ii = 1:length(s) | |
88 nterm = 1; | |
89 for jj = 1:length(sp(unst)) | |
90 nterm = nterm.*(s(ii)-pp(jj))./(s(ii)-psp(jj)); | |
91 end | |
92 phs(ii,1) = angle(nterm); | |
93 end | |
94 | |
95 resp(:,nn) = mresp(:,nn).*(cos(phs)+1i.*sin(phs)); | |
96 | |
97 % output stable poles | |
98 np(:,nn) = sp; | |
99 | |
100 if minphase | |
101 % finding zeros | |
102 [num,den] = residue(r,p,d); | |
103 zrs = roots(num); | |
104 | |
105 % stabilizing zeros | |
106 szrs = zrs; | |
107 zunst = abs(zrs) > 1; | |
108 szrs(zunst) = 1./conj(zrs(zunst)); | |
109 | |
110 zzrs = zrs(zunst); | |
111 zszrs = szrs(zunst); | |
112 for ii = 1:length(s) | |
113 nterm = 1; | |
114 for jj = 1:length(szrs(zunst)) | |
115 nterm = nterm.*(s(ii)-zszrs(jj))./(s(ii)-zzrs(jj)); | |
116 end | |
117 zphs(ii,1) = angle(nterm); | |
118 end | |
119 | |
120 resp(:,nn) = resp(:,nn).*(cos(zphs)+1i.*sin(zphs)); | |
121 | |
122 % output stable zeros | |
123 nz(:,nn) = szrs; | |
124 end | |
125 end | |
126 % output | |
127 if nargout == 1 | |
128 varargout{1} = resp; | |
129 elseif nargout == 2 | |
130 varargout{1} = resp; | |
131 varargout{2} = np; | |
132 elseif (nargout == 3) && minphase | |
133 varargout{1} = resp; | |
134 varargout{2} = np; | |
135 varargout{3} = nz; | |
136 else | |
137 error('Too many output arguments!') | |
138 end | |
139 end |