I'm just starting out with wavelet transform, and I want to do pitch detection.So I downloaded gnu's GSL computing library.But I don't understand a few lines of code in the wavelet transform function, can someone help me explain it?I posted the function related code.thank you
#define ELEMENT(a,stride,i) ((a)[(stride)*(i)])
int
gsl_wavelet_transform (const gsl_wavelet * w,
double *data, size_t stride, size_t n,
gsl_wavelet_direction dir,
gsl_wavelet_workspace * work)
{
size_t i;
if (work->n < n)
{
//GSL_ERROR ("not enough workspace provided", GSL_EINVAL);
}
if (binary_logn (n) == -1)
{
//GSL_ERROR ("n is not a power of 2", GSL_EINVAL);
}
if (n < 2)
{
return GSL_SUCCESS;
}
if (dir == gsl_wavelet_forward)
{
for (i = n; i >= 2; i >>= 1)
{
dwt_step (w, data, stride, i, dir, work);
}
}
else
{
for (i = 2; i <= n; i <<= 1)
{
dwt_step (w, data, stride, i, dir, work);
}
}
return GSL_SUCCESS;
}
static void
dwt_step (const gsl_wavelet * w, double *a, size_t stride, size_t n,
gsl_wavelet_direction dir, gsl_wavelet_workspace * work)
{
double ai, ai1;
size_t i, ii;
size_t jf;
size_t k;
size_t n1, ni, nh, nmod;
for (i = 0; i < work->n; i++)
{
work->scratch[i] = 0.0;
}
**nmod = w->nc * n;** //Can not understand the meaning of this code
**nmod -= w->offset;** //Why does it need to be offset /* center support */
**n1 = n - 1;**
**nh = n >> 1;**
if (dir == gsl_wavelet_forward)
{
for (ii = 0, i = 0; i < n; i += 2, ii++)
{
double h = 0, g = 0;
**ni = i + nmod;** //What meaning
for (k = 0; k < w->nc; k++)
{
**jf = n1 & (ni + k);** //What meaning
h += w->h1[k] * ELEMENT (a, stride, jf);
g += w->g1[k] * ELEMENT (a, stride, jf);
}
work->scratch[ii] += h;
work->scratch[ii + nh] += g;
}
}
/* else { for (ii = 0, i = 0; i < n; i += 2, ii++) { ai = ELEMENT (a, stride, ii); ai1 = ELEMENT (a, stride, ii + nh); ni = i + nmod; for (k = 0; k < w->nc; k++) { jf = (n1 & (ni + k)); work->scratch[jf] += (w->h2[k] * ai + w->g2[k] * ai1); } } } */ for (i = 0; i < n; i++) { ELEMENT (a, stride, i) = work->scratch[i]; } }
Aucun commentaire:
Enregistrer un commentaire