Mercurial > hg > ltpda
comparison m-toolbox/classes/@pz/resp.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 % RESP returns the complex response of the pz object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: RESP returns the complex response of the pz object. The | |
5 % response is computed assuming that object represents a pole. | |
6 % If the object represents a zero, just take the inverse of | |
7 % the returned response: 1./r. | |
8 % | |
9 % CALL: [f,r] = resp(p, f); % compute response for vector f | |
10 % [f,r] = resp(p, f1, f2, nf); % compute response from f1 to f2 | |
11 % % in nf steps. | |
12 % [f,r] = resp(p, f1, f2, nf, scale); % compute response from f1 to f2 | |
13 % % in nf steps using scale ['lin' or 'log']. | |
14 % [f,r] = resp(p); % compute response | |
15 % | |
16 % REMARK: This is just a helper function. This function should only be | |
17 % called from class functions. | |
18 % | |
19 % VERSION: $Id: resp.m,v 1.9 2011/02/18 16:48:54 ingo Exp $ | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function [f,r] = resp(varargin) | |
24 | |
25 %%% Input objects checks | |
26 if nargin < 1 | |
27 error('### incorrect number of inputs.') | |
28 end | |
29 | |
30 %%% look at inputs | |
31 p = varargin{1}; | |
32 if ~isa(p, 'pz') | |
33 error('### first argument should be a pz object.'); | |
34 end | |
35 | |
36 %%% decide whether we modify the pz-object, or create a new one. | |
37 p = copy(p, nargout); | |
38 | |
39 %%% Now look at the pole | |
40 f0 = p.f; | |
41 Q = p.q; | |
42 | |
43 %%% Define frequency vector | |
44 f = []; | |
45 | |
46 if nargin == 1 | |
47 f1 = f0/10; | |
48 f2 = f0*10; | |
49 nf = 1000; | |
50 scale = 'lin'; | |
51 elseif nargin == 2 | |
52 f = varargin{2}; | |
53 elseif nargin == 4 | |
54 f1 = varargin{2}; | |
55 f2 = varargin{3}; | |
56 nf = varargin{4}; | |
57 scale = 'lin'; | |
58 elseif nargin == 5 | |
59 f1 = varargin{2}; | |
60 f2 = varargin{3}; | |
61 nf = varargin{4}; | |
62 scale = varargin{5}; | |
63 else | |
64 error('### incorrect number of inputs.'); | |
65 end | |
66 | |
67 %%% Build f if we need it | |
68 if isempty(f) | |
69 switch lower(scale) | |
70 case 'lin' | |
71 f = linspace(f1, f2, nf); | |
72 case 'log' | |
73 f = logspace(log10(f1), log10(f2), nf); | |
74 end | |
75 end | |
76 | |
77 | |
78 %%% Now compute the response | |
79 if Q>=0.5 | |
80 re = 1 - (f.^2./f0^2); | |
81 im = f ./ (f0*Q); | |
82 r = 1./complex(re, im); | |
83 else | |
84 re = 1; | |
85 im = f./f0; | |
86 r = 1./complex(re, im); | |
87 end | |
88 end | |
89 |