int vsip_cfirflt_d(
        vsip_cfir_d *fir,
        const vsip_cvview_d *xc,
        const vsip_cvview_d *yc)
{
    vsip_length nout,k;
    vsip_cvview_d xx = *(xc),
                  yy = *(yc);
    vsip_cvview_d H1 = *(fir->h),
                  H2 = *(fir->h);
    vsip_cvview_d *x=&xx,*y=&yy;
    vsip_cvview_d *h1=&H1,*h2=&H2;
    vsip_offset oinc;
    oinc = (vsip_offset)((vsip_stride)fir->D * x->stride);
    /* calculate number of terms in y */
    nout = (fir->N - fir->p);
    nout = ((nout % fir->D) == 0) ? (nout / fir->D ) : (nout / fir->D + 1);
    /* do overlap section */
    k = 0;
    x->length = fir->p + 1;
    h1->length = fir->s->length;
    h2->length = x->length;
    h2->offset = h1->length;
    while(x->length < fir->M){
        vsip_cscalar_d a = vsip_cvdot_d(h1,fir->s);
        vsip_cscalar_d b = vsip_cvdot_d(h2,x);
        vsip_cvput_d(y,k++,vsip_cmplx_d(a.r + b.r,a.i + b.i));
        x->length += fir->D;
        fir->s->length -= fir->D;
        fir->s->offset += fir->D;
        h1->length = fir->s->length;
        h2->length = x->length;
        h2->offset = h1->length;
    }
    x->offset += (x->length - fir->M) * x->stride;
    x->length = fir->M;
    while(k < nout){ /* do the rest of the pieces */
       vsip_cvput_d(y,k++,vsip_cvdot_d(fir->h,x));
       x->offset += oinc;
    }
    {
       vsip_stride temp_p = (fir->p % fir->D) - (fir->N % fir->D);
       fir->p = ((temp_p < 0) ? (vsip_length)((vsip_stride)fir->D + temp_p) : (vsip_length)temp_p);
    }
    fir->s->offset = 0;
    fir->s->length = (fir->state == VSIP_STATE_SAVE) ? fir->M - 1 - fir->p : fir->M -1;
    x->length = fir->s->length;
    /* fix by JMA 31/01/2000, incorrect offset calculation */
    /* x->offset = xc->length - fir->s->length; */
     x->offset = xc->offset + (xc->length - fir->s->length) * xc->stride;
    if((fir->s->length > 0) && (fir->state == VSIP_STATE_SAVE)) 
               VI_cvcopy_d_d(x,fir->s);
    if(fir->state == VSIP_STATE_NO_SAVE) {  
       VI_cvfill_d(vsip_cmplx_d((vsip_scalar_d)0,(vsip_scalar_d)0),fir->s);
       fir->p = 0;
    }
    return k;
}
Example #2
0
File: ssdiv.c Project: ssacco/specs
int main()
{
    int i;
    /* define some data space */
    vsip_cvview_d* dataComplex;
    vsip_cvview_d* dataComplexQuotient;

    vsip_init((void *)0);
    dataComplex = vsip_cvcreate_d(L, VSIP_MEM_NONE);
    dataComplexQuotient = vsip_cvcreate_d(L, VSIP_MEM_NONE);
    /* put some complex data in dataComplex */
    for(i = 0; i < L; i++)
        vsip_cvput_d(dataComplex,i,
                     vsip_cmplx_d((double)(i * i),(double)(i+1)));
    /*divide dataComplex by some denom and print the input and output */
    vsip_cvrsdiv_d(dataComplex,denom,dataComplexQuotient);
    for(i=0; i<L; i++)
        printf("(%7.4f + %7.4fi) / %7.4f) = (%7.4f + %7.4fi)\n",
               vsip_real_d(vsip_cvget_d(dataComplex,i)),
               vsip_imag_d(vsip_cvget_d(dataComplex,i)),
               denom,
               vsip_real_d(vsip_cvget_d(dataComplexQuotient,i)),
               vsip_imag_d(vsip_cvget_d(dataComplexQuotient,i)));
    vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplex));
    vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplexQuotient));
    vsip_finalize((void *)0);
    return 0;
}
Example #3
0
int main(int argc, char *argv[]){vsip_init((void*)0);
{ if(argc < 4){
    printf("usage\nfirEx length decimation filterFile <indataFile >outputFile\n");
    exit(0);
   }
   {
       vsip_length N = (vsip_length)atoi(argv[1]);
       int D = atoi(argv[2]);
       vsip_scalar_vi n = 0,k = 0;
       vsip_scalar_d hvr,hvi;
       FILE *fh;
       vsip_cfir_d *fir;
       vsip_cvview_d *x = vsip_cvcreate_d(N,0),
                    *h,*y;
       fh = fopen(argv[3],"r");
       while(fscanf(fh,"%lf %lf",&hvr, &hvi) == 2) n++;
       rewind(fh);
       y = vsip_cvcreate_d(N/D + ((N % D) ? 1:0),0);
       h = vsip_cvcreate_d(n,0);
       n=0;
       while(fscanf(fh,"%lf %lf",&hvr,&hvi) == 2){
           vsip_cvput_d(h,n,vsip_cmplx_d(hvr,hvi));
           n++;
       }
       fclose(fh);
/*       fir = vsip_cfir_create_d(h,VSIP_SYM_EVEN_LEN_ODD,N,D,STATE,0,0); */
/*       fir = vsip_cfir_create_d(h,VSIP_SYM_EVEN_LEN_EVEN,N,D,STATE,0,0); */
       fir = vsip_cfir_create_d(h,VSIP_NONSYM,N,D,STATE,0,0); 
       n = VU_cscanstdin_d(x);
       while(n == N){
            k = vsip_cfirflt_d(fir,x,y);
            VU_cprintstdout_d(y,0,k);
            n = VU_cscanstdin_d(x);
       }
       if(n != 0){
            k = vsip_cfirflt_d(fir,x,y);
            VU_cprintstdout_d(y,0,k);
       }
       {/* test getattr */
           vsip_cfir_attr attr;
           vsip_cfir_getattr_d(fir,&attr);
           printf("kernel %lu\n input %lu\n output %lu\ndecimation %d\n",
               attr.kernel_len,attr.in_len,attr.out_len, attr.decimation);
       } 
       vsip_cvalldestroy_d(y);
       vsip_cvalldestroy_d(x);
       vsip_cvalldestroy_d(h);
       vsip_cfir_destroy_d(fir);
       }vsip_finalize((void*)0);return 1;
   }
} 
int main(){vsip_init((void*)0);
{
/*   vsip_cmview_d *B = vsip_cmcreate_d(P,N,VSIP_ROW,0);*/
   vsip_scalar_d Re[20], Im[20];
   vsip_cblock_d *Bblock = vsip_cblockbind_d(Re,Im,20,0);
   vsip_cmview_d *B = vsip_cmbind_d(Bblock,0,4,5,1,4);
   vsip_cvview_d *a = vsip_cvcreate_d(P,0),
                 *r = vsip_cvcreate_d(N,0);
   int i, j;
   for(i=0;i<P;i++) 
        vsip_cvput_d(a,i,vsip_cmplx_d(i,1 + sqrt(i)));
   
   for(i=0;i<P;i++) for(j=0;j<N;j++)
        vsip_cmput_d(B,i,j,vsip_cmplx_d(1 , i * j));
   
   vsip_cvmprod_d(a,B,r);
   printf("\n vector input \n v=[");

   for(i=0;i<P;i++)
          printf("(%5.2f %+5.2fi) ",
          vsip_real_d(vsip_cvget_d(a,i)),
          vsip_imag_d(vsip_cvget_d(a,i)));
   printf("]\n");
   
   printf("\n B input \n B =[\n");
   {for(i=0;i<P;i++) {for(j=0;j<N;j++){
           printf(" (%5.2f %+5.2fi) ",
             vsip_real_d(vsip_cmget_d(B,i,j)),
             vsip_imag_d(vsip_cmget_d(B,i,j)));
           }
           printf(";\n");
       }
       printf("]\n");
   }
   printf("\n vector output \n");
   for(i=0;i<N;i++)
           printf("(%5.2f, %5.2f) ",
             vsip_real_d(vsip_cvget_d(r,i)),
             vsip_imag_d(vsip_cvget_d(r,i)));
   printf("\n");
   vsip_cvalldestroy_d(a);
   vsip_cmalldestroy_d(B);
   vsip_cvalldestroy_d(r);
   }vsip_finalize((void*)0);return 0;
}
Example #5
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);
  }
}