comparison m-toolbox/classes/@ao/rms.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 % RMS Calculate RMS deviation from spectrum
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: RMS Calculate RMS deviation from spectrum
5 %
6 % CALL: b=rms(a)
7 %
8 % INPUTS: a - input analysis object containing spectrum
9 %
10 % OUTPUTS: b - analysis object containing RMS deviation
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'rms')">Parameters Description</a>
13 %
14 % VERSION: $Id: rms.m,v 1.22 2011/04/08 08:56:11 hewitson Exp $
15 %
16 % NOTE: Taken from code by: 1998.05.25 Masaki Ando
17 %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
20 function varargout = rms(varargin)
21
22 % Check if this is a call for parameters
23 if utils.helper.isinfocall(varargin{:})
24 varargout{1} = getInfo(varargin{3});
25 return
26 end
27
28 import utils.const.*
29 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
30
31 % Collect input variable names
32 in_names = cell(size(varargin));
33 for ii = 1:nargin,in_names{ii} = inputname(ii);end
34
35 % Collect all AOs and plists
36 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
37
38 % Decide on a deep copy or a modify
39 bs = copy(as, nargout);
40
41 % Loop over input AOs
42 for j=1:numel(bs)
43 % check input data
44 if isa(bs(j).data, 'fsdata')
45 % get data
46 f = bs(j).data.getX;
47 spe = [f bs(j).data.getY];
48 % start and end frequencies
49 s = f(1);
50 e = f(end);
51 % compute integrated rms
52 l1=spe(:,1)>=s;
53 sp=spe(l1,:);
54 l2=sp(:,1)<=e;
55 sp=sp(l2,:);
56 si=size(sp);
57 li=si(1,1);
58 freq=sp(:,1);
59 sp2=sp(:,2).^2;
60 ms=sp2;
61 for i= li-1 :-1: 1
62 ms(i)=ms(i+1)+(sp2(i+1)+sp2(i))*(freq(i+1)-freq(i))/2;
63 end
64 % set data
65 bs(j).data.setXY(freq, sqrt(ms));
66 % set name
67 bs(j).name = sprintf('RMS(%s)', ao_invars{j});
68 % Add history
69 bs(j).addHistory(getInfo('None'), plist, ao_invars(j), bs(j).hist);
70 % clear errors
71 bs(j).clearErrors;
72 else
73 warning('!!! Skipping AO %s - it''s not an frequency series.', ao_invars{j});
74 end
75 end
76
77 % Set output
78 if nargout == numel(bs)
79 % List of outputs
80 for ii = 1:numel(bs)
81 varargout{ii} = bs(ii);
82 end
83 else
84 % Single output
85 varargout{1} = bs;
86 end
87 end
88
89 %--------------------------------------------------------------------------
90 % Get Info Object
91 %--------------------------------------------------------------------------
92 function ii = getInfo(varargin)
93 if nargin == 1 && strcmpi(varargin{1}, 'None')
94 sets = {};
95 pl = [];
96 else
97 sets = {'Default'};
98 pl = getDefaultPlist;
99 end
100 % Build info object
101 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: rms.m,v 1.22 2011/04/08 08:56:11 hewitson Exp $', sets, pl);
102 end
103
104 %--------------------------------------------------------------------------
105 % Get Default Plist
106 %--------------------------------------------------------------------------
107 function plout = getDefaultPlist()
108 persistent pl;
109 if exist('pl', 'var')==0 || isempty(pl)
110 pl = buildplist();
111 end
112 plout = pl;
113 end
114
115 function pl = buildplist()
116 pl = plist.EMPTY_PLIST;
117 end
118 % END
119