本文整理汇总了C++中cabs函数的典型用法代码示例。如果您正苦于以下问题:C++ cabs函数的具体用法?C++ cabs怎么用?C++ cabs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cabs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ov_matrix12x12_rowsumnorm
double ov_matrix12x12_rowsumnorm(matrix12x12 A) {
double norm, nrm;
int i, j;
norm = 0.0;
for (i=0; i<12; i++) {
nrm = 0.0;
for (j=0; j<12; j++)
nrm += cabs(A[i][j]);
if (nrm > norm)
norm = nrm;
}
return norm;
}
开发者ID:LorenzoRiggio,项目名称:tmLQCD,代码行数:18,代码来源:overlaptests.c
示例2: RealCepstrum
// Compute Real Cepstrum Of Signal
void RealCepstrum(int n, float *signal, float *realCepstrum)
{
float *realTime, *imagTime, *realFreq, *imagFreq;
int i;
realTime = new float[n];
imagTime = new float[n];
realFreq = new float[n];
imagFreq = new float[n];
// Compose Complex FFT Input
for(i = 0; i < n; i++)
{
realTime[i] = signal[i];
imagTime[i] = 0.0f;
}
// Perform DFT
DFT(n, realTime, imagTime, realFreq, imagFreq);
// Calculate Log Of Absolute Value
for(i = 0; i < n; i++)
{
realFreq[i] = logf(cabs(realFreq[i], imagFreq[i]));
imagFreq[i] = 0.0f;
}
// Perform Inverse FFT
InverseDFT(n, realTime, imagTime, realFreq, imagFreq);
// Output Real Part Of FFT
for(i = 0; i < n; i++)
realCepstrum[i] = realTime[i];
delete realTime;
delete imagTime;
delete realFreq;
delete imagFreq;
}
开发者ID:OpenDAWN,项目名称:triceratops,代码行数:44,代码来源:minBLEP.cpp
示例3: DiffIE
PetscErrorCode DiffIE(Vec originalVec, Vec reducedVec, Vec Distance, Vec nParticlePerCube)
{
// Find the distance between 2 solutions originalVec and reducedVec
PetscInt s,t;
PetscInt n,xstart,xend;
PetscScalar tmp,v,diff;
Vec vec;
VecScatter scat;
IS is;
PetscFunctionBegin;
VecGetOwnershipRange(originalVec,&xstart,&xend);
VecGetSize(reducedVec,&n);
VecCreate(PETSC_COMM_SELF,&vec);
VecSetSizes(vec,PETSC_DECIDE,n);
VecSetFromOptions(vec);
ISCreateStride(PETSC_COMM_WORLD,n,0,1,&is);
VecScatterCreate(reducedVec,PETSC_NULL,vec,is,&scat);
//VecScatterCreateToAll(reducedVec,&scat,&vec);
VecScatterBegin(scat,reducedVec,vec,INSERT_VALUES,SCATTER_FORWARD);
VecScatterEnd(scat,reducedVec,vec,INSERT_VALUES,SCATTER_FORWARD);
for(s=xstart;s<xend;s++)
{
t = ScatIE.FindCube(s);
VecGetValues(vec,1,&t,&tmp);
VecGetValues(originalVec,1,&s,&v);
diff = cabs(v - tmp);
VecSetValues(Distance,1,&t,&diff,ADD_VALUES);
tmp = 1;
VecSetValues(nParticlePerCube,1,&t,&tmp,ADD_VALUES);
}
VecDestroy(&vec);
VecScatterDestroy(&scat);
ISDestroy(&is);
PetscFunctionReturn(0);
}
开发者ID:trannhan,项目名称:Fast-algorithm,代码行数:42,代码来源:scat.c
示例4: output_td_waveform
/* writes a time-domain waveform to stdout as tab-separated values */
int output_td_waveform(REAL8TimeSeries * h_plus, REAL8TimeSeries * h_cross, struct params p)
{
double t0;
size_t j;
t0 = XLALGPSGetREAL8(&h_plus->epoch);
if (p.amp_phase) {
REAL8Sequence *amp = XLALCreateREAL8Sequence(h_plus->data->length);
REAL8Sequence *phi = XLALCreateREAL8Sequence(h_plus->data->length);
double phi0;
/* compute the amplitude and phase of h+ - i hx */
for (j = 0; j < h_plus->data->length; ++j) {
double complex z = h_plus->data->data[j] - I * h_cross->data->data[j];
amp->data[j] = cabs(z);
phi->data[j] = carg(z);
}
/* unwrap the phase */
XLALREAL8VectorUnwrapAngle(phi, phi);
/* make phase in range -pi to +pi at end of waveform */
/* extrapolate the end of the waveform using last and second last points */
phi0 = 2 * phi->data[phi->length - 1] - phi->data[phi->length - 2];
// phi0 = phi->data[phi->length - 1];
phi0 -= fmod(phi0 + copysign(LAL_PI, phi0), 2.0 * LAL_PI) - copysign(LAL_PI, phi0);
for (j = 0; j < phi->length; ++j)
phi->data[j] -= phi0;
fprintf(stdout, "# time (s)\th_abs (strain)\t h_arg (rad)\n");
for (j = 0; j < h_plus->data->length; ++j)
fprintf(stdout, "%.9f\t%e\t%e\n", t0 + j * h_plus->deltaT, amp->data[j], phi->data[j]);
XLALDestroyREAL8Sequence(phi);
XLALDestroyREAL8Sequence(amp);
} else {
fprintf(stdout, "# time (s)\th_+ (strain)\th_x (strain)\n");
for (j = 0; j < h_plus->data->length; ++j)
fprintf(stdout, "%.9f\t%e\t%e\n", t0 + j * h_plus->deltaT, h_plus->data->data[j], h_cross->data->data[j]);
}
return 0;
}
开发者ID:GeraintPratten,项目名称:lalsuite,代码行数:42,代码来源:inspiral.c
示例5: inverse
// calculates the inverse of the matrix M outputs to M_1 //
int
inverse( GLU_complex M_1[ NCNC ] ,
const GLU_complex M[ NCNC ] )
{
#if (defined HAVE_LAPACKE_H)
const int n = NC , lda = NC ;
int ipiv[ NC + 1 ] ;
memcpy( M_1 , M , NCNC * sizeof( GLU_complex ) ) ;
int info = LAPACKE_zgetrf( LAPACK_ROW_MAJOR , n , n , M_1 , lda , ipiv ) ;
info = LAPACKE_zgetri( LAPACK_ROW_MAJOR , n , M_1 , lda, ipiv ) ;
return info ;
#elif (defined CLASSICAL_ADJOINT_INV)
// define the adjunct //
GLU_complex adjunct[ NCNC ] GLUalign ;
register GLU_complex deter = cofactor_transpose( adjunct , M ) ;
// here we worry about numerical stability //
if( cabs( deter ) < NC * PREC_TOL ) {
fprintf( stderr , "[INVERSE] Matrix is singular !!! "
"deter=%1.14e %1.14e \n" , creal( deter ) , cimag( deter ) ) ;
write_matrix( M ) ;
return GLU_FAILURE ;
}
// obtain inverse of M from 1/( detM )*adj( M ) //
size_t i ;
deter = 1.0 / deter ;
for( i = 0 ; i < NCNC ; i++ ) { M_1[i] = adjunct[i] * deter ; }
return GLU_SUCCESS ;
#else
#if NC == 2
// use the identity, should warn for singular matrices
const double complex INV_detM = 1.0 / ( det( M ) ) ;
M_1[ 0 ] = M[ 3 ] * INV_detM ;
M_1[ 1 ] = -M[ 1 ] * INV_detM ;
M_1[ 2 ] = -M[ 2 ] * INV_detM ;
M_1[ 3 ] = M[ 0 ] * INV_detM ;
return GLU_SUCCESS ;
#else
return gauss_jordan( M_1 , M ) ;
#endif
#endif
}
开发者ID:RJHudspith,项目名称:GLU,代码行数:42,代码来源:invert_SSE.c
示例6: v_matrix_element
static double_complex v_matrix_element(unsigned *total_num_eval,
const struct integrand_params *params,
double r_max, double abs_err,
double rel_err, unsigned limit)
{
double est_err;
unsigned num_eval;
const double_complex integral = gk_cquad(integrand, params, 0, r_max,
abs_err, rel_err, limit,
&est_err, &num_eval);
const double_complex element = 2 / M_PI * integral;
if (!(est_err < dmax(abs_err, rel_err * cabs(integral)))) {
fprintf(stderr, "WARNING: integral did not converge: "
"%i evals; error is %g, required %g\n",
num_eval, est_err, abs_err);
fflush(stderr);
}
if (total_num_eval)
*total_num_eval += num_eval;
return element;
}
开发者ID:xrf,项目名称:phy982-proj,代码行数:21,代码来源:proj.c
示例7: compute_mandelbrot
double compute_mandelbrot(double _Complex c, int maxiter){
double _Complex z = 0;
int value = 0;
int diverge = 0;
int n;
for (n=0; n < maxiter; n++){
z = cpow (z, 2) + c;
if (cabs(z) > 2){
value = n;
diverge = 1;
break;
}
}
if (diverge == 1){
return value;
}
else{
return 2;
}
}
开发者ID:hkjeldsberg,项目名称:inf3331,代码行数:21,代码来源:mandelbrot.c
示例8: CT_Freq_Res_mag
void CT_Freq_Res_mag(double *num,double *den,int N,int points,double *response,double Wmax)
{
double complex response_num[points];
double complex response_den[points];
double w;
int i,j;
double complex S;
for(w=0,j=0;w< Wmax; w= w+(Wmax/points)){
S = 1;
response_num[j] = 0;
response_den[j] = 0;
for(i=N-1;i>=0;i--){
response_num[j] += (num[i]*S);
response_den[j] += (den[i]*S);
S *= I*w;
}
response[j] = cabs(response_num[j]/response_den[j]);
j++;
}
}
开发者ID:RubiksD,项目名称:DSP_Library,代码行数:21,代码来源:Freq_Res.c
示例9: cos
Signal::Signal() {
value.resize(N);
int n;
for (n = 0; n < N; n++) {
value[n] = A0 * cos(phase(n)) + A0 * sin(phase(n)) * _Complex_I;
}
ofstream infile;
infile.open("fq.dat");
for (int n = 1; n < N; n++) {
infile << (phase(n) - phase(n - 1)) / (Ts * 2 * M_PI) << " " << (n * Ts) << endl;
frequency.push_back((phase(n) - phase(n - 1)) / (Ts * 2 * M_PI));
}
infile.close();
infile.open("s.dat");
for (int n = 0; n < N; n++) {
infile << cabs(value[n]) * cos(carg(value[n])) << " " << (n * Ts) << endl;
}
infile.close();
}
开发者ID:porcupineG,项目名称:CCM,代码行数:21,代码来源:signal.cpp
示例10: main
int main()
{
FILE *fp_r = fopen("Eth_r.txt", "r");
FILE *fp_i = fopen("Eth_i.txt", "r");
Complex datas[n];
memset(datas, 0, sizeof(Complex)*n);
for(int j=0; j<1500; j++)
{
double rm, im;
fscanf(fp_r, "%lf", &rm);
fscanf(fp_i, "%lf", &im);
datas[j] = rm + I*im;
}
printf("read file\n");
FILE *outR = fopen("re.txt", "w");
FILE *outI = fopen("im.txt", "w");
for(int i=0; i<1500; i++){
fprintf(outR, "%lf\n", creal(datas[i]));
fprintf(outI, "%lf\n", cimag(datas[i]));
}
fclose(outR);
fclose(outI);
Complex *res = cdft(datas, n);
FILE *fp = fopen("rest2.txt", "w");
for(int i=0; i<1500; i++)
{
fprintf(fp, "%lf\n", cabs(res[i]) / sqrt(n));
}
free(res);
fclose(fp);
printf("finish\n");
return 0;
}
开发者ID:rennone,项目名称:Cpp,代码行数:40,代码来源:dft.c
示例11: laguer
int laguer(double complex a[], const int m, double complex *x, int *its, const int maxit) {
int iter, i, j;
double abx, abp, abm, err;
double complex dx,x1,b,d,f,g,h,sq,gp,gm,g2;
static double frac[MR+1] = {0.0,0.5,0.25,0.75,0.13,0.38,0.62,0.88,1.0};
for (iter = 1; iter <= maxit; iter++) {
*its = iter;
b = a[m];
err = cabs(b);
d = 0.;
f = 0.;
abx = cabs(*x);
for (j = m-1; j >= 0; j--) {
f = (*x) * f + d;
d = (*x) * d + b;
b = (*x) * b + a[j];
err = cabs(b) + abx * err;
}
err *= epss;
if (cabs(b) <= err) return(0);
g = d / b;
g2 = g * g;
h = g2 - 2. * f / b;
sq = csqrt((double)(m-1) * ((double)(m)*h - g2));
gp = g + sq;
gm = g - sq;
abp = cabs(gp);
abm = cabs(gm);
if (abp < abm) gp = gm;
dx=((dmax(abp,abm) > 0. ?
((double complex)(m))/gp :
(1. + abx)*(cos((double)iter) + _Complex_I*sin((double)iter))));
x1 = (*x) - dx;
if (creal(*x) == creal(x1) && cimag(*x) == cimag(x1)) {
return(0);
}
if (iter % MT) {
*x=x1;
}
else {
*x = (*x) - frac[iter/MT]*dx;
}
}
fprintf(stderr, "Too many iterations in laguer\n");
return(-1);
}
开发者ID:palao,项目名称:tmLQCD,代码行数:47,代码来源:laguer.c
示例12: noise_estimate
//Calculate noise buffer
void noise_estimate(){
int i;
float mag,s_factor;
for (i=0;i<FFTLEN;i++)
{
s_factor=1;
mag=cabs(buffer[i]);
N_i[i] = M1[i];
if(N_i[i]>M2[i]){N_i[i]=M2[i];}
if(N_i[i]>M3[i]){N_i[i]=M3[i];}
if(N_i[i]>M4[i]){N_i[i]=M4[i];}
SNR20=2-mag/N_i[i];//first order maclaurin
SNR=SNR20*20;
if(SNR>20){SNR=20;}
if(SNR<0){SNR=0;}
SNR_GAIN=-0.2*SNR+6;
if(add1==1){
if(i<=2||(i>=30&&i<=223)||i>=253){s_factor=50;}
}
N[i]=SNR_GAIN*s_factor*alpha*(1-lpf_weight_noise)*N_i[i]+lpf_weight_noise*N[i];
}
}
开发者ID:hd1812,项目名称:RTDSP-Projects,代码行数:23,代码来源:enhance.c
示例13: cpow
double complex
cpow(double complex a, double complex z)
{
double complex w;
double x, y, r, theta, absa, arga;
x = creal(z);
y = cimag(z);
absa = cabs(a);
if (absa == 0.0) {
return (0.0 + 0.0 * I);
}
arga = carg(a);
r = pow(absa, x);
theta = x * arga;
if (y != 0.0) {
r = r * exp(-y * arga);
theta = theta + y * log(absa);
}
w = r * cos(theta) + (r * sin(theta)) * I;
return w;
}
开发者ID:Alexpux,项目名称:Cygwin,代码行数:22,代码来源:cpow.c
示例14: noise_estimate
//Calculate noise buffer
void noise_estimate(){
int i;
float mag,s_factor;
for (i=0;i<FFTLEN;i++)
{
s_factor=1;
mag=cabs(buffer[i]);
N_i[i] = M1[i];
if(N_i[i]>M2[i]){N_i[i]=M2[i];}
if(N_i[i]>M3[i]){N_i[i]=M3[i];}
if(N_i[i]>M4[i]){N_i[i]=M4[i];}
SNR20=2-mag/N_i[i];//first order maclaurin
SNR=SNR20*20;
if(SNR>10){SNR=10;}
if(SNR<-5){SNR=-5;}
alpha=-0.2*SNR+5;
if(add1==1){
if(i<=5||i>=80){s_factor=2;}
}
N[i]=s_factor*alpha*(1-lpf_weight_noise)*N_i[i]+lpf_weight_noise*N[i];
}
}
开发者ID:hd1812,项目名称:RTDSP-Projects,代码行数:23,代码来源:Ad1_enhancement.c
示例15: combine_eig_spec
// NOTE: S is both an input AND output.
// Combines eigenspectra, fills S, but also computes the normalized absolute difference from what
// was previously in S. This difference = || S_new - S_old ||/N is returned in diff.
void combine_eig_spec( const fftw_complex *Sk, uint_t K, uint_t N, const double *wk, uint_t nwk, fftw_complex *S, double &diff){
uint_t iwt; //index of weight to use
diff=0;
double absdiff;
fftw_complex Sl;
for (uint_t ii=0; ii<N; ii++){
Sl=S[ii]; //stores previous value
S[ii]=0;
for ( uint_t jj=0; jj< K; jj++){
iwt=jj*nwk+(ii%nwk);
S[ii]=S[ii]+wk[iwt]*Sk[jj*N+ii]; //weighted average
}
absdiff=cabs(S[ii]-Sl); //absolute difference
diff=diff+absdiff;
}
diff=sqrt(diff)/N;
}
开发者ID:OldOldSwede,项目名称:mtpsd,代码行数:25,代码来源:mtcpsd.cpp
示例16: deconv
void deconv(double g[], int lg, double f[], int lf, double out[], int row_len) {
int ns = 0;
cplx *g2 = pad_two(g, lg, &ns);
cplx *f2 = pad_two(f, lf, &ns);
fft(g2, ns);
fft(f2, ns);
cplx h[ns];
for (int i = 0; i < ns; i++) h[i] = g2[i] / f2[i];
fft(h, ns);
for (int i = 0; i < ns; i++) {
if (cabs(creal(h[i])) < 1e-10)
h[i] = 0;
}
for (int i = 0; i > lf - lg - row_len; i--)
out[-i] = h[(i + ns) % ns]/32;
free(g2);
free(f2);
}
开发者ID:Anatolt,项目名称:RosettaCodeData,代码行数:22,代码来源:deconvolution-2d+-1.c
示例17: load_V_from_U
static void
load_V_from_U(info_t *info, hisq_auxiliary_t *aux, ks_component_paths *ap1){
su3_matrix *U_link = aux->U_link;
su3_matrix *V_link = aux->V_link;
load_fatlinks(info, V_link, ap1, U_link);
#ifdef MILC_GLOBAL_DEBUG
#ifdef HISQ_REUNITARIZATION_DEBUG
int i, idir;
complex cdetV;
FORALLSITES_OMP(i,s,private(idir,cdetV))
for(idir=XUP;idir<=TUP;idir++) {
if( lattice[i].on_step_V[idir] < global_current_time_step ) {
lattice[i].on_step_V[idir] = global_current_time_step;
cdetV = det_su3( &(V_link[idir][i]) );
lattice[i].Vdet[idir] = cabs( &cdetV );
}
}
END_LOOP_OMP;
#endif /* HISQ_REUNITARIZATION_DEBUG */
#endif /* MILC_GLOBAL_DEBUG */
}
开发者ID:jcosborn,项目名称:milc_qcd,代码行数:23,代码来源:fermion_links_hisq_load_milc.c
示例18: accumulate
static void accumulate(int const S1[],
int const S2[],
double C4[],
double cr[],
complex double ck[],
fftw_plan dft,
fftw_plan idct)
{
int i;
/* use convolution theorem to compute correlation function */
/* compute the overlap field */
for (i = 0; i < N; i++) cr[i] = (1./N)*S1[i]*S2[i];
/* FT to k-space and square */
fftw_execute(dft);
for (i = 0; i <= N/2; i++) cr[i] = pow(cabs(ck[i]), 2);
/* FT back to real space */
fftw_execute(idct);
for (i = 0; i < N/2; i++) C4[i] += cr[i];
}
开发者ID:mcwitt,项目名称:isg,代码行数:23,代码来源:mod_corr_fft.c
示例19: noise_reduction
//reduce noise using noise buffer
void noise_reduction(){
int k;
float a,b,gain;
for (k=0;k<FFTLEN;k++)
{
P[k]=(1-lpf_weight)*cabs(buffer[k])+lpf_weight*P[k];
switch(gain_sel){
case 1://enhancement4 trial 1
a=lambda*N[k]/cabs(buffer[k]);
b=1-N[k]/cabs(buffer[k]);
break;
case 2:
a=lambda*P[k]/cabs(buffer[k]);
b=1-N[k]/cabs(buffer[k]);
break;
case 3:
a=lambda*N[k]/P[k];
b=1-N[k]/P[k];
break;
case 4:
a=lambda;
b=1-N[k]/P[k];
break;
case 5: //enhancement5
a=lambda;
b=sqrt(1-N[k]*N[k]/cabs(cmul(buffer[k],buffer[k])));
break;
default://no enhancement
a=lambda;
b=1-N[k]/cabs(buffer[k]);
break;
}
gain=a;
if(a<b){
gain=b;
}
buffer[k] = rmul(gain,buffer[k]);
}
ifft(FFTLEN,buffer);
}
开发者ID:hd1812,项目名称:RTDSP-Projects,代码行数:41,代码来源:enhance.c
示例20: pymic_offload_array_abs
PYMIC_KERNEL
void pymic_offload_array_abs(const int64_t *dtype, const int64_t *n,
const void *x_, void *r_) {
/* pymic_offload_array_abs(int dtype, int n,
type *x, type *result) */
size_t i;
switch(*dtype) {
case DTYPE_INT:
{
const int64_t *x = (const int64_t *)x_;
int64_t *r = (int64_t *)r_;
for (i = 0; i < *n; i++) {
r[i] = labs(x[i]);
}
}
break;
case DTYPE_FLOAT:
{
const double *x = (const double *)x_;
double *r = (double *)r_;
for (i = 0; i < *n; i++) {
r[i] = fabs(x[i]);
}
}
break;
case DTYPE_COMPLEX:
{
const double complex *x = (const double complex *)x_;
double *r = (double *)r_;
for (i = 0; i < *n; i++) {
r[i] = cabs(x[i]);
}
}
break;
}
}
开发者ID:seanjensengrey,项目名称:pyMIC,代码行数:36,代码来源:offload_array.c
注:本文中的cabs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论