]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/dctmtx.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / dctmtx.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 ## T = dctmtx (n)
17 ## Return the DCT transformation matrix of size n x n.
18 ##
19 ## If A is an n x n matrix, then the following are true:
20 ##     T*A    == dct(A),  T'*A   == idct(A)
21 ##     T*A*T' == dct2(A), T'*A*T == idct2(A)
22 ##
23 ## A dct transformation matrix is useful for doing things like jpeg
24 ## image compression, in which an 8x8 dct matrix is applied to
25 ## non-overlapping blocks throughout an image and only a subblock on the
26 ## top left of each block is kept.  During restoration, the remainder of
27 ## the block is filled with zeros and the inverse transform is applied
28 ## to the block.
29 ##
30 ## See also: dct, idct, dct2, idct2
31
32 function T = dctmtx(n)
33   if nargin != 1
34     print_usage;
35   endif
36
37   if n > 1
38     T = [ sqrt(1/n)*ones(1,n) ; \
39          sqrt(2/n)*cos((pi/2/n)*([1:n-1]'*[1:2:2*n])) ];
40   elseif n == 1
41     T = 1;
42   else
43     error ("dctmtx: n must be at least 1");
44   endif
45
46 endfunction