Repository navigation
Expand file tree
/
Copy pathrms.m
More file actions
75 lines (58 loc) · 1.45 KB
/
Copy pathrms.m
File metadata and controls
75 lines (58 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% SIG.RMS
%
% Copyright (C) 2014, 2017, Olivier Lartillot
%
% All rights reserved.
% License: New BSD License. See full text of the license in LICENSE.txt in
% the main folder of the MiningSuite distribution.
function varargout = rms(varargin)
varargout = sig.operate('sig','rms',...
initoptions,@init,@main,@after,varargin,'plus');
end
%%
function options = initoptions
options = sig.signal.signaloptions('FrameAuto',.05,.5);
end
%%
function [x type] = init(x,option,frame)
type = 'sig.signal';
end
function out = main(in,option)
x = in{1};
if ~strcmpi(x.yname,'RMS')
d = sig.compute(@routine,x.Ydata);
x = sig.signal(d,'Name','RMS',...
'Srate',x.Frate,'Ssize',x.Ssize,...
'FbChannels',x.fbchannels);
end
out = {x};
end
function out = routine(d)
if find(strcmp('element',d.dims))
dim = 'element';
else
dim = 'sample';
end
e = d.apply(@algo,{},{dim},1);
e = e.deframe;
out = {e};
end
function y = algo(x)
y = x'*x;
end
function out = after(in,option)
x = in{1};
if find(strcmp('element',x.Ydata.dims))
dim = 'element';
else
dim = 'sample';
end
x.Ydata = sig.compute(@routine_norm,x.Ydata,x.Ssize,dim);
out = {x};
end
function d = routine_norm(d,Ssize,dim)
d = d.apply(@afternorm,{Ssize},{dim},Inf);
end
function d = afternorm(d,l)
d = sqrt(d/l);
end