Mercurial > octave-antonio
comparison scripts/signal/blackman.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 ("blackman: M must be a positive integer"); | 45 error ("blackman: 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 ('blackman: window type must be either "periodic" or "symmetric"'); | 56 error ('blackman: 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 k = (0 : m)' / N; |
65 endif | |
66 k = (0 : m)' / m; | |
67 c = 0.42 - 0.5 * cos (2 * pi * k) + 0.08 * cos (4 * pi * k); | 65 c = 0.42 - 0.5 * cos (2 * pi * k) + 0.08 * cos (4 * pi * k); |
68 endif | |
69 | |
70 if (periodic) | |
71 c = c(1:end-1); | |
72 endif | 66 endif |
73 | 67 |
74 endfunction | 68 endfunction |
75 | 69 |
76 | 70 |