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