annotate scripts/signal/fftconv.m @ 20614:10ec79b47808

use new string_value method to handle value extraction errors * __voronoi__.cc, chol.cc, colamd.cc, fftw.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 18:15:56 -0400
parents f1d0f506ee78
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 1994-2015 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1026
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 904
diff changeset
18
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
19 ## -*- texinfo -*-
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
20 ## @deftypefn {Function File} {} fftconv (@var{x}, @var{y})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
21 ## @deftypefnx {Function File} {} fftconv (@var{x}, @var{y}, @var{n})
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
22 ## Convolve two vectors using the FFT for computation.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
23 ##
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
24 ## @code{c = fftconv (@var{x}, @var{y})} returns a vector of length equal to
20200
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
25 ## @code{length (@var{x}) + length (@var{y}) - 1}. If @var{x} and @var{y}
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
26 ## are the coefficient vectors of two polynomials, the returned value is the
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
27 ## coefficient vector of the product polynomial.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
28 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
29 ## The computation uses the FFT by calling the function @code{fftfilt}. If
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
30 ## the optional argument @var{n} is specified, an N-point FFT is used.
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
31 ## @seealso{deconv, conv, conv2}
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
32 ## @end deftypefn
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
33
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
34 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
35 ## Created: 3 September 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
36 ## Adapted-By: jwe
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
37
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
38 function c = fftconv (x, y, n)
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
39
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
40 if (nargin < 2 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
41 print_usage ();
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
42 endif
2325
b5568c31ee2c [project @ 1996-07-15 22:20:21 by jwe]
jwe
parents: 2313
diff changeset
43
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
44 if (! (isvector (x) && isvector (y)))
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
45 error ("fftconv: both A and B must be vectors");
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
46 endif
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
47 la = length (x);
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
48 lb = length (y);
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
49 if ((la == 1) || (lb == 1))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
50 c = x * y;
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
51 else
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
52 lc = la + lb - 1;
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
53 x(lc) = 0;
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
54 y(lc) = 0;
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
55 if (nargin == 2)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
56 c = fftfilt (x, y);
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
57 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
58 if (! isscalar (n))
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
59 error ("fftconv: N must be a scalar");
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
60 endif
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
61 c = fftfilt (x, y, n);
787
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
62 endif
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
63 endif
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
64
c5d35bb139b6 [project @ 1994-10-11 00:34:13 by jwe]
jwe
parents:
diff changeset
65 endfunction
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
66
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11124
diff changeset
67
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
68 ## FIXME: Borrow tests from conv.m. May need tolerance on the assert stmt.
11124
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
69 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
70 %! x = ones (3,1);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
71 %! y = ones (1,3);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
72 %! b = 2;
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
73 %! c = 3;
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
74 %! assert (fftconv (x, x), [1; 2; 3; 2; 1], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
75 %! assert (fftconv (y, y), [1, 2, 3, 2, 1], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
76 %! assert (fftconv (x, y), [1, 2, 3, 2, 1], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
77 %! assert (fftconv (y, x), [1; 2; 3; 2; 1], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
78 %! assert (fftconv (c, x), [3; 3; 3], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
79 %! assert (fftconv (c, y), [3, 3, 3], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
80 %! assert (fftconv (x, c), [3; 3; 3], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
81 %! assert (fftconv (y, c), [3, 3, 3], 5*eps);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
82 %! assert (fftconv (b, c), 6, 5*eps);
11124
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
83
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
84 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
85 %! a = 1:10;
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
86 %! b = 1:3;
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
87 %! assert (size (conv (a,b)), [1, numel(a)+numel(b)-1]);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
88 %! assert (size (conv (b,a)), [1, numel(a)+numel(b)-1]);
11124
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
89
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
90 %! a = (1:10).';
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
91 %! b = 1:3;
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
92 %! assert (size (conv (a,b)), [numel(a)+numel(b)-1, 1]);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
93 %! assert (size (conv (b,a)), [numel(a)+numel(b)-1, 1]);
11124
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
94
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
95 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
96 %! a = 1:10;
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
97 %! b = (1:3).';
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
98 %! assert (size (conv (a,b)), [1, numel(a)+numel(b)-1]);
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 14868
diff changeset
99 %! assert (size (conv (b,a)), [1, numel(a)+numel(b)-1]);
11124
e79f59d31a74 Add tests for fftconv.m
Rik <octave@nomad.inbox5.com>
parents: 11085
diff changeset
100
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
101 ## Test input validation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
102 %!error fftconv (1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
103 %!error fftconv (1,2,3,4)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
104 %!error fftconv ([1, 2; 3, 4], 3)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
105 %!error fftconv (2, [])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
106 %!error fftconv ([1,1], [2,2] , [3, 4])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
107