diff options
Diffstat (limited to 'macros/nuttallwin.sci')
-rw-r--r-- | macros/nuttallwin.sci | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/macros/nuttallwin.sci b/macros/nuttallwin.sci index c066ef5..a7090ad 100644 --- a/macros/nuttallwin.sci +++ b/macros/nuttallwin.sci @@ -1,34 +1,39 @@ function w = nuttallwin (m, opt) -//This function returns the filter coefficients of a Blackman-Harris window. -//Calling Sequence -//w = nuttallwin (m) -//w = nuttallwin (m, opt) -//Parameters -//m: positive integer value -//opt: string value, takes in "periodic" or "symmetric" -//w: output variable, vector of real numbers -//Description -//This is an Octave function. -//This function returns the filter coefficients of a Blackman-Harris window defined by Nuttall of length m supplied as input, to the output vector w. -//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric. -//Examples -//nuttallwin(2, "periodic") -//ans = -// - 2.429D-17 -// 1. + funcprot(0); + rhs= argn(2); + if (rhs < 1 | rhs > 2) + error("Wrong Number of input arguments"); + end -rhs = argn(2) -if(rhs<1 | rhs>2) -error("Wrong number of input arguments.") -end + if (~ (isscalar (m) & (m == fix (m)) & (m > 0))) + error ("nuttallwin: M must be a positive integer"); + end - select(rhs) - case 1 then - w = callOctave("nuttallwin",m) - case 2 then - w = callOctave("nuttallwin",m,opt) - end -endfunction + N = m - 1; + if (rhs == 2) + select (opt) + case "periodic" + N = m; + case "symmetric" + N = m-1; + else + error ('nuttallwin: window type must be either periodic or symmetric"); + end + end + + if (m == 1) + w = 1; + else + a0 = 0.355768; + a1 = 0.487396; + a2 = 0.144232; + a3 = 0.012604; +// n = [-N/2:(m-1)/2]'; +// w = a0 + a1.*cos(2.*%pi.*n./N) + a2.*cos(4.*%pi.*n./N) + a3.*cos(6.*%pi.*n./N); + n=[0:m-1]' + w = a0 - a1.*cos(2.*%pi.*n./N) + a2.*cos(4.*%pi.*n./N) - a3.*cos(6.*%pi.*n./N); + end +endfunction |