File: dgt_multi.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 (136 lines) | stat: -rw-r--r-- 4,202 bytes parent folder | download | duplicates (6)
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
#include "ltfat.h"
#include "ltfat_types.h"

LTFAT_EXTERN void
LTFAT_NAME(nonsepwin2multi)(const LTFAT_COMPLEX *g,
                            const ltfatInt L, const ltfatInt Lg, const ltfatInt a, const ltfatInt M,
                            const ltfatInt lt1, const ltfatInt lt2,
                            LTFAT_COMPLEX *mwin)
{
    const ltfatInt b = L / M;

    const LTFAT_REAL scal = 2 * PI / L;

    LTFAT_COMPLEX *gwork = (LTFAT_COMPLEX *)ltfat_malloc(L * sizeof(LTFAT_COMPLEX));
    LTFAT_NAME(fir2long_c)((const LTFAT_COMPLEX*)g, Lg, L, (LTFAT_COMPLEX*)gwork);

    for (ltfatInt w = 0; w < lt2; w++)
    {
        const ltfatInt wavenum = ((w * lt1) % lt2) * b / lt2;
        for (ltfatInt l = 0; l < L; l++)
        {
            mwin[l + w * L] = cexp(I * scal * l * wavenum) * gwork[positiverem(l - w * a, L)];
        }
    }

    ltfat_free(gwork);
}


LTFAT_EXTERN LTFAT_NAME(dgt_multi_plan)
LTFAT_NAME(dgt_multi_init)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g,
                           const ltfatInt L, const ltfatInt Lg,
                           const ltfatInt W, const ltfatInt a, const ltfatInt M,
                           const ltfatInt lt1, const ltfatInt lt2,
                           LTFAT_COMPLEX *cout, unsigned flags)
{

    LTFAT_NAME(dgt_multi_plan) plan;

    plan.a = a;
    plan.M = M;
    plan.L = L;
    plan.Lg = Lg;
    plan.W = W;

    plan.lt1 = lt1;
    plan.lt2 = lt2;

    plan.f     = (LTFAT_COMPLEX *)f;
    plan.cout  = cout;

    const ltfatInt N   = L / a;
    const ltfatInt Ns  = N / lt2;

    plan.mwin = (LTFAT_COMPLEX *)ltfat_malloc(L * lt2 * sizeof(LTFAT_COMPLEX));
    plan.c_scratch = (LTFAT_COMPLEX *)ltfat_malloc(M * Ns * W * sizeof(LTFAT_COMPLEX));


    LTFAT_NAME(nonsepwin2multi)(g, L, Lg, a, M, lt1, lt2, plan.mwin);

    plan.rect_plan_array = (LTFAT_NAME(dgt_long_plan)*) ltfat_malloc(lt2 * sizeof(LTFAT_NAME(dgt_long_plan)));

    for (ltfatInt win = 0; win < lt2; win++)
    {
        plan.rect_plan_array[win] =
            LTFAT_NAME(dgt_long_init)((const LTFAT_COMPLEX*)plan.f,
                                      (const LTFAT_COMPLEX*)(plan.mwin + L * win),
                                      L, W, a * lt2, M, 
                                      (LTFAT_COMPLEX*)plan.c_scratch, 0, flags);
    }

    plan.mod = (LTFAT_COMPLEX*) ltfat_malloc(N * sizeof(LTFAT_COMPLEX));

    for (ltfatInt win = 0; win < plan.lt2; win++)
    {
        for (ltfatInt n = 0; n < Ns; n++)
        {
            plan.mod[win + n * lt2] = cexp(-2 * PI * I * (a * n * ((win * lt1) % lt2)) / M);
        }
    }

    return plan;
}

LTFAT_EXTERN void
LTFAT_NAME(dgt_multi_execute)(const LTFAT_NAME(dgt_multi_plan) plan)
{
    const ltfatInt N   = plan.L / plan.a;
    const ltfatInt Ns  = N / plan.lt2;

    const ltfatInt M = plan.M;
    const ltfatInt W = plan.W;
    const ltfatInt lt2 = plan.lt2;

    for (ltfatInt win = 0; win < plan.lt2; win++)
    {
        LTFAT_NAME(dgt_long_execute)(plan.rect_plan_array[win]);
        for (ltfatInt w = 0; w < W; w++)
        {
            for (ltfatInt n = 0; n < Ns; n++)
            {
                for (ltfatInt m = 0; m < M; m++)
                {
                    plan.cout[m + win * M + n * lt2 * M + w * M * N] = plan.mod[win + n * lt2] * plan.c_scratch[m + n * M + w * M * Ns];
                }
            }
        }
    }
}

LTFAT_EXTERN void
LTFAT_NAME(dgt_multi_done)(LTFAT_NAME(dgt_multi_plan) plan)
{
    for (ltfatInt ii = 0; ii < plan.lt2; ii++)
    {
        LTFAT_NAME(dgt_long_done)(plan.rect_plan_array[ii]);
    }
    LTFAT_SAFEFREEALL(plan.mod, plan.rect_plan_array, plan.c_scratch, plan.mwin);
}


LTFAT_EXTERN void
LTFAT_NAME(dgt_multi)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g,
                      const ltfatInt L, const ltfatInt Lg, const ltfatInt W, const ltfatInt a, const ltfatInt M,
                      const ltfatInt lt1, const ltfatInt lt2,
                      LTFAT_COMPLEX *cout)
{

    LTFAT_NAME(dgt_multi_plan) plan = LTFAT_NAME(dgt_multi_init)(
                                          f, g, L, Lg, W, a, M, lt1, lt2, cout, FFTW_ESTIMATE);

    LTFAT_NAME(dgt_multi_execute)(plan);

    LTFAT_NAME(dgt_multi_done)(plan);

}