Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/pfallpz2.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 % PFALLPZ2 all pass filtering 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] = pfallpz2(ip,mresp,f,fs) | |
13 % | |
14 % INPUTS: | |
15 % | |
16 % ip: are poles | |
17 % f: is the frequancies vector in (Hz) | |
18 % fs: is the sampling frequency in (Hz) | |
19 % | |
20 % OUTPUTS: | |
21 % | |
22 % resp: is the functions phase frequency response | |
23 % np: are the new stable poles | |
24 % | |
25 % NOTE: | |
26 % | |
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
28 % VERSION: $Id: pfallpz.m,v 1.6 2009/06/10 15:47:00 luigi Exp $ | |
29 % | |
30 % HISTORY: 12-09-2008 L Ferraioli | |
31 % Creation | |
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
33 function varargout = pfallpz2(ip,mresp,f,fs) | |
34 | |
35 [a,b] = size(ip); | |
36 if a<b | |
37 ip = ip.'; % reshape as a column vector | |
38 end | |
39 | |
40 [a,b] = size(f); | |
41 if a<b | |
42 f = f.'; % reshape as a column vector | |
43 end | |
44 | |
45 if isempty(fs) | |
46 fs = 1; | |
47 end | |
48 [a,b] = size(fs); | |
49 if a ~= b | |
50 disp(' Fs has to be a number. Only first term will be considered! ') | |
51 fs = fs(1); | |
52 end | |
53 | |
54 | |
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
56 | |
57 Nb = numel(ip); | |
58 for nn = 1:Nb | |
59 | |
60 p = ip(nn).poles; | |
61 | |
62 % stabilizing poles | |
63 sp = p; | |
64 unst = abs(p) > 1; | |
65 sp(unst) = conj(sp(unst)); | |
66 | |
67 pp = p(unst); | |
68 psp = sp(unst); | |
69 allpstr = '(1'; | |
70 for jj = 1:numel(sp(unst)) | |
71 allpstr = [allpstr sprintf('.*((z-%0.20d)./(z*%0.20d-1))',pp(jj),psp(jj))]; | |
72 end | |
73 allpstr = [allpstr ')']; | |
74 | |
75 funcell{nn} = allpstr; | |
76 | |
77 end | |
78 | |
79 z = cos((2*pi/fs).*f) + 1i.*sin((2*pi/fs).*f); | |
80 fullallprsp = 1; | |
81 | |
82 for nn = 1:Nb | |
83 | |
84 nterm = eval(funcell{nn}); | |
85 % willing to work with columns | |
86 if size(nterm,2)>1 | |
87 nterm = nterm.'; | |
88 end | |
89 | |
90 allprsp(:,nn) = nterm; | |
91 | |
92 fullallprsp = fullallprsp.*nterm; | |
93 | |
94 end | |
95 | |
96 phs = angle(fullallprsp); | |
97 | |
98 for kk=1:Nb | |
99 resp(:,kk) = mresp(:,kk).*(cos(phs)+1i.*sin(phs)); | |
100 end | |
101 | |
102 | |
103 % output | |
104 if nargout == 1 | |
105 varargout{1} = resp; | |
106 else | |
107 error('Too many output arguments!') | |
108 end | |
109 end | |
110 | |
111 | |
112 | |
113 |