1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
(*************************************************************************
Copyright (c) 2009, Sergey Bochkanov (ALGLIB project).
>>> SOURCE LICENSE >>>
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 (www.fsf.org); either version 2 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.
A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************)
unit u_fht;
interface
uses Math, Sysutils, u_ap, u_ftbase, u_fft;
procedure FHTR1D(var A : TReal1DArray; N : Integer);
procedure FHTR1DInv(var A : TReal1DArray; N : Integer);
implementation
(*************************************************************************
1-dimensional Fast Hartley Transform.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - real function to be transformed
N - problem size
OUTPUT PARAMETERS
A - FHT of a input array, array[0..N-1],
A_out[k] = sum(A_in[j]*(cos(2*pi*j*k/N)+sin(2*pi*j*k/N)), j=0..N-1)
-- ALGLIB --
Copyright 04.06.2009 by Bochkanov Sergey
*************************************************************************)
procedure FHTR1D(var A : TReal1DArray; N : Integer);
var
Plan : FTPlan;
I : Integer;
FA : TComplex1DArray;
begin
Assert(N>0, 'FHTR1D: incorrect N!');
//
// Special case: N=1, FHT is just identity transform.
// After this block we assume that N is strictly greater than 1.
//
if N=1 then
begin
Exit;
end;
//
// Reduce FHt to real FFT
//
FFTR1D(A, N, FA);
I:=0;
while I<=N-1 do
begin
A[I] := FA[I].X-FA[I].Y;
Inc(I);
end;
end;
(*************************************************************************
1-dimensional inverse FHT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - complex array to be transformed
N - problem size
OUTPUT PARAMETERS
A - inverse FHT of a input array, array[0..N-1]
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************)
procedure FHTR1DInv(var A : TReal1DArray; N : Integer);
var
I : Integer;
begin
Assert(N>0, 'FHTR1DInv: incorrect N!');
//
// Special case: N=1, iFHT is just identity transform.
// After this block we assume that N is strictly greater than 1.
//
if N=1 then
begin
Exit;
end;
//
// Inverse FHT can be expressed in terms of the FHT as
//
// invfht(x) = fht(x)/N
//
FHTR1D(A, N);
I:=0;
while I<=N-1 do
begin
A[I] := A[I]/N;
Inc(I);
end;
end;
end.
|