1 #include "ltfat.h"
2 #include "ltfat/types.h"
3 #include "ltfat/macros.h"
4
5
6 #define CH(name) LTFAT_COMPLEXH(name)
7
8 #define POSTPROC_REAL \
9 for (ltfat_int n=0;n<N*W;n+=2) \
10 { \
11 pcoef[0]=ltfat_real(pcoef2[0]); \
12 \
13 for (ltfat_int m=1;m<M;m+=2) \
14 { \
15 pcoef[m]=-scalconst*ltfat_imag(pcoef2[m]); \
16 pcoef[m+M]=scalconst*ltfat_real(pcoef2[m+coef2_ld]); \
17 } \
18 \
19 for (ltfat_int m=2;m<M;m+=2) \
20 { \
21 pcoef[m]=scalconst*ltfat_real(pcoef2[m]); \
22 pcoef[m+M]=-scalconst*ltfat_imag(pcoef2[m+coef2_ld]); \
23 } \
24 \
25 pcoef[M]=ltfat_real(pcoef2[M+nyquestadd]); \
26 pcoef+=2*M; \
27 pcoef2+=2*coef2_ld; \
28 }
29
30 #define POSTPROC_COMPLEX \
31 for (ltfat_int n=0;n<N*W;n+=2) \
32 { \
33 pcoef[0] = pcoef2[0]; \
34 \
35 for (ltfat_int m=1;m<M;m+=2) \
36 { \
37 pcoef[m] = scalconst*I*(pcoef2[m]-pcoef2[M2-m]); \
38 pcoef[m+M]=scalconst*(pcoef2[m+M2]+pcoef2[M4-m]); \
39 } \
40 \
41 for (ltfat_int m=2;m<M;m+=2) \
42 { \
43 pcoef[m] = scalconst*(pcoef2[m]+pcoef2[M2-m]); \
44 pcoef[m+M] = scalconst*I*(pcoef2[m+M2]-pcoef2[M4-m]); \
45 } \
46 \
47 pcoef[M]=pcoef2[M+nyquestadd]; \
48 pcoef+=M2; \
49 pcoef2+=M4; \
50 }
51
52
53 LTFAT_API void
LTFAT_NAME_COMPLEX(dwilt_long)54 LTFAT_NAME_COMPLEX(dwilt_long)(const LTFAT_COMPLEX* f, const LTFAT_COMPLEX* g,
55 ltfat_int L, ltfat_int W,
56 ltfat_int M, LTFAT_COMPLEX* cout)
57 {
58 ltfat_int N = L / M;
59 ltfat_int M2 = 2 * M;
60 ltfat_int M4 = 4 * M;
61 const LTFAT_REAL scalconst = (LTFAT_REAL)( 1.0 / sqrt(2.0) );
62
63 LTFAT_COMPLEX* coef2 = LTFAT_NAME_COMPLEX(malloc)(2 * M * N * W);
64
65 /* coef2=comp_dgt(f,g,a,2*M,L); */
66 LTFAT_NAME_COMPLEX(dgt_long)(f, g, L, W, M, 2 * M, LTFAT_FREQINV, coef2);
67
68 ltfat_int nyquestadd = (M % 2) * M2;
69
70 LTFAT_COMPLEX* pcoef = cout;
71 LTFAT_COMPLEX* pcoef2 = coef2;
72
73 POSTPROC_COMPLEX
74
75 ltfat_free(coef2);
76
77 }
78
79 LTFAT_API void
LTFAT_NAME_REAL(dwilt_long)80 LTFAT_NAME_REAL(dwilt_long)(const LTFAT_REAL* f, const LTFAT_REAL* g,
81 ltfat_int L, ltfat_int W,
82 ltfat_int M, LTFAT_REAL* cout)
83 {
84 ltfat_int N = L / M;
85 ltfat_int coef2_ld = M + 1;
86 const LTFAT_REAL scalconst = (LTFAT_REAL) sqrt(2.0);
87 ltfat_int nyquestadd = (M % 2) * coef2_ld;
88
89 LTFAT_COMPLEX* coef2 = LTFAT_NAME_COMPLEX(malloc)((M + 1) * N * W);
90
91 /* coef2=comp_dgt(f,g,a,2*M,L); */
92 LTFAT_NAME(dgtreal_long)(f, g, L, W, M, 2 * M, LTFAT_FREQINV, coef2);
93
94
95 LTFAT_REAL* pcoef = cout;
96 LTFAT_COMPLEX* pcoef2 = coef2;
97
98 POSTPROC_REAL
99
100 ltfat_free(coef2);
101
102 }
103
104 LTFAT_API void
LTFAT_NAME_COMPLEX(dwilt_fb)105 LTFAT_NAME_COMPLEX(dwilt_fb)(const LTFAT_COMPLEX* f, const LTFAT_COMPLEX* g,
106 ltfat_int L, ltfat_int gl,
107 ltfat_int W, ltfat_int M,
108 LTFAT_COMPLEX* cout)
109 {
110 ltfat_int N = L / M;
111 ltfat_int M2 = 2 * M;
112 ltfat_int M4 = 4 * M;
113 const LTFAT_REAL scalconst = (LTFAT_REAL) ( 1.0 / sqrt(2.0) );
114
115 LTFAT_COMPLEX* coef2 = LTFAT_NAME_COMPLEX(malloc)(2 * M * N * W);
116
117 /* coef2=comp_dgt(f,g,a,2*M,L); */
118 LTFAT_NAME_COMPLEX(dgt_fb)(f, g, L, gl, W, M, 2 * M, LTFAT_FREQINV, coef2);
119
120 ltfat_int nyquestadd = (M % 2) * M2;
121
122 LTFAT_COMPLEX* pcoef = cout;
123 LTFAT_COMPLEX* pcoef2 = coef2;
124
125 POSTPROC_COMPLEX
126
127 ltfat_free(coef2);
128
129 }
130
131 LTFAT_API void
LTFAT_NAME_REAL(dwilt_fb)132 LTFAT_NAME_REAL(dwilt_fb)(const LTFAT_REAL* f, const LTFAT_REAL* g,
133 ltfat_int L, ltfat_int gl,
134 ltfat_int W, ltfat_int M,
135 LTFAT_REAL* cout)
136 {
137 ltfat_int N = L / M;
138 ltfat_int coef2_ld = M + 1;
139 ltfat_int nyquestadd = (M % 2) * coef2_ld;
140 const LTFAT_REAL scalconst = (LTFAT_REAL) sqrt(2.0);
141
142 LTFAT_COMPLEX* coef2 = LTFAT_NAME_COMPLEX(malloc)((M + 1) * N * W);
143 LTFAT_NAME(dgtreal_fb)(f, g, L, gl, W, M, 2 * M, LTFAT_FREQINV, coef2);
144
145 LTFAT_REAL* pcoef = cout;
146 LTFAT_COMPLEX* pcoef2 = coef2;
147
148 POSTPROC_REAL
149
150 ltfat_free(coef2);
151 }
152
153 #undef CH
154 #undef POSTPROC_REAL
155 #undef POSTPROC_COMPLEX
156