Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/fromPzmodel.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 % FROMPZMODEL Construct a time-series ao from polynomial coefficients | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: fromPzmodel | |
5 % | |
6 % DESCRIPTION: Construct a time-series ao from polynomial coefficients | |
7 % | |
8 % CALL: a = fromPzmodel(a, pl) | |
9 % | |
10 % PARAMETER: pl: plist containing 'pzmodel', 'Nsecs', 'fs' | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 function a = fromPzmodel(a, pli) | |
14 | |
15 VERSION = '$Id: fromPzmodel.m,v 1.24 2011/08/15 06:09:42 hewitson Exp $'; | |
16 | |
17 % get AO info | |
18 ii = ao.getInfo('ao', 'From Pzmodel'); | |
19 | |
20 % Set the method version string in the minfo object | |
21 ii.setMversion([VERSION '-->' ii.mversion]); | |
22 | |
23 % Add default values | |
24 pl = applyDefaults(ii.plists, pli); | |
25 pl.getSetRandState(); | |
26 | |
27 pzm = find(pl, 'pzmodel'); | |
28 nsecs = find(pl, 'Nsecs'); | |
29 fs = find(pl, 'fs'); | |
30 ndigits = find(pl, 'ndigits'); | |
31 | |
32 % Build t vector | |
33 if isempty(nsecs) || nsecs == 0 | |
34 error('### Please provide ''Nsecs'' for pzmodel constructor.'); | |
35 end | |
36 if isempty(fs) || fs == 0 | |
37 error('### Please provide ''fs'' for pzmodel constructor.'); | |
38 end | |
39 | |
40 % Check if input pzmodel has more zeros than poles | |
41 np = 0; | |
42 for i =1:length(pzm.poles) | |
43 if isnan(pzm.poles(i).q) % simple pole | |
44 np = np + 1; | |
45 elseif pzm.poles(i).q == 0.5 % critical damping | |
46 np = np + 1; | |
47 else % double pole | |
48 np = np + 2; | |
49 end | |
50 end | |
51 nz = 0; | |
52 for i =1:length(pzm.zeros) | |
53 if isnan(pzm.zeros(i).q) | |
54 nz = nz + 1; | |
55 elseif pzm.zeros(i).q == 0.5 | |
56 nz = nz + 1; | |
57 else | |
58 nz = nz + 2; | |
59 end | |
60 end | |
61 if np <= nz | |
62 error('### The noise generator needs more poles than zeros.'); | |
63 end | |
64 % t = linspace(0, nsecs - 1/fs, nsecs*fs); | |
65 | |
66 % Run noise generator | |
67 % conversion | |
68 disp(' - Filter coefficients are calculated from input pzmodel.'); | |
69 [num, den] = ao.ngconv(pzm); | |
70 | |
71 % create matrices | |
72 toolboxinfo = ver('symbolic'); | |
73 | |
74 if isempty(toolboxinfo) | |
75 disp('the time series is calculated without the symbolic math toolbox') | |
76 disp(' - Matrices are calculated from evaluated denominator coefficients.'); | |
77 [Tinit, Tprop, E] = ao.ngsetup(den, fs); | |
78 else | |
79 disp('the time series is calculated using the symbolic math toolbox') | |
80 disp(' - Matrices are calculated from evaluated denominator coefficients.'); | |
81 if isempty(ndigits) | |
82 ndigits = 32; | |
83 warning('### set number of digits to 32!') | |
84 end | |
85 [Tinit, Tprop, E] = ao.ngsetup_vpa(den, fs, ndigits); | |
86 end | |
87 | |
88 % set state vector | |
89 disp(' - Since there is no given state vector it will be calculated.'); | |
90 | |
91 % make initial state vector | |
92 y = ao.nginit(Tinit); | |
93 | |
94 % propagate to make noise vector | |
95 [x, yo] = ao.ngprop(Tprop, E, num, y, fs*nsecs); | |
96 | |
97 % build variables into data object | |
98 t = x*pzm.gain; | |
99 data = tsdata(t,fs); | |
100 | |
101 a.data = data; | |
102 if isempty(pl.find('name')) | |
103 pl.pset('name', sprintf('noisegen(%s)', pzm.name)); | |
104 end | |
105 if isempty(pl.find('description')) | |
106 pl.pset('description', pzm.description); | |
107 end | |
108 | |
109 % Add history | |
110 a.addHistory(ii, pl, [], pzm.hist); | |
111 | |
112 % Set xunits | |
113 a.setXunits(pl.find('xunits')); | |
114 % Set yunits | |
115 a.setYunits(pl.find('yunits')); | |
116 % Set T0 | |
117 a.setT0(pl.find('t0')); | |
118 % Set toffset | |
119 a.setToffset(pl.find('toffset')); | |
120 | |
121 % Set object properties from the plist | |
122 a.setObjectProperties(pl); | |
123 | |
124 end | |
125 | |
126 |