Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/pzmodel2SSMats.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 function [A,B,C,D] = pzmodel2SSMats(pzm) | |
2 if (~numel(pzm)==1) || (~isa(pzm, 'pzmodel')) | |
3 error(['function ' mfilename ' only accepts one pzmodel as an input']) | |
4 end | |
5 | |
6 den = 1; | |
7 num = 1; | |
8 G = pzm.gain; | |
9 | |
10 % computing the A matrix | |
11 for i=1:length(pzm.poles) | |
12 if isnan(pzm.poles(i).q) | |
13 w0 = pzm.poles(i).f*2*pi ; | |
14 den = conv(den,[1 w0]); | |
15 G = G * w0; | |
16 else | |
17 q = pzm.poles(i).q; | |
18 w0 = 2*pi*pzm.poles(i).f; | |
19 p = [1, 1/q*w0 w0^2]; | |
20 den = conv(den,p); | |
21 G = G * w0 * w0; | |
22 end | |
23 end | |
24 | |
25 % computing the C matrix | |
26 for i=1:length(pzm.zeros) | |
27 if isnan(pzm.zeros(i).q) | |
28 w0 = pzm.zeros(i).f*2*pi ; | |
29 num = conv(num,[1 w0]); | |
30 G = G / w0; | |
31 else | |
32 q = pzm.zeros(i).q; | |
33 w0 = 2*pi*pzm.zeros(i).f; | |
34 p = [1, 1/q*w0 w0^2]; | |
35 num = conv(num,p); | |
36 G = G / w0 / w0; | |
37 end | |
38 end | |
39 | |
40 % setting gain | |
41 num = num*G; | |
42 | |
43 % zero padding TF numerator if degree is smaller than denominator | |
44 Nss = length(den)-1; | |
45 if length(num)<Nss+1 | |
46 num = [zeros(1,Nss+1-length(num)) num]; | |
47 end | |
48 | |
49 % computing the D/C matrix | |
50 [q,r] = deconv(num,den); % polynmial division for den = conv(num,q)+r . | |
51 if ~length(q)==1 | |
52 error('system may be non causal'); | |
53 end | |
54 | |
55 % Allocating matrices | |
56 D = q; | |
57 A = [zeros(Nss-1,1) eye(Nss-1); fliplr(-den(2:(Nss+1)))]; | |
58 B = zeros(Nss,1); | |
59 if Nss>0 | |
60 B(Nss) = 1; | |
61 end | |
62 C = fliplr(r(2:(Nss+1))); | |
63 | |
64 end |