summaryrefslogtreecommitdiff
path: root/macros/tukeywin.sci
diff options
context:
space:
mode:
authorSunil Shetye2018-07-25 17:11:09 +0530
committerSunil Shetye2018-07-26 23:50:17 +0530
commit1251f70aa3442736ce6fd9c4fb7fbce412af5a52 (patch)
tree360311ffaf6151c5066439f481e8ac38cfd047b9 /macros/tukeywin.sci
parent9ca7882cee16ad48b18df989e8300c697010e55a (diff)
downloadFOSSEE-Signal-Processing-Toolbox-1251f70aa3442736ce6fd9c4fb7fbce412af5a52.tar.gz
FOSSEE-Signal-Processing-Toolbox-1251f70aa3442736ce6fd9c4fb7fbce412af5a52.tar.bz2
FOSSEE-Signal-Processing-Toolbox-1251f70aa3442736ce6fd9c4fb7fbce412af5a52.zip
code changes by Kartik Hegde during FOSSEE Fellowship 2018
Diffstat (limited to 'macros/tukeywin.sci')
-rw-r--r--macros/tukeywin.sci91
1 files changed, 71 insertions, 20 deletions
diff --git a/macros/tukeywin.sci b/macros/tukeywin.sci
index 7ac8641..880f67f 100644
--- a/macros/tukeywin.sci
+++ b/macros/tukeywin.sci
@@ -1,4 +1,6 @@
-function w = tukeywin (m, r)
+// ...................................................Using"callOctave" method...................................................................................
+
+//function w = tukeywin (m, r)
//This function returns the filter coefficients of a Tukey window.
//Calling Sequence
//w = tukeywin (m)
@@ -8,27 +10,76 @@ function w = tukeywin (m, r)
//r: positive real number, between 0 and 1
//Description
//This is an Octave function.
-//This function returns the filter coefficients of a Tukey window of length m supplied as input, to the output vector w.
+//This function returns the filter coefficients of a Tukey window of length m supplied as input, to the output vector w.
//The second parameter r defines the ratio between the constant and cosine section and its value has to be between 0 and 1, with default value 0.5.
//Examples
//tukeywin(5, 2)
//ans =
-// 0.
-// 0.5
-// 1.
-// 0.5
-// 0.
-
-funcprot(0);
-rhs = argn(2)
-if(rhs<1 | rhs>2)
-error("Wrong number of input arguments.")
-end
- select(rhs)
- case 1 then
- w = callOctave("tukeywin",m)
- case 2 then
- w = callOctave("tukeywin",m,r)
- end
-endfunction
+// 0.
+// 0.5
+// 1.
+// 0.5
+// 0.
+
+//funcprot(0);
+//rhs = argn(2)
+//if(rhs<1 | rhs>2)
+//error("Wrong number of input arguments.")
+//end
+// select(rhs)
+// case 1 then
+// w = callOctave("tukeywin",m)
+// case 2 then
+// w = callOctave("tukeywin",m,r)
+// end
+//endfunction
+
+
+
+
+//...................................................................................................................................................................................
+// .....................................................Using pure "Scilab".............................................................................................
+//...................................................................................................................................................................................
+
+
+function w = tukeywin (m, varargin)
+
+ funcprot(0);
+ [nargout,nargin]=argn();
+
+
+ if (nargin < 1 | nargin > 2)
+ error("Wrong Number of input arguments");
+ elseif (~ (isscalar (m) & (m == fix (m)) & (m > 0)))
+ error ("tukeywin: M must be a positive integer");
+ elseif (nargin == 2)
+ // check that 0 < r < 1
+ r=varargin(1);
+ if r > 1
+ r = 1;
+ elseif r < 0
+ r = 0;
+ end
+ else
+ r=0.5;
+ end
+
+ //generate window
+ select(r)
+ case 0,
+ //full box
+ w = ones (m, 1);
+ case 1,
+ // Hanning window
+ w = hanning (m);
+ else
+ // cosine-tapered window
+ t = linspace(0,1,m);
+ t = t(1:$/2)';
+ w = (1 + cos(%pi*(2*t/r-1)))/2;
+ w(floor(r*(m-1)/2)+2:$) = 1;
+ w = [w; ones(modulo(m,2)); w($:-1:1,:)];
+ end
+
+endfunction