void remove_noise(int mplgs,struct complex *acf, struct complex *ncf) { int i; double pa, plim; plim = lag_power(&ncf[0]); pa = lag_power(&acf[0]); if( pa > plim ) for (i=0; i < mplgs; i++) { acf[i].x -= ncf[i].x; acf[i].y -= ncf[i].y; } else for (i=0; i < mplgs; i++) { acf[i].x = 0; acf[i].y = 0; } return; }
double noise_stat(double mnpwr,struct FitPrm *ptr, struct FitACFBadSample *badsmp, struct complex *acf[MAX_RANGE]) { /* double *signal) { */ double plim; int i, j, np0, npt; int bdlag[LAG_SIZE]; double var, sigma, P, P2; double temp, fluct, low_lim, high_lim; plim = PLIM * mnpwr; P = 0.0; P2 = 0.0; var = 0.0; np0 = 0; npt = 0; for (i=0; i < ptr->nrang; ++i) { if ((acf[i][0].x > plim) || (acf[i][0].x <= 0.0)) continue; FitACFCkRng((i+1), bdlag,badsmp, ptr); ++np0; fluct = ((double) acf[i][0].x)/sqrt(ptr->nave); low_lim = acf[i][0].x - 2.0*fluct; if (low_lim < 0) low_lim = low_lim + fluct; high_lim = acf[i][0].x + fluct; for (j=1; j < ptr->mplgs; ++j) { if (bdlag[j]) continue; temp = lag_power(&acf[i][j]); if (temp < low_lim || temp > high_lim) continue; ++npt; P = P + temp; P2 = P2 + temp*temp; } } if (npt < 2) { /* *signal = 0; */ return plim/sqrt((double) ptr->nave); } P = P/npt; var = (P2 - P*P*npt)/((double) (npt-1)); sigma = (var > 0.0) ? sqrt(var) : 0.0; /*if ((P >= sigma * ROOT_3) && (sigma > 0.0)) *signal = P; else *signal = 0.0; */ return (P > sigma) ? P : sigma; }
double noise_acf(double mnpwr,struct FitPrm *ptr, double *pwr, struct FitACFBadSample *badsmp, struct complex *raw, struct complex *n_acf) { int i, j; int *np=NULL; int *bad=NULL; double plim, P; np=malloc(sizeof(int)*ptr->mplgs); if (np==NULL) return -1; memset(np,0,sizeof(int)*ptr->mplgs); bad=malloc(sizeof(int)*ptr->bad); if (bad==NULL) { free(np); return -1; } memset(bad,0,sizeof(int)*ptr->mplgs); for (i=0; i< ptr->mplgs; i++) { n_acf[i].x = 0; n_acf[i].y= 0; np[i] = 0; } plim = PLIM * mnpwr; for (i=0; i< ptr->nrang; i++) { if ((pwr[i] < plim) && ((fabs(raw[i*ptr->mplgs].x) + fabs(raw[i*ptr->mplgs].y)) > 0) && (fabs(raw[i*ptr->mplgs].x) < plim) && (fabs(raw[i*ptr->mplgs].y) < plim)) { FitACFCkRng((i+1), bad,badsmp, ptr); for (j=0; j< ptr->mplgs; j++) { if ((fabs(raw[i*ptr->mplgs+j].x) < plim) && (fabs(raw[i*ptr->mplgs+j].y) < plim) && (bad[j] == 0)) { n_acf[j].x = n_acf[j].x + raw[i*ptr->mplgs+j].x; n_acf[j].y = n_acf[j].y + raw[i*ptr->mplgs+j].y; ++(np[j]); } } } } if (np[0] <= 2) { for (i=0; i < ptr->mplgs; ++i) { n_acf[i].x = 0; n_acf[i].y = 0; } return 0.0; } for (i=0; i< ptr->mplgs; i++) { if (np[i] > 2) { n_acf[i].x = n_acf[i].x/np[i]; n_acf[i].y = n_acf[i].y/np[i]; } else { n_acf[i].x = 0; n_acf[i].y= 0; } } /* Now determine the average power in the non-zero lags of the noise acf */ for (i=1, P=0; i < ptr->mplgs; ++i) { P = P + lag_power(&n_acf[i]); } P = P/(ptr->mplgs - 1); return P; }