]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/ifht.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / ifht.m
1 ## Copyright (C) 2008 Muthiah Annamalai <muthiah.annamalai@uta.edu>
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 ## -*- texinfo -*-
17 ## @deftypefn{Function File} {m = } ifht ( d, n, dim )
18 ## @cindex linear algebra 
19 ##  The function ifht calculates  Fast Hartley Transform
20 ##  where @var{d} is the real input vector (matrix), and @var{m}
21 ## is the real-transform vector. For matrices the hartley transform
22 ## is calculated along the columns by default. The options @var{n},
23 ## and @var{dim} are similar to the options of FFT function.
24 ## 
25 ## The forward and inverse hartley transforms are the same (except for a
26 ## scale factor of 1/N for the inverse hartley transform), but
27 ## implemented using different functions .
28 ##
29 ## The definition of the forward hartley transform for vector d,
30 ## @math{
31 ## m[K] = 1/N \sum_{i=0}^{N-1} d[i]*(cos[K*2*pi*i/N] + sin[K*2*pi*i/N]), for  0 <= K < N.
32 ## m[K] = 1/N \sum_{i=0}^{N-1} d[i]*CAS[K*i], for  0 <= K < N. }
33 ## 
34 ## @example
35 ## ifht(1:4)
36 ## @end example
37 ## @seealso{fht,fft}
38 ## @end deftypefn
39
40 function m = ifht( d, n, dim )
41
42   if ( nargin < 1 )
43     print_usage();
44   end
45
46   if ( nargin == 3 )
47     Y = ifft(d,n,dim);
48   elseif ( nargin == 2 )
49     Y = ifft(d,n);
50   else
51     Y = ifft(d);
52   end
53   
54   m = real(Y) + imag(Y);
55
56 #   -- Traditional --
57 #   N = length(d);
58 #   for K = 1:N
59 #     i = 0:N-1;
60 #     t = (2*pi*(K-1).*i/N);
61 #     ker = (cos(t) + sin(t));
62 #     val = dot(d,ker)./N;
63 #     m(K) = val;
64 #   end
65
66 end
67
68 %!assert(ifht(fht(1:4)),[1 2 3 4])