diff options
Diffstat (limited to 'macros/blackmanharris.sci')
-rw-r--r-- | macros/blackmanharris.sci | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/macros/blackmanharris.sci b/macros/blackmanharris.sci index f2affdf..faec39a 100644 --- a/macros/blackmanharris.sci +++ b/macros/blackmanharris.sci @@ -1,35 +1,38 @@ function w = blackmanharris (m, opt) -//This function returns the filter coefficients of a Blackman-Harris window. -//Calling Sequence -//w = blackmanharris (m) -//w = blackmanharris (m, opt) -//Parameters -//m: positive integer value -//opt: string value, takes "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 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 -//blackmanharris(5,"periodic") -//ans = -// 0.00006 -// 0.1030115 -// 0.7938335 -// 0.7938335 -// 0.1030115 - -rhs = argn(2) -if(rhs<1 | rhs>2) -error("Wrong number of input arguments.") -end - select(rhs) - case 1 then - w = callOctave("blackmanharris",m) - case 2 then - w = callOctave("blackmanharris",m,opt) - end -endfunction + 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 ("blackmanharris: M must be a positive integer"); + end + + N = m - 1; + if (rhs == 2) + select (opt) + case "periodic" + N = m; + case "symmetric" + N = m-1; + else + error ("blackmanharris: window type must be either periodic or symmetric"); + end + end + + if (m == 1) + w = 1; + else + a0 = 0.35875; + a1 = 0.48829; + a2 = 0.14128; + a3 = 0.01168; + 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 |