Exemple #1
0
int main()
{
  int i;
  vsip_randstate *state;
  vsip_cmview_d *xy;
  vsip_cvview_d *xy_row;
  vsip_length stride;
  vsip_cvview_d *sum;
  vsip_fftm_d *ccfftmip;
  vsip_length seed =0, num_procs=1, id=1;

  vsip_init((void *)0);
  /* Initialize Random Number Generator */
  state = vsip_randcreate(seed, num_procs, id, VSIP_PRNG);
  /* Row major, 64 (ROWS) of 16 point data vectors */
  xy = vsip_cmcreate_d(ROWS, 16, VSIP_ROW, VSIP_MEM_NONE);
  /* Bind xy_row view initially to row 0 of xy */
  xy_row = vsip_cmrowview_d(xy, 0);
  /* Stride between column elements of xy */
  stride = vsip_cmgetcolstride_d(xy);
  sum = vsip_cvcreate_d(N, VSIP_MEM_NONE);
  /* Create an in-place Cmplx->Cmplx Multiple N-pt FFT */
  ccfftmip = vsip_ccfftmip_create_d(ROWS, N, 1.0, VSIP_FFT_FWD,
				    VSIP_ROW, 1, VSIP_ALG_TIME);
  /* Initialize xy by rows with complex Gaussian noise N(0,1) */
  for (i=0; i<ROWS; i++) 
  {
    vsip_cvputoffset_d(xy_row, i*stride); /* view of row i of xy */
    vsip_cvrand_d(state,xy_row); /* Initialize row i of xy */
  }
  /* Compute an in-place Cmplx->Cmplx Multiple N-pt FFT using the
     ccfftmip object*/
  vsip_ccfftmip_d(ccfftmip, xy);
  /* Coherently sum the rows together (in the Freq domain) */
  vsip_cvputoffset_d(xy_row, 0);
  vsip_cvcopy_d_d(xy_row, sum); /* sum = row 0 of xy */
  for (i=1; i<ROWS; i++)
  {
    vsip_cvputoffset_d(xy_row, i*stride); /* view of row i of xy */
    vsip_cvadd_d(xy_row, sum, sum); /* sum += row i of xy */
  }
  /* Print it */
  printf("\nComplex Output Vector (Real, Imag)\n");
  for(i=0; i<N; i++)
    printf("%d:\t" SCMPLX "\n", i, ACMPLX(vsip_cvget_d(sum,i)));
  printf("\n");
  /* Destroy all the objects */
  vsip_fftm_destroy_d(ccfftmip);
  vsip_cvdestroy(xy_row);
  vsip_cvdestroy(sum);
  vsip_cmalldestroy_d(xy);
  vsip_randdestroy(state);
  vsip_finalize((void *)0);
  return(0);
}
Exemple #2
0
void
ref_ccorr_d(vsip_bias bias, vsip_support_region sup,
            vsip_cvview_d const *ref,
            vsip_cvview_d const *in,
            vsip_cvview_d const *out)
{
  vsip_length M = vsip_cvgetlength_d(ref);
  vsip_length N = vsip_cvgetlength_d(in);
  vsip_length P = vsip_cvgetlength_d(out);
  vsip_length expected_P = ref_corr_output_size(sup, M, N);
  vsip_stride shift      = ref_expected_shift(sup, M);

  assert(expected_P == P);

  vsip_cvview_d *sub = vsip_cvcreate_d(M, VSIP_MEM_NONE);

  // compute correlation
  vsip_index i;
  for (i=0; i<P; ++i)
  {
    vsip_cvfill_d(vsip_cmplx_d(0,0), sub);
    vsip_stride pos = (vsip_stride)i + shift;
    double scale;
    if (pos < 0)
    {
      vsip_cvview_d *subsub = vsip_cvsubview_d(sub, -pos, M + pos);
      vsip_cvview_d *insub = vsip_cvsubview_d(in, 0, M + pos);
      vsip_cvcopy_d_d(insub, subsub);
      vsip_cvdestroy_d(subsub);
      vsip_cvdestroy_d(insub);
      scale = M + pos;
    }
    else if (pos + M > N)
    {
      vsip_cvview_d *subsub = vsip_cvsubview_d(sub, 0, N - pos);
      vsip_cvview_d *insub = vsip_cvsubview_d(in, pos, N - pos);
      vsip_cvcopy_d_d(insub, subsub);
      vsip_cvdestroy_d(subsub);
      vsip_cvdestroy_d(insub);
      scale = N - pos;
    }
    else
    {
      vsip_cvview_d *insub = vsip_cvsubview_d(in, pos, M);
      vsip_cvcopy_d_d(insub, sub);
      vsip_cvdestroy_d(insub);
      scale = M;
    }

#if VSIP_IMPL_CORR_CORRECT_SAME_SUPPORT_SCALING
#else
    if (sup == VSIP_SUPPORT_SAME)
    {
      if      (i < (M/2))     scale = i + (M+1)/2;         // i + ceil(M/2)
      else if (i < N - (M/2)) scale = M;                   // M
      else                    scale = N - 1 + (M+1)/2 - i; // N-1+ceil(M/2)-i
    }
#endif
      
    vsip_cscalar_d val = vsip_cvjdot_d(ref, sub);
    if (bias == VSIP_UNBIASED)
    {
      val.r /= scale;
      val.i /= scale;
    }
    vsip_cvput_d(out, i, val);
  }
}