Mercurial > hg > octave-nkf
annotate scripts/signal/bartlett.m @ 13818:a05e5db7b94e
have some fun with waitbar demo #2
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 04 Nov 2011 14:33:44 -0400 |
parents | 984359717d71 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Andreas Weingessel |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3191 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3191 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3191 | 18 |
3449 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} bartlett (@var{m}) | |
21 ## Return the filter coefficients of a Bartlett (triangular) window of | |
22 ## length @var{m}. | |
3191 | 23 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## For a definition of the Bartlett window, see e.g., A. V. Oppenheim & |
8484
895d49a7e36a
[docs] "Discrete-Time Signal Processing" => @cite{Discrete-Time Signal Processing}
Brian Gough <bjg@gnu.org>
parents:
7017
diff
changeset
|
25 ## R. W. Schafer, @cite{Discrete-Time Signal Processing}. |
3449 | 26 ## @end deftypefn |
3191 | 27 |
3457 | 28 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
29 ## Description: Coefficients of the Bartlett (triangular) window | |
3191 | 30 |
31 function c = bartlett (m) | |
3426 | 32 |
3191 | 33 if (nargin != 1) |
6046 | 34 print_usage (); |
3191 | 35 endif |
3426 | 36 |
13279
984359717d71
Use common code idiom for checking whether a double value is an integer.
Rik <octave@nomad.inbox5.com>
parents:
13062
diff
changeset
|
37 if (! (isscalar (m) && (m == fix (m)) && (m > 0))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
9051
diff
changeset
|
38 error ("bartlett: M has to be an integer > 0"); |
3191 | 39 endif |
3426 | 40 |
3191 | 41 if (m == 1) |
42 c = 1; | |
43 else | |
44 m = m - 1; | |
45 n = fix (m / 2); | |
4172 | 46 c = [2*(0:n)/m, 2-2*(n+1:m)/m]'; |
3191 | 47 endif |
48 | |
49 endfunction | |
13062
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
50 |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
51 %!assert (bartlett (1), 1); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
52 %!assert (bartlett (2), zeros (2,1)); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
53 %!assert (bartlett (16), fliplr (bartlett (16))); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
54 %!assert (bartlett (15), fliplr (bartlett (15))); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
55 %!test |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
56 %! N = 9; |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
57 %! A = bartlett (N); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
58 %! assert (A (ceil (N/2)), 1); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
59 |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
60 %!error bartlett (); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
61 %!error bartlett (0.5); |
b3a8b75dfec3
codesprint: 9 tests for bartlett.m
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
11523
diff
changeset
|
62 %!error bartlett (-1); |
13279
984359717d71
Use common code idiom for checking whether a double value is an integer.
Rik <octave@nomad.inbox5.com>
parents:
13062
diff
changeset
|
63 %!error bartlett (ones(1,4)); |