X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fsignal-1.1.3%2Fdctmtx.m;fp=octave_packages%2Fsignal-1.1.3%2Fdctmtx.m;h=b47564b61244986dd8cbf27b845683ed2a0f3259;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/signal-1.1.3/dctmtx.m b/octave_packages/signal-1.1.3/dctmtx.m new file mode 100644 index 0000000..b47564b --- /dev/null +++ b/octave_packages/signal-1.1.3/dctmtx.m @@ -0,0 +1,46 @@ +## Copyright (C) 2001 Paul Kienzle +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + +## T = dctmtx (n) +## Return the DCT transformation matrix of size n x n. +## +## If A is an n x n matrix, then the following are true: +## T*A == dct(A), T'*A == idct(A) +## T*A*T' == dct2(A), T'*A*T == idct2(A) +## +## A dct transformation matrix is useful for doing things like jpeg +## image compression, in which an 8x8 dct matrix is applied to +## non-overlapping blocks throughout an image and only a subblock on the +## top left of each block is kept. During restoration, the remainder of +## the block is filled with zeros and the inverse transform is applied +## to the block. +## +## See also: dct, idct, dct2, idct2 + +function T = dctmtx(n) + if nargin != 1 + print_usage; + endif + + if n > 1 + T = [ sqrt(1/n)*ones(1,n) ; \ + sqrt(2/n)*cos((pi/2/n)*([1:n-1]'*[1:2:2*n])) ]; + elseif n == 1 + T = 1; + else + error ("dctmtx: n must be at least 1"); + endif + +endfunction