1 | /*************************************************************************
|
---|
2 | Copyright (c) 2009, Sergey Bochkanov (ALGLIB project).
|
---|
3 |
|
---|
4 | >>> SOURCE LICENSE >>>
|
---|
5 | This program is free software; you can redistribute it and/or modify
|
---|
6 | it under the terms of the GNU General Public License as published by
|
---|
7 | the Free Software Foundation (www.fsf.org); either version 2 of the
|
---|
8 | License, or (at your option) any later version.
|
---|
9 |
|
---|
10 | This program is distributed in the hope that it will be useful,
|
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | GNU General Public License for more details.
|
---|
14 |
|
---|
15 | A copy of the GNU General Public License is available at
|
---|
16 | http://www.fsf.org/licensing/licenses
|
---|
17 |
|
---|
18 | >>> END OF LICENSE >>>
|
---|
19 | *************************************************************************/
|
---|
20 |
|
---|
21 |
|
---|
22 | namespace alglib {
|
---|
23 | public class fht {
|
---|
24 | /*************************************************************************
|
---|
25 | 1-dimensional Fast Hartley Transform.
|
---|
26 |
|
---|
27 | Algorithm has O(N*logN) complexity for any N (composite or prime).
|
---|
28 |
|
---|
29 | INPUT PARAMETERS
|
---|
30 | A - array[0..N-1] - real function to be transformed
|
---|
31 | N - problem size
|
---|
32 |
|
---|
33 | OUTPUT PARAMETERS
|
---|
34 | A - FHT of a input array, array[0..N-1],
|
---|
35 | A_out[k] = sum(A_in[j]*(cos(2*pi*j*k/N)+sin(2*pi*j*k/N)), j=0..N-1)
|
---|
36 |
|
---|
37 |
|
---|
38 | -- ALGLIB --
|
---|
39 | Copyright 04.06.2009 by Bochkanov Sergey
|
---|
40 | *************************************************************************/
|
---|
41 | public static void fhtr1d(ref double[] a,
|
---|
42 | int n) {
|
---|
43 | ftbase.ftplan plan = new ftbase.ftplan();
|
---|
44 | int i = 0;
|
---|
45 | AP.Complex[] fa = new AP.Complex[0];
|
---|
46 |
|
---|
47 | System.Diagnostics.Debug.Assert(n > 0, "FHTR1D: incorrect N!");
|
---|
48 |
|
---|
49 | //
|
---|
50 | // Special case: N=1, FHT is just identity transform.
|
---|
51 | // After this block we assume that N is strictly greater than 1.
|
---|
52 | //
|
---|
53 | if (n == 1) {
|
---|
54 | return;
|
---|
55 | }
|
---|
56 |
|
---|
57 | //
|
---|
58 | // Reduce FHt to real FFT
|
---|
59 | //
|
---|
60 | fft.fftr1d(ref a, n, ref fa);
|
---|
61 | for (i = 0; i <= n - 1; i++) {
|
---|
62 | a[i] = fa[i].x - fa[i].y;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /*************************************************************************
|
---|
68 | 1-dimensional inverse FHT.
|
---|
69 |
|
---|
70 | Algorithm has O(N*logN) complexity for any N (composite or prime).
|
---|
71 |
|
---|
72 | INPUT PARAMETERS
|
---|
73 | A - array[0..N-1] - complex array to be transformed
|
---|
74 | N - problem size
|
---|
75 |
|
---|
76 | OUTPUT PARAMETERS
|
---|
77 | A - inverse FHT of a input array, array[0..N-1]
|
---|
78 |
|
---|
79 |
|
---|
80 | -- ALGLIB --
|
---|
81 | Copyright 29.05.2009 by Bochkanov Sergey
|
---|
82 | *************************************************************************/
|
---|
83 | public static void fhtr1dinv(ref double[] a,
|
---|
84 | int n) {
|
---|
85 | int i = 0;
|
---|
86 |
|
---|
87 | System.Diagnostics.Debug.Assert(n > 0, "FHTR1DInv: incorrect N!");
|
---|
88 |
|
---|
89 | //
|
---|
90 | // Special case: N=1, iFHT is just identity transform.
|
---|
91 | // After this block we assume that N is strictly greater than 1.
|
---|
92 | //
|
---|
93 | if (n == 1) {
|
---|
94 | return;
|
---|
95 | }
|
---|
96 |
|
---|
97 | //
|
---|
98 | // Inverse FHT can be expressed in terms of the FHT as
|
---|
99 | //
|
---|
100 | // invfht(x) = fht(x)/N
|
---|
101 | //
|
---|
102 | fhtr1d(ref a, n);
|
---|
103 | for (i = 0; i <= n - 1; i++) {
|
---|
104 | a[i] = a[i] / n;
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|