Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/pf2ss.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 % PF2SS Convert partial fraction models to state space matrices | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % DESCRIPTION: | |
4 % | |
5 % Convert partial fraction models to state space matrices. This method | |
6 % works only for poles of multiplicity one. In case of multiple parfrac | |
7 % models they must have the same set of poles. | |
8 % | |
9 % | |
10 % CALL: | |
11 % | |
12 % [A,B,C,D] = pf2ss(pf) | |
13 % | |
14 % INPUTS: | |
15 % | |
16 % Assuming to have M pf models with N poles (common to every model) | |
17 % | |
18 % - res, vector of matrix of residuals NxM, M is the number of pf | |
19 % models | |
20 % - poles, vector of poles Nx1 | |
21 % - dterm, vector of direct terms, Mx1 | |
22 % | |
23 % OUTPUT: | |
24 % | |
25 % - A matrix | |
26 % - B matrix | |
27 % - C matrix | |
28 % - D matrix | |
29 % | |
30 % | |
31 % | |
32 % NOTE: | |
33 % | |
34 % This method works only for poles of multiplicity one. | |
35 % In case of multiple parfrac models they must have the same set of poles | |
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
37 % HISTORY: 29-01-2010 L Ferraioli | |
38 % Creation | |
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
40 % VERSION: '$Id: vcfit.m,v 1.10 2009/04/21 10:15:35 luigi Exp $'; | |
41 % | |
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
43 function [A,B,C,D] = pf2ss(res,poles,dterm) | |
44 | |
45 [N,M]=size(res); | |
46 | |
47 % pf = varargin{:}; | |
48 % | |
49 % %%% get poles, residues and direct terms | |
50 % poles = pf(1).poles; % a common set of poles is assumed | |
51 % | |
52 % N = length(poles); | |
53 % M = numel(pf); | |
54 % | |
55 % res = zeros(N,M); % init residues matrix | |
56 % | |
57 % if size(poles,2)>1 | |
58 % poles = poles.'; | |
59 % end | |
60 % dterm = zeros(M,1); % init dterm matrix | |
61 % | |
62 % for ii=1:M | |
63 % r = pf(ii).res; | |
64 % if size(r,2)>1 | |
65 % r = r.'; | |
66 % end | |
67 % res(:,ii) = r; | |
68 % dterm(ii,1) = pf(ii).dir; | |
69 % end | |
70 | |
71 %%% Marking complex and real poles | |
72 % cindex = 1; pole is complex, next conjugate pole is marked with cindex | |
73 % = 2. cindex = 0; pole is real | |
74 cindex=zeros(1,N); | |
75 for m=1:N | |
76 if imag(poles(m))~=0 | |
77 if m==1 | |
78 cindex(m)=1; | |
79 else | |
80 if cindex(m-1)==0 || cindex(m-1)==2 | |
81 cindex(m)=1; cindex(m+1)=2; | |
82 else | |
83 cindex(m)=2; | |
84 end | |
85 end | |
86 end | |
87 end | |
88 | |
89 %%% Build SS matrices | |
90 % init matrices | |
91 A = diag(poles); | |
92 B = ones(N,M); | |
93 C = res.'; | |
94 D = dterm; | |
95 | |
96 for kk = 1:N | |
97 if cindex(kk) == 1 | |
98 A(kk,kk)=real(poles(kk)); | |
99 A(kk,kk+1)=imag(poles(kk)); | |
100 A(kk+1,kk)=-1*imag(poles(kk)); | |
101 A(kk+1,kk+1)=real(poles(kk)); | |
102 B(kk,:) = 2; | |
103 B(kk+1,:) = 0; | |
104 C(:,kk+1) = imag(C(:,kk)); | |
105 C(:,kk) = real(C(:,kk)); | |
106 end | |
107 end | |
108 | |
109 end | |
110 |