Example #1
0
/*! \brief
 * Compute one cross correlation corr = f x g using FFT.
 *
 * \param[in] n number of data point
 * \param[in] f first function
 * \param[in] g second function
 * \param[out] corr output correlation
 * \param[in] fft FFT data structure
 */
static void cross_corr_low(int n, real f[], real g[], real corr[], gmx_fft_t fft)
{
    int             i;
    const int       size = zeroPaddingSize(n);
    double    **    in1, ** in2;
    snew(in1, size);
    snew(in2, size);

    for (i = 0; i < size; i++)
    {
        snew(in1[i], 2);
        snew(in2[i], 2);
    }

    for (i = 0; i < n; i++)
    {
        in1[i][0]  = (double)f[i];
        in1[i][1]  = 0;
        in2[i][0]  = (double)g[i];
        in2[i][1]  = 0;
    }
    for (; i < size; i++)
    {
        in1[i][0]  = 0;
        in1[i][1]  = 0;
        in2[i][0]  = 0;
        in2[i][1]  = 0;
    }


    gmx_fft_1d(fft, GMX_FFT_FORWARD, in1, in1);
    gmx_fft_1d(fft, GMX_FFT_FORWARD, in2, in2);

    for (i = 0; i < size; i++)
    {
        complexConjugatMult(in1[i], in2[i]);
        in1[i][0] /= size;
    }
    gmx_fft_1d(fft, GMX_FFT_BACKWARD, in1, in1);

    for (i = 0; i < n; i++)
    {
        corr[i] = (real)(in1[i][0]);
    }

    for (i = 0; i < size; i++)
    {
        sfree(in1[i]);
        sfree(in2[i]);
    }

    sfree(in1);
    sfree(in2);

}
Example #2
0
/*! \brief
 * Compute one cross correlation corr = f x g using FFT.
 *
 * \param[in] n number of data point
 * \param[in] f first function
 * \param[in] g second function
 * \param[out] corr output correlation
 * \param[in] fft FFT data structure
 */
static void cross_corr_low(int n, const real f[], const real g[], real corr[], gmx_fft_t fft)
{
    int             i;
    const int       size = zeroPaddingSize(n);
    t_complex *     in1, * in2;

    snew(in1, size);
    snew(in2, size);

    for (i = 0; i < n; i++)
    {
        in1[i].re  = f[i];
        in1[i].im  = 0;
        in2[i].re  = g[i];
        in2[i].im  = 0;
    }
    for (; i < size; i++)
    {
        in1[i].re  = 0;
        in1[i].im  = 0;
        in2[i].re  = 0;
        in2[i].im  = 0;
    }
    gmx_fft_1d(fft, GMX_FFT_FORWARD, in1, in1);
    gmx_fft_1d(fft, GMX_FFT_FORWARD, in2, in2);

    for (i = 0; i < size; i++)
    {
        complexConjugatMult(&in1[i], &in2[i]);
        in1[i].re /= size;
    }
    gmx_fft_1d(fft, GMX_FFT_BACKWARD, in1, in1);

    for (i = 0; i < n; i++)
    {
        corr[i] = in1[i].re;
    }

    sfree(in1);
    sfree(in2);

}