comparison m-toolbox/classes/+utils/@math/pfallpsyms2.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 % PFALLPSYMS2 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= pfallpsyms2(ip,mresp,f,fs)
13 %
14 % INPUTS:
15 %
16 % ip: is a struct with fields named poles
17 % mresp: is a vector with functions response
18 % f: is the frequancies vector in (Hz)
19 % fs: is the sampling frequency in (Hz)
20 %
21 % OUTPUTS:
22 %
23 % resp: is the stable functions frequency response
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 = pfallpsyms2(ip,mresp,f)
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
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 Nb = numel(ip);
48 for nn = 1:Nb
49
50 p = ip(nn).poles;
51
52 % stabilizing poles
53 sp = sym(p);
54 unst = real(p) > 0;
55 sp(unst) = conj(sp(unst));
56
57 pp = sym(p(unst));
58 psp = sp(unst);
59 syms s
60 allpsym = 1;
61 for jj=1:numel(psp)
62 allpsym = allpsym.*((s-pp(jj))./(s+psp(jj)));
63 end
64 funcell{nn} = allpsym;
65
66 end
67
68 fullallprsp = 1;
69
70 for nn = 1:Nb
71 symexpr = funcell{nn};
72 nterm = subs(symexpr,s,(1i*2*pi).*f);
73 % willing to work with columns
74 if size(nterm,2)>1
75 nterm = nterm.';
76 end
77
78 fullallprsp = fullallprsp.*nterm;
79
80 end
81
82 % rallp = real(fullallprsp);
83 % iallp = imag(fullallprsp);
84 % ang = atan(iallp./rallp);
85
86 for kk=1:Nb
87 sresp(:,kk) = mresp(:,kk).*fullallprsp;
88 % sresp(:,kk) = mresp(:,kk).*(cos(ang)+1i.*sin(ang));
89 end
90
91 for kk=1:Nb
92 resp(:,kk) = double(sresp(:,kk));
93 end
94
95
96 % output
97 if nargout == 1
98 varargout{1} = resp;
99 else
100 error('Too many output arguments!')
101 end
102 end
103
104
105
106