comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirrms.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function varargout = mirrms(x,varargin)
2 % e = mirrms(x) calculates the root mean square energy.
3 % Optional arguments:
4 % mirrms(...,'Frame') computes the temporal evolution of the energy.
5 % mirrms(...,'Root',0) does not apply the root operation to the mean
6 % square energy.
7
8 normal.key = 'Normal';
9 normal.type = 'Boolean';
10 normal.default = 1;
11 option.normal = normal;
12
13 root.key = 'Root';
14 root.type = 'Boolean';
15 root.default = 1;
16 option.root = root;
17
18 specif.option = option;
19
20 specif.defaultframelength = 0.05;
21 specif.defaultframehop = 0.5;
22
23 specif.eachchunk = @eachchunk;
24 specif.combinechunk = @combinechunk;
25 specif.afterchunk = @afterchunk;
26
27 varargout = mirfunction(@mirrms,x,varargin,nargout,specif,@init,@main);
28
29
30 function [x type] = init(x,option)
31 type = 'mirscalar';
32
33
34 function e = main(x,option,postoption)
35 if iscell(x)
36 x = x{1};
37 end
38 d = get(x,'Data');
39 v = mircompute(@algo,d,option);
40 e = mirscalar(x,'Data',v,'Title','RMS energy');
41
42
43 function e = algo(d,option)
44 nl = size(d,1);
45 nc = size(d,2);
46 nch = size(d,3);
47 e = zeros(1,nc,nch);
48 for i = 1:nch
49 for j = 1:nc
50 if option.root
51 e(1,j,i) = norm(d(:,j,i));
52 else
53 e(1,j,i) = d(:,j,i)'*d(:,j,i);
54 end
55 end
56 end
57 if option.normal
58 e = e/sqrt(nl);
59 end
60
61
62 function [y orig] = eachchunk(orig,option,missing,postchunk)
63 option.normal = 0;
64 y = mirrms(orig,option);
65
66
67 function y = combinechunk(old,new)
68 do = get(old,'Data');
69 do = do{1}{1};
70 dn = get(new,'Data');
71 dn = dn{1}{1};
72 y = set(old,'ChunkData',sqrt(do^2+dn^2));
73
74
75 function y = afterchunk(orig,length,postoption)
76 d = get(orig,'Data');
77 v = mircompute(@afternorm,d,length);
78 y = set(orig,'Data',v);
79
80
81 function e = afternorm(d,length)
82 e = d/sqrt(length);