]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/dct2.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / dct2.m
1 ## Copyright (C) 2001 Paul Kienzle <pkienzle@users.sf.net>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## y = dct2 (x)
17 ##   Computes the 2-D discrete cosine transform of matrix x
18 ##
19 ## y = dct2 (x, m, n) or y = dct2 (x, [m n])
20 ##   Computes the 2-D DCT of x after padding or trimming rows to m and
21 ##   columns to n.
22
23 function y = dct2 (x, m, n)
24
25   if (nargin < 1 || nargin > 3)
26     print_usage;
27   endif
28
29   if nargin == 1
30     [m, n] = size(x);
31   elseif (nargin == 2)
32     n = m(2);
33     m = m(1);
34   endif
35
36   if m == 1
37     y = dct (x.', n).';
38   elseif n == 1
39     y = dct (x, m);
40   else
41     y = dct (dct (x, m).', n).';
42   endif
43
44 endfunction