File: dwilt.c

package info (click to toggle)
python-ltfatpy 1.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,412 kB
  • sloc: ansic: 8,546; python: 6,470; makefile: 15
file content (154 lines) | stat: -rw-r--r-- 3,989 bytes parent folder | download | duplicates (7)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "ltfat.h"
#include "ltfat_types.h"

#define CH(name) LTFAT_COMPLEXH(name)

#define POSTPROC_REAL \
  for (ltfatInt n=0;n<N*W;n+=2) \
  { \
     pcoef[0]=CH(creal)(pcoef2[0]); \
\
     for (ltfatInt m=1;m<M;m+=2) \
     { \
       pcoef[m]=-scalconst*CH(cimag)(pcoef2[m]); \
       pcoef[m+M]=scalconst*CH(creal)(pcoef2[m+coef2_ld]); \
     } \
 \
     for (ltfatInt m=2;m<M;m+=2) \
     { \
       pcoef[m]=scalconst*CH(creal)(pcoef2[m]); \
       pcoef[m+M]=-scalconst*CH(cimag)(pcoef2[m+coef2_ld]); \
     } \
 \
     pcoef[M]=CH(creal)(pcoef2[M+nyquestadd]); \
     pcoef+=2*M; \
     pcoef2+=2*coef2_ld; \
  }

#define POSTPROC_COMPLEX \
  for (ltfatInt n=0;n<N*W;n+=2) \
  { \
     pcoef[0] = pcoef2[0]; \
 \
     for (ltfatInt m=1;m<M;m+=2) \
     { \
       pcoef[m] = scalconst*I*(pcoef2[m]-pcoef2[M2-m]); \
       pcoef[m+M]=scalconst*(pcoef2[m+M2]+pcoef2[M4-m]); \
     } \
 \
     for (ltfatInt m=2;m<M;m+=2) \
     { \
         pcoef[m] = scalconst*(pcoef2[m]+pcoef2[M2-m]); \
         pcoef[m+M] = scalconst*I*(pcoef2[m+M2]-pcoef2[M4-m]); \
     } \
 \
     pcoef[M]=pcoef2[M+nyquestadd]; \
     pcoef+=M2; \
     pcoef2+=M4; \
  }


LTFAT_EXTERN void
LTFAT_NAME_COMPLEX(dwilt_long)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g,
                               const ltfatInt L, const ltfatInt W,
                               const ltfatInt M, LTFAT_COMPLEX *cout)
{
    const ltfatInt N=L/M;
    const ltfatInt M2=2*M;
    const ltfatInt M4=4*M;
    const LTFAT_REAL scalconst = 1.0/sqrt(2.0);

    LTFAT_COMPLEX *coef2 = ltfat_malloc(2*M*N*W*sizeof*coef2);

    /* coef2=comp_dgt(f,g,a,2*M,L); */
    LTFAT_NAME_COMPLEX(dgt_long)(f, g, L, W, M, 2*M, FREQINV, coef2);

    const ltfatInt nyquestadd = (M%2)*M2;

    LTFAT_COMPLEX *pcoef  = cout;
    LTFAT_COMPLEX *pcoef2 = coef2;

    POSTPROC_COMPLEX

    ltfat_free(coef2);

}

LTFAT_EXTERN void
LTFAT_NAME_REAL(dwilt_long)(const LTFAT_REAL *f, const LTFAT_REAL *g,
                            const ltfatInt L, const ltfatInt W,
                            const ltfatInt M, LTFAT_REAL *cout)
{
    const ltfatInt N=L/M;
    const ltfatInt coef2_ld = M+1;
    const LTFAT_REAL scalconst = sqrt(2.0);
    const ltfatInt nyquestadd = (M%2)*coef2_ld;

    LTFAT_COMPLEX *coef2 = ltfat_malloc((M+1)*N*W*sizeof*coef2);

    /* coef2=comp_dgt(f,g,a,2*M,L); */
    LTFAT_NAME(dgtreal_long)(f, g, L, W, M, 2*M, FREQINV,coef2);


    LTFAT_REAL *pcoef  = cout;
    LTFAT_COMPLEX *pcoef2 = coef2;

    POSTPROC_REAL

    ltfat_free(coef2);

}

LTFAT_EXTERN void
LTFAT_NAME_COMPLEX(dwilt_fb)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g,
                             const ltfatInt L, const ltfatInt gl,
                             const ltfatInt W, const ltfatInt M,
                             LTFAT_COMPLEX *cout)
{
    const ltfatInt N=L/M;
    const ltfatInt M2=2*M;
    const ltfatInt M4=4*M;
    const LTFAT_REAL scalconst = 1.0/sqrt(2.0);

    LTFAT_COMPLEX *coef2 = ltfat_malloc(2*M*N*W*sizeof*coef2);

    /* coef2=comp_dgt(f,g,a,2*M,L); */
    LTFAT_NAME_COMPLEX(dgt_fb)(f, g, L, gl, W, M, 2*M, FREQINV, coef2);

    const ltfatInt nyquestadd = (M%2)*M2;

    LTFAT_COMPLEX *pcoef  = cout;
    LTFAT_COMPLEX *pcoef2 = coef2;

    POSTPROC_COMPLEX

    ltfat_free(coef2);

}

LTFAT_EXTERN void
LTFAT_NAME_REAL(dwilt_fb)(const LTFAT_REAL *f, const LTFAT_REAL *g,
                          const ltfatInt L, const ltfatInt gl,
                          const ltfatInt W, const ltfatInt M,
                          LTFAT_REAL *cout)
{
    const ltfatInt N = L/M;
    const ltfatInt coef2_ld = M + 1;
    const ltfatInt nyquestadd = (M%2)*coef2_ld;
    const LTFAT_REAL scalconst = (LTFAT_REAL) sqrt(2.0);

    LTFAT_COMPLEX *coef2 = ltfat_malloc((M+1)*N*W*sizeof*coef2);
    LTFAT_NAME(dgtreal_fb)(f, g, L, gl, W, M, 2*M, FREQINV, coef2);

    LTFAT_REAL* pcoef  = cout;
    LTFAT_COMPLEX* pcoef2 = coef2;

    POSTPROC_REAL

    ltfat_free(coef2);
}

#undef CH
#undef POSTPROC_REAL
#undef POSTPROC_COMPLEX