Example #1
0
void generate_y (){

    int i;
    for (i=0; i<N_DATA; i++){
        y[i]=(double)x[i] + nrnd();
    }

}
Example #2
0
/*
 * perform one iteration of decay
 */
static unsigned long
decayscreen_draw (Display *dpy, Window window, void *closure)
{
    struct state *st = (struct state *) closure;
    int left, top, width, height, toleft, totop;

#define L 101
#define R 102
#define U 103
#define D 104
    static const int no_bias[]        = { L,L,L,L, R,R,R,R, U,U,U,U, D,D,D,D };
    static const int up_bias[]        = { L,L,L,L, R,R,R,R, U,U,U,U, U,U,D,D };
    static const int down_bias[]      = { L,L,L,L, R,R,R,R, U,U,D,D, D,D,D,D };
    static const int left_bias[]      = { L,L,L,L, L,L,R,R, U,U,U,U, D,D,D,D };
    static const int right_bias[]     = { L,L,R,R, R,R,R,R, U,U,U,U, D,D,D,D };

    static const int upleft_bias[]    = { L,L,L,L, L,R,R,R, U,U,U,U, U,D,D,D };
    static const int downleft_bias[]  = { L,L,L,L, L,R,R,R, U,U,U,D, D,D,D,D };
    static const int upright_bias[]   = { L,L,L,R, R,R,R,R, U,U,U,U, U,D,D,D };
    static const int downright_bias[] = { L,L,L,R, R,R,R,R, U,U,U,D, D,D,D,D };

    if (st->img_loader)   /* still loading */
      {
        st->img_loader = load_image_async_simple (st->img_loader, 
                                                  0, 0, 0, 0, 0);
        if (! st->img_loader) {  /* just finished */
          if (st->mode == MELT || st->mode == STRETCH)
            /* make sure screen eventually turns background color */
            XDrawLine (st->dpy, st->window, st->gc, 0, 0, st->sizex, 0); 
        }
      return st->delay;
    }

    switch (st->mode) {
      case SHUFFLE:	st->current_bias = no_bias; break;
      case UP:		st->current_bias = up_bias; break;
      case LEFT:	st->current_bias = left_bias; break;
      case RIGHT:	st->current_bias = right_bias; break;
      case DOWN:	st->current_bias = down_bias; break;
      case UPLEFT:	st->current_bias = upleft_bias; break;
      case DOWNLEFT:	st->current_bias = downleft_bias; break;
      case UPRIGHT:	st->current_bias = upright_bias; break;
      case DOWNRIGHT:	st->current_bias = downright_bias; break;
      case IN:		st->current_bias = no_bias; break;
      case OUT:		st->current_bias = no_bias; break;
      case MELT:	st->current_bias = no_bias; break;
      case STRETCH:	st->current_bias = no_bias; break;
      case FUZZ:	st->current_bias = no_bias; break;
     default: abort();
    }

#define nrnd(x) ((x) ? random() % (x) : x)

    if (st->mode == MELT || st->mode == STRETCH) {
      left = nrnd(st->sizex/2);
      top = nrnd(st->sizey);
      width = nrnd( st->sizex/2 ) + st->sizex/2 - left;
      height = nrnd(st->sizey - top);
      toleft = left;
      totop = top+1;

    } else if (st->mode == FUZZ) {  /* By Vince Levey <*****@*****.**>;
                                   inspired by the "melt" mode of the
                                   "scrhack" IrisGL program by Paul Haeberli
                                   circa 1991. */
      left = nrnd(st->sizex - 1);
      top  = nrnd(st->sizey - 1);
      st->fuzz_toggle = !st->fuzz_toggle;
      if (st->fuzz_toggle)
        {
          totop = top;
          height = 1;
          toleft = nrnd(st->sizex - 1);
          if (toleft > left)
            {
              width = toleft-left;
              toleft = left;
              left++;
            }
          else
            {
              width = left-toleft;
              left = toleft;
              toleft++;
            }
        }
      else
        {
          toleft = left;
          width = 1;
          totop  = nrnd(st->sizey - 1);
          if (totop > top)
            {
              height = totop-top;
              totop = top;
              top++;
            }
          else
            {
              height = top-totop;
              top = totop;
              totop++;
            }
        }

    } else {

      left = nrnd(st->sizex - 1);
      top = nrnd(st->sizey);
      width = nrnd(st->sizex - left);
      height = nrnd(st->sizey - top);
      
      toleft = left;
      totop = top;
      if (st->mode == IN || st->mode == OUT) {
	int x = left+(width/2);
	int y = top+(height/2);
	int cx = st->sizex/2;
	int cy = st->sizey/2;
	if (st->mode == IN) {
	  if      (x > cx && y > cy)   st->current_bias = upleft_bias;
	  else if (x < cx && y > cy)   st->current_bias = upright_bias;
	  else if (x < cx && y < cy)   st->current_bias = downright_bias;
	  else /* (x > cx && y < cy)*/ st->current_bias = downleft_bias;
	} else {
	  if      (x > cx && y > cy)   st->current_bias = downright_bias;
	  else if (x < cx && y > cy)   st->current_bias = downleft_bias;
	  else if (x < cx && y < cy)   st->current_bias = upleft_bias;
	  else /* (x > cx && y < cy)*/ st->current_bias = upright_bias;
	}
      }
      
      switch (st->current_bias[random() % (sizeof(no_bias)/sizeof(*no_bias))]) {
      case L: toleft = left-1; break;
      case R: toleft = left+1; break;
      case U: totop = top-1; break;
      case D: totop = top+1; break;
      default: abort(); break;
      }
    }
    
    if (st->mode == STRETCH) {
      XCopyArea (st->dpy, st->window, st->window, st->gc, 0, st->sizey-top-2, st->sizex, top+1, 
		 0, st->sizey-top-1); 
    } else {
      XCopyArea (st->dpy, st->window, st->window, st->gc, left, top, width, height,
		 toleft, totop);
    }

#undef nrnd

    return st->delay;
}
void main() {
	double* MyData = (double*)calloc(CODE_LENGTH, sizeof(double));		// 自局データ
	double* OtherData = (double*)calloc(CODE_LENGTH, sizeof(double));	// 他局データ
	double MyPn[CODE_LENGTH] =  {-1,1,1,1,-1,1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,-1,-1,1,-1,-1,1,-1,-1,1,1,-1,-1,1};
	double OtherPn[CODE_LENGTH] = {1,1,-1,-1,-1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,1,1,-1,1,1,-1,-1,1,-1,1,-1,1,1,1,-1,1};

	double* TransmitMyData =  (double*)calloc(CODE_LENGTH, sizeof(double)); 	// 自局送信データ
	double* TransmitOtherData = (double*)calloc(CODE_LENGTH, sizeof(double)); 	// 他局送信データ

	double* ReceiveData = (double*)calloc(CODE_LENGTH, sizeof(double));			// 受信信号データ
	double* SubtractData = (double*)calloc(CODE_LENGTH, sizeof(double));		// 減算データ

	double* RegenerateMyData = (double*)calloc(CODE_LENGTH, sizeof(double));		// 自局再生による自局復調データ
	double* RegenerateOtherData = (double*)calloc(CODE_LENGTH, sizeof(double));		// 他局再生による他局復調データ

	double* OutputData = (double*)calloc(CODE_LENGTH, sizeof(double));			// 出力信号データ

	//double* MySuccessData = (double*)calloc(CODE_LENGTH, sizeof(double));			// [自局]減算成功データ
	//double* OtherSuccessData = (double*)calloc(CODE_LENGTH, sizeof(double));		// [他局]減算成功データ

	int i, j, k;
	unsigned long n, nn=0;
	double en, pebs;
	double end[P] = {0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0};
	double en2 = pow(10.0, SIR/10.0);

	double* flag = (double*)calloc(CODE_LENGTH, sizeof(double));		// 干渉除去が成功しているかのフラグ
	
	seed = (unsigned long)time(NULL);

	//自局データの作成
	for(i=0 ; i<CODE_LENGTH ; i++){
		MyData[i] = 1.0;
	}

	//BER特性の導出
	for(i=0 ; i<P ; i++){
		en = pow(10.0, end[i]/10.0);

		for(j=n=0 ; j<N; j++){

			//自局送信データの作成
			MakeMyData(MyData, MyPn, TransmitMyData);

			for(k=0 ; k<CODE_LENGTH ; k++){	
				if(rnd()>0.5){
					OtherData[k] = 1.0;
				}else{
					OtherData[k] = -1.0;
				}
			}

			MakeOtherData(OtherData, OtherPn, TransmitOtherData);

			//受信信号の作成
			for(k=0 ; k<CODE_LENGTH ; k++){
				ReceiveData[k] = TransmitMyData[k] + (TransmitOtherData[k] / sqrt(en2)) + nrnd(0, sqrt((CODE_LENGTH)/(2.0*en)));
			}

			//他局信号の再生
			RegenerationOtherData(ReceiveData, OtherPn, RegenerateOtherData);

			for(k=0 ; k<CODE_LENGTH ; k++){
				SubtractData[k] = ReceiveData[k] - (RegenerateOtherData[k] / sqrt(en2));
			}

			//自局1回目判定
			Demodulation(SubtractData, MyPn, OutputData);

			//自局信号の再生
			MakeMyData(OutputData, MyPn, RegenerateMyData);

			for(k=0 ; k<CODE_LENGTH ; k++){
				SubtractData[k] = ReceiveData[k] - RegenerateMyData[k];
			}

			//他局1回目判定
			Demodulation2(SubtractData, OtherPn, OutputData);

			/* 2回目 */

			//他局信号の再生
			MakeOtherData(OutputData, OtherPn, RegenerateOtherData);

			/*for(k=0 ; k<CODE_LENGTH ; k++){
				printf("%lf\n", RegenerateOtherData[k]/sqrt(32));
			}*/


			//3値判定
			for(k=0 ; k<CODE_LENGTH ; k++){
				if(RegenerateOtherData[k] > sqrt(CODE_LENGTH)){
					SubtractData[k] = ReceiveData[k] - (RegenerateOtherData[k]/sqrt(en2));
					flag[k] = 0.0;
				}else if(RegenerateOtherData[k] < -sqrt(CODE_LENGTH)){
					SubtractData[k] = ReceiveData[k] - (RegenerateOtherData[k]/sqrt(en2));
					flag[k] = 0.0;
				}else{
					SubtractData[k] = ReceiveData[k];
					flag[k] = 1.0;
				}
			}

			//flag=0の部分に関しては2倍引くか足す
			/*for(k=0 ; k<CODE_LENGTH ; k++){
				if(flag[k] == 0){
					if(SubtractData[k] >= 1/pow(10.0, SIRVTH/10.0)){
						SubtractData[k] -= 2 * 1/sqrt(en2);
					}else if(SubtractData[k] <= -1/pow(10.0, SIRVTH/10.0)){
						SubtractData[k] += 2 * 1/sqrt(en2);
					}else{

					}
				}else{

				}
			}*/

			//自局2回目判定
			Demodulation(SubtractData, MyPn, OutputData);

			for(k=0; k<CODE_LENGTH ; k++){
				if(OutputData[k] != MyData[k]){
					n++;
				}
			}
		}

		pebs = (double)n / (double)(N*32);

		printf("Error = %d\n", n);
		printf("All = %d\n", N*32);
		printf("%9.6f\t%15.6e\n\n", end[i], pebs);
	}
		//printf("%d\n", nn/N);

	free(MyData);
	free(OtherData);
	free(TransmitMyData);
	free(TransmitOtherData);
	free(ReceiveData);
	free(SubtractData);
	free(RegenerateMyData);
	free(RegenerateOtherData);
	free(OutputData);
}