diff options
Diffstat (limited to 'macros/hamming.sci')
-rw-r--r-- | macros/hamming.sci | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/macros/hamming.sci b/macros/hamming.sci index 49a970f..79d97fa 100644 --- a/macros/hamming.sci +++ b/macros/hamming.sci @@ -1,24 +1,33 @@ -function y = hamming(m, varargin) -//Return the filter coefficients of a Hamming window of length M -//Calling Sequence -//hamming (M) -//hamming (M, "periodic") -//hamming (M, "symmetric") -//Parameters -//M: real scalar, which will be the length of hamming window -//Description -//Return the filter coefficients of a Hamming window of length M. -//If the optional argument "periodic" is given, the periodic form of the window is returned. This is equivalent to the window of length M+1 with the last coefficient removed. The optional argument "symmetric" is equivalent to not specifying a second argument. -funcprot(0); -rhs= argn(2); -if(rhs <1 | rhs>2) -error("Wrong number of Input parameters"); -end +function c = hamming (m, opt) + + funcprot(0); + rhs= argn(2); + + if (rhs < 1 | rhs > 2) + error("Wrong Number of input arguments"); + end + + if (~ (isscalar (m) & (m == fix (m)) & (m > 0))) + error ("hamming: M must be a positive integer"); + end + + N = m - 1; + if (rhs == 2) + select (opt) + case "periodic" + N = m; + case "symmetric" + //Default option, same as no option specified. + else + error ('hamming: window type must be either periodic or symmetric"); + end + end + + if (m == 1) + c = 1; + else + m = m - 1; + c = 0.54 - 0.46 * cos (2 * %pi * (0 : m)' / N); + end -select(rhs) - case 1 then - y= callOctave("hamming", m); - case 2 then - y= callOctave("hamming", m , varargin(1)); -end endfunction |