39 @deftypefn {Built-in Function} {} conv2 (@var{A}, @var{B})\n\
40 @deftypefnx {Built-in Function} {} conv2 (@var{v1}, @var{v2}, @var{m})\n\
41 @deftypefnx {Built-in Function} {} conv2 (@dots{}, @var{shape})\n\
42 Return the 2-D convolution of @var{A} and @var{B}. The size of the result\n\
43 is determined by the optional @var{shape} argument which takes the following\n\
47 @item @var{shape} = @qcode{\"full\"}\n\
48 Return the full convolution. (default)\n\
50 @item @var{shape} = @qcode{\"same\"}\n\
51 Return the central part of the convolution with the same size as @var{A}.\n\
52 The central part of the convolution begins at the indices\n\
53 @code{floor ([size(@var{B})/2] + 1)}.\n\
55 @item @var{shape} = @qcode{\"valid\"}\n\
56 Return only the parts which do not include zero-padded edges.\n\
57 The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
60 When the third argument is a matrix, return the convolution of the matrix\n\
61 @var{m} by the vector @var{v1} in the column direction and by the vector\n\
62 @var{v2} in the row direction.\n\
63 @seealso{conv, convn}\n\
68 int nargin = args.
length ();
69 std::string shape =
"full";
70 bool separable =
false;
80 if (args(2).is_string ())
88 shape = args(3).string_value ();
91 if (args(0).ndims () > 2 || args(1).ndims () > 2)
93 error (
"conv2: A and B must be 1-D vectors or 2-D matrices");
99 else if (shape ==
"same")
101 else if (shape ==
"valid")
105 error (
"conv2: SHAPE type not valid");
114 if (! (1 == args(0).rows () || 1 == args(0).columns ())
115 || ! (1 == args(1).rows () || 1 == args(1).columns ()))
121 if (args(0).is_single_type () || args(1).is_single_type ()
122 || args(2).is_single_type ())
124 if (args(0).is_complex_type () || args(1).is_complex_type ()
125 || args(2).is_complex_type ())
128 if (args(1).is_real_type () && args(2).is_real_type ())
132 retval =
convn (a, v1, v2, ct);
138 retval =
convn (a, v1, v2, ct);
146 retval =
convn (a, v1, v2, ct);
151 if (args(0).is_complex_type () || args(1).is_complex_type ()
152 || args(2).is_complex_type ())
155 if (args(1).is_real_type () && args(2).is_real_type ())
159 retval =
convn (a, v1, v2, ct);
165 retval =
convn (a, v1, v2, ct);
172 Matrix a (args(2).matrix_value ());
173 retval =
convn (a, v1, v2, ct);
179 if (args(0).is_single_type () || args(1).is_single_type ())
181 if (args(0).is_complex_type () || args(1).is_complex_type ())
184 if (args(1).is_real_type ())
187 retval =
convn (a, b, ct);
192 retval =
convn (a, b, ct);
199 retval =
convn (a, b, ct);
204 if (args(0).is_complex_type () || args(1).is_complex_type ())
207 if (args(1).is_real_type ())
209 Matrix b (args(1).matrix_value ());
210 retval =
convn (a, b, ct);
215 retval =
convn (a, b, ct);
220 Matrix a (args(0).matrix_value ());
221 Matrix b (args(1).matrix_value ());
222 retval =
convn (a, b, ct);
295 @deftypefn {Built-in Function} {@var{C} =} convn (@var{A}, @var{B})\n\
296 @deftypefnx {Built-in Function} {@var{C} =} convn (@var{A}, @var{B}, @var{shape})\n\
297 Return the n-D convolution of @var{A} and @var{B}. The size of the result\n\
298 is determined by the optional @var{shape} argument which takes the following\n\
302 @item @var{shape} = @qcode{\"full\"}\n\
303 Return the full convolution. (default)\n\
305 @item @var{shape} = @qcode{\"same\"}\n\
306 Return central part of the convolution with the same size as @var{A}.\n\
307 The central part of the convolution begins at the indices\n\
308 @code{floor ([size(@var{B})/2] + 1)}.\n\
310 @item @var{shape} = @qcode{\"valid\"}\n\
311 Return only the parts which do not include zero-padded edges.\n\
312 The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
315 @seealso{conv2, conv}\n\
320 int nargin = args.
length ();
321 std::string shape =
"full";
324 if (nargin < 2 || nargin > 3)
329 else if (nargin == 3)
331 if (args(2).is_string ())
335 error (
"convn: SHAPE must be a string");
342 else if (shape ==
"same")
344 else if (shape ==
"valid")
348 error (
"convn: SHAPE type not valid");
353 if (args(0).is_single_type () || args(1).is_single_type ())
355 if (args(0).is_complex_type () || args(1).is_complex_type ())
358 if (args(1).is_real_type ())
361 retval =
convn (a, b, ct);
366 retval =
convn (a, b, ct);
373 retval =
convn (a, b, ct);
378 if (args(0).is_complex_type () || args(1).is_complex_type ())
381 if (args(1).is_real_type ())
384 retval =
convn (a, b, ct);
389 retval =
convn (a, b, ct);
396 retval =
convn (a, b, ct);