diff options
Diffstat (limited to 'macros/decimate.sci')
-rw-r--r-- | macros/decimate.sci | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/macros/decimate.sci b/macros/decimate.sci index 5a2e428..9f8aeb5 100644 --- a/macros/decimate.sci +++ b/macros/decimate.sci @@ -1,14 +1,47 @@ function y = decimate(x, q, n, ftype) +//Decimation — decrease sample rate by integer factor + +//Calling Sequence +//y = decimate(x,q) +//y = decimate(x,q,n) +// y = decimate (…, "fir") + +//Parameters +//x: input sequence +//q: reduction factor +//n : filter order +//ftype: filter type : iir or fir + +//Description +//this is an octave function +//y = decimate(x,q) reduces the sample rate of x, the input signal, by a factor of q. +//By default, an order n Chebyshev type I filter is used. If n is not specified, the default is 8. +//If the optional argument "fir" is given, an order n FIR filter is used, with a default order of 30 if n is not given. +//Note that q must be an integer for this rate change method. +// +//Example : +//t = 0:.00025:1; +//x = sin(2*%pi*30*t) + sin(2*%pi*60*t); +//y = decimate(x,4); +//subplot(211); +//plot2d3((0:120),x(1:121)); +//subplot(212); +//plot2d3((0:30),y(1:31)); + +//This will result in plots of original sequence v/s sample number and decimated sequence v/s sample number + rhs = argn(2) if(rhs<2 | rhs>4) error("Wrong number of input arguments.") elseif(~(sum(length(q)==1) & q == fix (q) & q > 0)) error("Parameter 2 must be a positive integer.") end -if (nargin < 3) +//if (nargin < 3) +if(argn(2) < 3) ftype = "iir" n = [] -elseif (nargin < 4) +//elseif (nargin < 4) +elseif(argn(2) < 4) if (ischar (n)) ftype = n n = [] @@ -17,7 +50,8 @@ ftype = "iir" end end -if (~ and(strcmp (ftype, {"fir", "iir"}))) +//if (~ and(strcmp (ftype, {"fir", "iir"}))) // if strings are equal strcmp returns 0 +if(strcmp(ftype,"iir") & strcmp(ftype,"fir")) error("Filter type must be either fir or iir.") end @@ -42,6 +76,3 @@ case 4 then y = callOctave("decimate", x, q, n, ftype) end endfunction - - - |