-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathswtf.cpp
67 lines (62 loc) · 1.56 KB
/
swtf.cpp
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
void swtf ( int n, double a[] )
{
double *b;
double h0 = ( 1.0 + sqrt ( 3.0 ) ) / sqrt ( 32.0 );
double h1 = ( 3.0 + sqrt ( 3.0 ) ) / sqrt ( 32.0 );
double h2 = ( 3.0 - sqrt ( 3.0 ) ) / sqrt ( 32.0 );
double h3 = ( 1.0 - sqrt ( 3.0 ) ) / sqrt ( 32.0 );
int i;
int j;
int nhalf;
if ( 4 <= n )
{
nhalf = n / 2;
b = new double[n];
i = 0;
for ( j = 0; j < n - 3; j = j + 2 )
{
b[i] = h0 * a[j] + h1 * a[j+1] + h2 * a[j+2] + h3 * a[j+3];
b[i+nhalf] = h3 * a[j] - h2 * a[j+1] + h1 * a[j+2] - h0 * a[j+3];
i++;
}
b[i] = h0 * a[n-2] + h1 * a[n-1] + h2 * a[0] + h3 * a[1];
b[i+nhalf] = h3 * a[n-2] - h2 * a[n-1] + h1 * a[0] - h0 * a[1];
for ( i = 0; i < n; i++ )
{
a[i] = b[i];
}
delete [] b;
}
return
}
void swtb ( int n, double a[] )
{
double *b;
double h0 = ( 1.0 + sqrt ( 3.0 ) ) / sqrt ( 32.0 );
double h1 = ( 3.0 + sqrt ( 3.0 ) ) / sqrt ( 32.0 );
double h2 = ( 3.0 - sqrt ( 3.0 ) ) / sqrt ( 32.0 );
double h3 = ( 1.0 - sqrt ( 3.0 ) ) / sqrt ( 32.0 );
int i;
int j;
int nhalf;
if ( 4 <= n )
{
nhalf = n / 2;
b = new double[n];
b[0] = h0 * a[n-2] + h1 * a[n-1] + h2 * a[0] + h3 * a[1];
b[1] = h3 * a[n-2] - h2 * a[n-1] + h1 * a[0] - h0 * a[1];
j = 2;
for ( i = 0; i < half - 1; i++ )
{
j++;
b[j] = h3 * a[i] - h2 * a[i+nhalf] + h1 * a[i+1] - h0 * a[i+nhalf+1];
j++;
b[j] = h0 * a[i] + h1 * a[i+nhalf] + h2 * a[i+1] + h3 * a[i+nhalf+1];
}
for ( i = 0; i < n; i++ )
{
a[i] = b[i];
}
}
return
}