comparison scripts/signal/hanning.m @ 20026:230c1e2a678d

blackman, hamming, hanning: Simplify handling of periodic window option * blackman.m, hamming.m, hanning.m: Simplify logic for handling periodic or symmetric window option.
author Mike Miller <mtmiller@octave.org>
date Sat, 04 Apr 2015 14:12:10 -0400
parents d209fbae38ae
children f1d0f506ee78
comparison
equal deleted inserted replaced
20025:d209fbae38ae 20026:230c1e2a678d
43 43
44 if (! (isscalar (m) && (m == fix (m)) && (m > 0))) 44 if (! (isscalar (m) && (m == fix (m)) && (m > 0)))
45 error ("hanning: M must be a positive integer"); 45 error ("hanning: M must be a positive integer");
46 endif 46 endif
47 47
48 periodic = false; 48 N = m - 1;
49 if (nargin == 2) 49 if (nargin == 2)
50 switch (opt) 50 switch (opt)
51 case "periodic" 51 case "periodic"
52 periodic = true; 52 N = m;
53 case "symmetric" 53 case "symmetric"
54 ## Default option, same as no option specified. 54 ## Default option, same as no option specified.
55 otherwise 55 otherwise
56 error ('hanning: window type must be either "periodic" or "symmetric"'); 56 error ('hanning: window type must be either "periodic" or "symmetric"');
57 endswitch 57 endswitch
58 endif 58 endif
59 59
60 if (m == 1) 60 if (m == 1)
61 c = 1; 61 c = 1;
62 else 62 else
63 if (! periodic) 63 m = m - 1;
64 m = m - 1; 64 c = 0.5 - 0.5 * cos (2 * pi * (0 : m)' / N);
65 endif
66 c = 0.5 - 0.5 * cos (2 * pi * (0 : m)' / m);
67 endif
68
69 if (periodic)
70 c = c(1:end-1);
71 endif 65 endif
72 66
73 endfunction 67 endfunction
74 68
75 69