blob: 39abd44461c80a6aa72d06089be056aeb868335d (
plain)
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
|
//Root mean squared value \
//Y=rms(X);
//Y=rms(X,dim);
//For vectors, RMS(X) is the root mean squared value in X. For matrices,
// RMS(X) is a row vector containing the RMS value from each column. For
// N-D arrays, RMS(X) operates along the first non-singleton dimension.
//
// Y = RMS(X,DIM) operates along the dimension DIM.
//
// When X is complex, the RMS is computed using the magnitude
// RMS(ABS(X)).
//Author Debdeep Dey
function y = rms(x, dim)
//convert i/p values to their ascii values if they are of type char
if(type(x)==10) then
xa=x;
x=ascii(x);
x=matrix(x,size(xa));
end
if argn(2)==1
[rm,cm]=size(x);
if(rm>1) then
y = sqrt(mean((x .* conj(x)),'r'));
else
y=sqrt(mean((x.*conj(x))));
end
else
if(dim==1)
y = sqrt(mean((x .* conj(x)),'r'));
else
y = sqrt(mean((x .* conj(x)),'c'));
end
end
endfunction
|