Mercurial > hg > octave-lyh
annotate scripts/signal/fftconv.m @ 11540:b0ef6f28e09a
deprecate krylovb function
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 15 Jan 2011 03:40:32 -0500 |
parents | fd0a3ac60b0e |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 John W. Eaton |
2313 | 2 ## |
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. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
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/>. | |
1026 | 18 |
3367 | 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. |
2beacd515e09
Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents:
7017
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 |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11124
diff
changeset
|
25 ## @code{length (@var{x}) + length (@var{y}) - 1}. |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11124
diff
changeset
|
26 ## If @var{x} and @var{y} are the coefficient vectors of two polynomials, the |
11085
2beacd515e09
Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
27 ## returned value is the coefficient vector of the product polynomial. |
3426 | 28 ## |
3367 | 29 ## The computation uses the FFT by calling the function @code{fftfilt}. If |
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 | 32 ## @end deftypefn |
787 | 33 |
5428 | 34 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312 | 35 ## Created: 3 September 1994 |
36 ## Adapted-By: jwe | |
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 | 39 |
40 if (nargin < 2 || nargin > 3) | |
6046 | 41 print_usage (); |
787 | 42 endif |
2325 | 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 | 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 | 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 | 51 else |
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 | 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 | 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 | 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 | 62 endif |
63 endif | |
64 | |
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 |
11085
2beacd515e09
Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
68 %% FIXME: Borrow tests from conv.m. May need a tolerance on the assert comparison |
11124 | 69 %!test |
70 %! x = ones(3,1); | |
71 %! y = ones(1,3); | |
72 %! b = 2; | |
73 %! c = 3; | |
74 %! assert (fftconv (x, x), [1; 2; 3; 2; 1], 5*eps); | |
75 %! assert (fftconv (y, y), [1, 2, 3, 2, 1], 5*eps); | |
76 %! assert (fftconv (x, y), [1, 2, 3, 2, 1], 5*eps); | |
77 %! assert (fftconv (y, x), [1; 2; 3; 2; 1], 5*eps); | |
78 %! assert (fftconv (c, x), [3; 3; 3], 5*eps); | |
79 %! assert (fftconv (c, y), [3, 3, 3], 5*eps); | |
80 %! assert (fftconv (x, c), [3; 3; 3], 5*eps); | |
81 %! assert (fftconv (y, c), [3, 3, 3], 5*eps); | |
82 %! assert (fftconv (b, c), 6, 5*eps); | |
83 | |
84 %!test | |
85 %! a = 1:10; | |
86 %! b = 1:3; | |
87 %! assert (size(conv(a,b)), [1, numel(a)+numel(b)-1]) | |
88 %! assert (size(conv(b,a)), [1, numel(a)+numel(b)-1]) | |
89 | |
90 %! a = (1:10).'; | |
91 %! b = 1:3; | |
92 %! assert (size(conv(a,b)), [numel(a)+numel(b)-1, 1]) | |
93 %! assert (size(conv(b,a)), [numel(a)+numel(b)-1, 1]) | |
94 | |
95 %!test | |
96 %! a = 1:10; | |
97 %! b = (1:3).'; | |
98 %! assert (size(conv(a,b)), [1, numel(a)+numel(b)-1]) | |
99 %! assert (size(conv(b,a)), [1, numel(a)+numel(b)-1]) | |
100 | |
101 %% Test input validation | |
102 %!error fftconv (1); | |
103 %!error fftconv (1,2,3,4); | |
104 %!error fftconv ([1, 2; 3, 4], 3); | |
105 %!error fftconv (2, []); | |
106 %!error fftconv ([1,1], [2,2] , [3, 4]); |