summaryrefslogtreecommitdiff
path: root/macros/movingrms.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/movingrms.sci')
-rw-r--r--macros/movingrms.sci128
1 files changed, 104 insertions, 24 deletions
diff --git a/macros/movingrms.sci b/macros/movingrms.sci
index 231a9f1..07e6f87 100644
--- a/macros/movingrms.sci
+++ b/macros/movingrms.sci
@@ -1,33 +1,113 @@
-function [rmsx,w]=movingrms(x,w,rc,Fs)
+function [rmsx, w] = movingrms(x, width, risetime, varargin)
// Find moving RMS value of signal in x
+
// Calling Sequence
-// [rmsx,w]=movingrms(x,w,rc,Fs=1)
+//[rmsx,w]=movingrms(x,width,risetime)
+//[rmsx,w]=movingrms(x,width,risetime,Fs)
+
// Parameters
-// x: Real or complex valued vector or matrix
-// w: Real or complex scalar value
-// rc: Real or complex scalar value
-// Fs: Real or complex scalar value
+// x: (Real or complex valued vector or matrix) Input Signal
+// width: Real or complex scalar value
+// risetime: Real or complex scalar value
+// Fs: (Real or complex scalar value) Sampling frequency
+
// Description
-// This is an Octave function.
-// The signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1).
-// Examples
-// 1. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2)
-// a = 0.91237 17.71929 0.96254
-// 0.91237 17.71929 0.96254
-// b = 0.18877
-// 0.18877
-// 2. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2,2)
-// a = 4.8332 93.8669 5.0990
-// 4.8332 93.8669 5.0990
-// b = 1
-// 1
+// In this function signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1).
+
+// Example : 1
+//[a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2)
+// Output:
+// b =
+//
+// 0.1887703
+// 0.1887703
+// a =
+//
+// 0.9123683 17.719291 0.9625436
+// 0.9123683 17.719291 0.9625436
+
+//Example : 2
+// [a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2,2)
+//Output :
+// b =
+//
+// 1.
+// 1.
+// a =
+//
+// 4.8332184 93.866927 5.0990195
+// 4.8332184 93.866927 5.0990195
funcprot(0);
-rhs=argn(2);
-if (rhs<3) then
- error("Wrong number of input arguments.")
-elseif (rhs==3) then Fs=1;
+
+//**************************************************************************************************
+//______________________________________________version1 code (not working)_________________________
+//__________________________________________________________________________________________________
+//**************************************************************************************************
+
+//rhs=argn(2);
+//if (rhs<3) then
+// error("Wrong number of input arguments.")
+//elseif (rhs==3) then Fs=1;
+//end
+//[rmsx,w]=callOctave("movingrms",x,w,rc,Fs)
+
+//**************************************************************************************************
+//______________________________________________version2 code ( working)____________________________
+//__________________________________________________________________________________________________
+//**************************************************************************************************
+if argn(2) > 4 | argn(2) < 3 then
+ error("movingrms : wrong number of inputs ")
end
-[rmsx,w]=callOctave("movingrms",x,w,rc,Fs)
+
+ if length(varargin)==0 then
+ Fs = 1;
+ else
+ Fs = varargin(1);
+ end
+
+ [N nc] = size (x);
+ if width*Fs > N/2
+ idx = [1 N];
+ w = ones(N,1);
+ else
+ idx = round ((N + width*Fs*[-1 1])/2);
+ w = sigmoid_train((1:N)', idx, risetime*Fs);
+ end
+ fw = fft (w.^2);
+ //fx = fft (x.^2); itdoes columwise fft in Octave but in scilab it does 2D fft
+
+ //Evaluating columnwise fft using for loop
+ fx = [];
+ for k = 1:nc
+ fx = [fx fft(x(:,k).^2)];
+ k = k + 1;
+ end
+ //end of Evaluating columnwise fft using for loop
+
+ // in octave fx.*fw does row element wise multiplication but it is inconsistance in scilab
+ //doing it using for loop
+ fxw = [];
+ for k = 1:N
+ fxw = [fxw ; fx(k,:).*fw(k,:)]
+ end
+ //end of fxw computation
+
+ //rmsx = real(ifft (fxw)/(N-1)); itdoes columwise ifft in Octave but in scilab it does 2D ifft
+ //Evaluating columnwise ifft using for loop
+ ifxw = [];
+ for k = 1:nc
+ ifxw = [ifxw ifft(fxw(:,k))];
+ k = k + 1;
+ end
+
+ rmsx = real(ifxw/(N-1))
+ //end of Evaluating columnwise ifft using for loop
+
+ rmsx (rmsx < %eps*max(rmsx(:))) = 0;
+
+ rmsx = circshift (sqrt (rmsx), round(mean(idx)));
+ //##w = circshift (w, -idx(1));
+
endfunction