int VU_vfrdB_f(vsip_vview_f *a,vsip_scalar_f range) { int ret = 0; vsip_length N_len=vsip_vgetlength_f(a); vsip_cvview_f *ca=vsip_cvcreate_f(N_len,VSIP_MEM_NONE); vsip_fft_f *fft = vsip_ccfftip_create_f( N_len,1,VSIP_FFT_FWD,0,0); vsip_vview_f *ra = vsip_vrealview_f(ca), *ia = vsip_vimagview_f(ca), *ta = vsip_vcloneview_f(a); vsip_offset s = (vsip_offset)vsip_vgetstride_f(ta); if((ca == NULL) || (fft == NULL) || (ra == NULL) || (ia == NULL) || (ta == NULL)){ret = 1; }else{ vsip_vfill_f(0,ia); vsip_vcopy_f_f(a,ra); vsip_ccfftip_f(fft,ca); vsip_vcmagsq_f(ca,ra); { vsip_index ind;/* scale by "range" min to max*/ vsip_scalar_f max = vsip_vmaxval_f(ra,&ind); vsip_scalar_f min = max * range; vsip_vclip_f(ra,min,max,min,max,ra); } if(N_len%2){vsip_length Nlen = N_len/2; vsip_vputlength_f(ta,Nlen+1); vsip_vputlength_f(ra,Nlen+1); vsip_vputoffset_f(ta,Nlen * s); vsip_vcopy_f_f(ra,ta); vsip_vputlength_f(ra,Nlen); vsip_vputlength_f(ta,Nlen); vsip_vputoffset_f(ta,vsip_vgetoffset_f(a)); vsip_vputoffset_f(ra,Nlen+1); vsip_vcopy_f_f(ra,ta); }else{vsip_length Nlen = N_len/2; vsip_vcopy_f_f(ra,ta); vsip_vputlength_f(ta,Nlen); vsip_vputlength_f(a,Nlen); vsip_vputoffset_f(ta,(vsip_offset)(Nlen) * s); vsip_vswap_f(ta,a); vsip_vputlength_f(a,N_len); }vsip_vlog10_f(a,a);vsip_svmul_f(10,a,a); }vsip_fft_destroy_f(fft); vsip_vdestroy_f(ra); vsip_vdestroy_f(ia); vsip_cvalldestroy_f(ca);vsip_vdestroy_f(ta); return ret; }
void vsip_ccorrelate1d_f( const vsip_ccorr1d_f *cor, vsip_bias bias, const vsip_cvview_f *h, const vsip_cvview_f *x, const vsip_cvview_f *y) { vsip_cvview_f xx = *cor->x, hh = *cor->h; vsip_cvview_f *xt = &xx, *ht = &hh; xt->length = cor->x->length - x->length; VI_cvfill_f(vsip_cmplx_f((vsip_scalar_f)0,(vsip_scalar_f)0),xt); xt->offset = xt->length; xt->length = x->length; VI_cvcopy_f_f(x,xt); xt->length = cor->x->length; xt->offset = 0; ht->length = cor->h->length - h->length; ht->offset = h->length; VI_cvfill_f(vsip_cmplx_f((vsip_scalar_f)0,(vsip_scalar_f)0),ht); ht->offset = 0; ht->length = h->length; VI_cvcopy_f_f(h,ht); vsip_ccfftip_f(cor->fft,cor->h); vsip_ccfftip_f(cor->fft,cor->x); vsip_cvjmul_f(cor->x,cor->h,cor->x); vsip_cvconj_f(cor->x,cor->x); vsip_rscvmul_f(1/(vsip_scalar_f)cor->N,cor->x,cor->x); vsip_ccfftip_f(cor->fft,cor->x); /* vsip_cvconj_f(cor->x,cor->x); */ switch(cor->support){ case VSIP_SUPPORT_FULL: xt->offset = xt->length - cor->mn; xt->length = y->length; if(bias == VSIP_UNBIASED){ VI_cvunbiasfull_f(cor,xt,y); } else { VI_cvcopy_f_f(xt,y); } break; case VSIP_SUPPORT_SAME: xt->offset = xt->length - cor->mn + (cor->m-1)/2; xt->length = y->length; if(bias == VSIP_UNBIASED){ VI_cvunbiassame_f(cor,xt,y); } else { VI_cvcopy_f_f(xt,y); } break; case VSIP_SUPPORT_MIN: xt->offset = xt->length - cor->mn + cor->m - 1; xt->length = y->length; if(bias == VSIP_UNBIASED){ vsip_rscvmul_f((vsip_scalar_f)1.0/(vsip_scalar_f)cor->m,xt,y); } else { VI_cvcopy_f_f(xt,y); } break; } return; }