- Code: Select all
`array hanming(int nx, int ny, float alpha)`

{

float twopi = 2 * Pi;

array w1 = seq(nx);

w1 = alpha + (alpha - 1.) * cos(w1 * twopi / (float) nx);

if (ny > 1) {

array w2 = seq(ny);

w2 = alpha + (alpha - 1.) * cos(w2 * twopi / (float) ny);

return matmul(w1, w2, B_transpose);

}

return w1;

}

void hanmingcpu(float *res, int nx, int ny, float alpha)

{

int i, j;

float fact;

float *w1, *w2;

/* Initialise constants */

double pi = 3.141592654;

double two_pi = 2.0 * pi;

nx = (nx > 0) ? nx : 1;

ny = (ny > 0) ? ny : 1;

/* Initialize window arrays */

w1 = (float *) (malloc(nx * sizeof(float)));

for (i = 0; i < nx; i++) {

w1[i] = alpha +

(alpha -

1.) *

((float)

(cos((double) (two_pi * ((float) i) / ((float) nx)))));

}

if (ny > 1) {

w2 = (float *) (malloc(ny * sizeof(float)));

for (i = 0; i < ny; i++) {

w2[i] = alpha +

(alpha -

1.) *

((float)

(cos((double) (two_pi * ((float) i) / ((float) ny)))));

}

}

/* Set window */

for (j = 0; j < ny; j++) {

fact = (ny > 1) ? w2[j] : 1.0;

for (i = 0; i < nx; i++) {

res[j * nx + i] = fact * w1[i];

}

}

free(w1);

if (ny > 1)

free(w2);

}