summaryrefslogtreecommitdiff
path: root/macros/sawtooth.sci
diff options
context:
space:
mode:
authorttt2018-12-06 13:02:48 +0530
committerttt2018-12-06 13:02:48 +0530
commit3ffa5ac619587eadfdb4ffd3e2fee57fee385e21 (patch)
tree8ed1a41fc2814d53d60bc4e091a1458350482662 /macros/sawtooth.sci
parent0ee5488b9c99cdd0d631d97cd1de566a8785ffae (diff)
downloadFOSSEE-Signal-Processing-Toolbox-3ffa5ac619587eadfdb4ffd3e2fee57fee385e21.tar.gz
FOSSEE-Signal-Processing-Toolbox-3ffa5ac619587eadfdb4ffd3e2fee57fee385e21.tar.bz2
FOSSEE-Signal-Processing-Toolbox-3ffa5ac619587eadfdb4ffd3e2fee57fee385e21.zip
code by jitendra
Diffstat (limited to 'macros/sawtooth.sci')
-rw-r--r--macros/sawtooth.sci22
1 files changed, 15 insertions, 7 deletions
diff --git a/macros/sawtooth.sci b/macros/sawtooth.sci
index 50d093d..8c3d689 100644
--- a/macros/sawtooth.sci
+++ b/macros/sawtooth.sci
@@ -8,7 +8,6 @@ function [y]=sawtooth (t,width)
// t: Real valued vector or matrix
// width: Real number between 0 and 1
// Description
-// This is an Octave function
// This function returns a sawtooth wave with period 2*pi with +1/-1 as the maximum and minimum values for elements of t. If width is specified, it determines where the maximum is in the interval [0,2*pi].
// Examples
// 1. sawtooth([1 2 3 4 5],0.5)
@@ -16,12 +15,21 @@ function [y]=sawtooth (t,width)
// 2. sawtooth([1 2; 4 5])
// ans = [-0.68169 -0.36338; 0.27324 0.59155]
-funcprot(0);
-rhs=argn(2);
-if (rhs<1) then
+if (argn(2)<1 | argn(2)>2) then
error ("Wrong number of input arguments.")
-elseif (rhs==1)
- y=callOctave("sawtooth",t)
-else y=callOctave("sawtooth",t,width)
+elseif (argn(2)==1)
+ width=1
end
+ if (width < 0 | width > 1 | ~ isreal (width))
+ error ("width must be a real value between 0 and 1");
+ end
+ t = pmodulo (t / (2 * %pi), 1);
+ y = zeros (size (t,1), size(t,2));
+
+ if (width ~= 0)
+ y (t < width) = 2 * t (t < width) / width - 1;
+ end
+ if (width ~= 1)
+ y( t >= width) = -2 * (t (t >= width) - width) / (1 - width) + 1;
+ end
endfunction