void ThroughPut::sys_function(){ // (2+i) *(3-i) /* double re,im; mult(2,1,3,-1,&re, &im); qDebug() << " re , im : " << re << im; */ double mat48_1_re[4][8]; double mat48_1_im[4][8]; double mat48_2_re[4][8]; double mat48_2_im[4][8]; double mat48_tmp_re[4][8]; double mat48_tmp_im[4][8]; double mat84_tmp_re[8][4]; double mat84_tmp_im[8][4]; double mat44_tmp_re[4][4] = {0}; double mat44_tmp_im[4][4] = {0}; double mat44_inv_re[4][4]; double mat44_inv_im[4][4]; double w84_re[8][4]; double w84_im[8][4]; double hw44_re[4][4]; double hw44_im[4][4]; /* FILE *fp1,*fp2; fp2 = fopen("data.txt","r"); fp1 = fopen("data2out.txt","w"); for( int i = 0 ; i < 4 ; i++){ for( int j = 0 ; j < 8 ; j++ ){ fscanf(fp2,"%lf",&mat48_1_re[i][j]); } } for( int i = 0 ; i < 4 ; i++){ for( int j = 0 ; j < 8 ; j++ ){ fscanf(fp2,"%lf",&mat48_1_im[i][j]); } } fclose(fp2); */ for( int t = 0 ; t < 3 ; t++){//time for(int f = 0 ; f < 4 ; f ++){//freq // get data t1 for (int i = 0;i<4;i++){ for(int j=0;j<8;j++){ mat48_1_re[i][j]=data1[i*256+j + 64*t + 8*f ][0]; mat48_1_im[i][j]=data1[i*256+j + 64*t + 8*f ][1]; } } // get data t2 for (int i = 0;i<4;i++){ for(int j=0;j<8;j++){ mat48_2_re[i][j]=data1[i*256+j + 64*t+ 64 + 8*f ][0]; mat48_2_im[i][j]=data1[i*256+j + 64*t + 64 + 8*f ][1]; } } hermitian( 4,8,mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im ); Matrix_mult484(mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im, mat44_tmp_re,mat44_tmp_im); chol_inv(mat44_tmp_re,mat44_tmp_im,mat44_inv_re,mat44_inv_im); Matrix_mult844(mat84_tmp_re,mat84_tmp_im, mat44_inv_re,mat44_inv_im, w84_re,w84_im); Matrix_mult484(mat48_2_re,mat48_2_im,w84_re,w84_im,hw44_re,hw44_im); // jiu xiangpian double alpha=0; for (int i=0;i<4;i++){ alpha += 0.25 * atan(hw44_im[i][i]/hw44_re[i][i]); } double hw2_44_re[4][4]; double hw2_44_im[4][4]; for(int i = 0 ; i < 4 ; i++ ){ for( int j = 0 ; j < 4 ; j++ ){ mult(cos(alpha),-sin(alpha),hw44_re[i][j],hw44_im[i][j],&hw2_44_re[i][j],&hw2_44_im[i][j]); } } //get x double x_re[4][1]; double x_im[4][1]; double y41_re[4][1]; double y41_im[4][1]; for( int ip = 0 ; ip < 4 ; ip++ ){ x_re[ip][0] = pilot2[cnt_pilot][0]; x_im[ip][0] = pilot2[cnt_pilot++][1]; if(cnt_pilot == 1200){ cnt_pilot = 0; } } //y = hw*x Matrix_mult441(hw2_44_re,hw2_44_im,x_re,x_im,y41_re,y41_im); /* for( int i = 0 ; i < 4 ; i++ ){ qDebug() << hw2_44_re[i][0] << hw2_44_re[i][1] << hw2_44_re[i][2] << hw2_44_re[i][3] ; }qDebug() << "\n"; */ cnt_allstar1 ++; if( ( (y41_re[0][0] -x_re[0][0] )*(y41_re[0][0] -x_re[0][0]) + (y41_im[0][0] -x_im[0][0])*(y41_im[0][0] -x_im[0][0]) ) >0.5 ){ cnt_err_g1++; } for( int i = 0 ; i < 4 ; i ++ ){ if( ( (y41_re[i][0] -x_re[i][0] )*(y41_re[i][0] -x_re[i][0]) + (y41_im[i][0] -x_im[i][0])*(y41_im[i][0] -x_im[i][0]) ) >0.5 ){ cnt_err_g[i]++; } } if( cnt_allstar1 == 500){ for( int i = 1 ; i <= 4 ; i++ ){ //comp_err_1 = cnt_err_g[i] / cnt_allstar1; comp_err[i] = cnt_err_g[i-1] / cnt_allstar1; height2[i] = -1+ (1-comp_err[i]) ; //height2[i] = -1+ i*0.3 ; } //height2[0] = -1 + ( 1 - cnt_err_g1/cnt_allstar1 ); comp_err[0] = 1- cnt_err_g1/cnt_allstar1; comp_err[5] = comp_err[1]; comp_err[6] = comp_err[2]; height2[5] = height2[1] ; height2[6] = height2[2] ; qDebug() << " comp err : " << cnt_err_g1; qDebug() << " yre : " << y41_re[0][0] << " yim : " << y41_im[0][0] ; qDebug() << " xre : " << x_re[0][0] << " xim : " << x_im[0][0] ; cnt_allstar1 = 0; cnt_err_g1 = 0; cnt_err_g[0] = 0;cnt_err_g[1] =1;cnt_err_g[2] = 0;cnt_err_g[2] = 0;cnt_err_g[3] = 0; } new_star[cnt_newstar][0] = y41_re[0][0]; new_star[cnt_newstar++][1] = y41_im[0][0]; if(cnt_newstar == 120){ cnt_newstar = 0; } } } for( int t = 0 ; t < 3 ; t++){//time for(int f = 0 ; f < 4 ; f ++){//freq // get data t1 for (int i = 0;i<4;i++){ for(int j=0;j<8;j++){ mat48_1_re[i][j]=data1[i*256+j + 64*t + 8*f +32][0];//s1 ue2 mat48_1_im[i][j]=data1[i*256+j + 64*t + 8*f +32][1]; } } // get data t2 for (int i = 0;i<4;i++){ for(int j=0;j<8;j++){ mat48_2_re[i][j]=data1[i*256+j + 64*t+ 64 + 8*f +32][0]; mat48_2_im[i][j]=data1[i*256+j + 64*t + 64 + 8*f +32][1]; } } hermitian( 4,8,mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im ); Matrix_mult484(mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im, mat44_tmp_re,mat44_tmp_im); chol_inv(mat44_tmp_re,mat44_tmp_im,mat44_inv_re,mat44_inv_im); Matrix_mult844(mat84_tmp_re,mat84_tmp_im, mat44_inv_re,mat44_inv_im, w84_re,w84_im); Matrix_mult484(mat48_2_re,mat48_2_im,w84_re,w84_im,hw44_re,hw44_im); // jiu xiangpian double alpha=0; for (int i=0;i<4;i++){ alpha += 0.25 * atan(hw44_im[i][i]/hw44_re[i][i]); } double hw2_44_re[4][4]; double hw2_44_im[4][4]; for(int i = 0 ; i < 4 ; i++ ){ for( int j = 0 ; j < 4 ; j++ ){ mult(cos(alpha),-sin(alpha),hw44_re[i][j],hw44_im[i][j],&hw2_44_re[i][j],&hw2_44_im[i][j]); } } //get x double x_re[4][1]; double x_im[4][1]; double y41_re[4][1]; double y41_im[4][1]; for( int ip = 0 ; ip < 4 ; ip++ ){ x_re[ip][0] = pilot2[cnt_pilot][0]; x_im[ip][0] = pilot2[cnt_pilot++][1]; if(cnt_pilot == 1200){ cnt_pilot = 0; } } //y = hw*x Matrix_mult441(hw2_44_re,hw2_44_im,x_re,x_im,y41_re,y41_im); new_star[cnt_newstar][0] = y41_re[2][0]; new_star[cnt_newstar++][1] = y41_im[2][0]; if(cnt_newstar == 120){ cnt_newstar = 0; } cnt_allstar2 ++; if( ( (y41_re[0][0] -x_re[0][0] )*(y41_re[0][0] -x_re[0][0]) + (y41_im[0][0] -x_im[0][0])*(y41_im[0][0] -x_im[0][0]) ) >0.5 ){ cnt_err_g1++; } for( int i = 2 ; i < 4 ; i ++ ){ if( ( (y41_re[i][0] -x_re[i][0] )*(y41_re[i][0] -x_re[i][0]) + (y41_im[i][0] -x_im[i][0])*(y41_im[i][0] -x_im[i][0]) ) >0.5 ){ cnt_err_g[i+4]++; } } if( cnt_allstar2 == 500){ for( int i = 7 ; i < 9 ; i++ ){ //comp_err_1 = cnt_err_g[i] / cnt_allstar2; comp_err[i] = cnt_err_g[i-1] / cnt_allstar2; height2[i] = -1+ (1-comp_err[i]) ; // height2[i] = -1+ i*0.3 ; } qDebug() << " comp err : " << cnt_err_g1; qDebug() << " yre : " << y41_re[0][0] << " yim : " << y41_im[0][0] ; qDebug() << " xre : " << x_re[0][0] << " xim : " << x_im[0][0] ; cnt_allstar1 = 0; cnt_err_g1 = 0; cnt_err_g[0] = 0;cnt_err_g[1] = 1; } } } #ifdef onetime for (int i = 0;i<4;i++){ for(int j=0;j<8;j++){ mat48_1_re[i][j]=data1[i*256+j][0]; mat48_1_im[i][j]=data1[i*256+j][1]; } } for (int i = 0;i<4;i++){ for(int j=0;j<8;j++){ mat48_2_re[i][j]=data1[i*256+j+64][0]; mat48_2_im[i][j]=data1[i*256+j+64][1]; } } hermitian( 4,8,mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im ); Matrix_mult484(mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im, mat44_tmp_re,mat44_tmp_im); chol_inv(mat44_tmp_re,mat44_tmp_im,mat44_inv_re,mat44_inv_im); Matrix_mult844(mat84_tmp_re,mat84_tmp_im, mat44_inv_re,mat44_inv_im, w84_re,w84_im); Matrix_mult484(mat48_2_re,mat48_2_im,w84_re,w84_im,hw44_re,hw44_im); double x_re[4][1]; double x_im[4][1]; double y41_re[4][1]; double y41_im[4][1]; for( int i = 0 ; i < 4 ; i++ ){ x_re[i][0] = pilot2[i][0]; x_im[i][0] = pilot2[i][1]; } double alpha=0; for (int i=0;i<4;i++){ alpha += 0.25 * atan(hw44_im[i][i]/hw44_re[i][i]); } double hw2_44_re[4][4]; double hw2_44_im[4][4]; for(int i = 0 ; i < 4 ; i++ ){ for( int j = 0 ; j < 4 ; j++ ){ mult(cos(alpha),-sin(alpha),hw44_re[i][j],hw44_im[i][j],&hw2_44_re[i][j],&hw2_44_im[i][j]); } } Matrix_mult441(hw2_44_re,hw2_44_im,x_re,x_im,y41_re,y41_im); /* for( int i = 0 ; i < 4; i++){ for( int j = 0 ; j < 4 ; j++ ){ fprintf(fp1,"%lf\t",hw44_re[i][j]); }fprintf(fp1,"\n"); } for( int i = 0 ; i < 4; i++){ for( int j = 0 ; j < 4 ; j++ ){ fprintf(fp1,"%lf\t",hw44_im[i][j]); }fprintf(fp1,"\n"); } */ for( int i = 0 ; i < 4; i++){ qDebug() << hw44_re[i][0] << hw44_re[i][1] << hw44_re[i][2] << hw44_re[i][3];// << mat48_1_re[i][4] << mat48_1_re[i][5] << mat48_1_re[i][6] << mat48_1_re[i][7]; }qDebug()<<"\n"; for( int i = 0 ; i < 4; i++){ qDebug() << hw44_im[i][0] << hw44_im[i][1] << hw44_im[i][2] << hw44_im[i][3] ;//<< hw44_im[i][4] << mat48_2_re[i][5] << mat48_2_re[i][6] << mat48_2_re[i][7]; }qDebug()<<"\n"; qDebug() << "y re is "<< y41_re[0][0] << y41_re[1][0] << y41_re[2][0] << y41_re[3][0] ; qDebug() << "y im is "<< y41_im[0][0] << y41_im[1][0] << y41_im[2][0] << y41_im[3][0] ; qDebug() << "x re is "<< pilot2[0][0] << pilot2[1][0] << pilot2[2][0] << pilot2[3][0] ; qDebug() << "x im is "<< pilot2[0][1] << pilot2[1][1] << pilot2[2][1] << pilot2[3][1] ; new_star[cnt_newstar][0] = y41_re[1][0]; new_star[cnt_newstar++][1] = y41_im[1][0]; new_star[cnt_newstar][0] = y41_re[0][0]; new_star[cnt_newstar++][1] = y41_im[0][0]; new_star[cnt_newstar][0] = y41_re[2][0]; new_star[cnt_newstar++][1] = y41_im[2][0]; new_star[cnt_newstar][0] = y41_re[3][0]; new_star[cnt_newstar++][1] = y41_im[3][0]; if(cnt_newstar == 60){ cnt_newstar = 0; } #endif /* for( int i = 0 ; i < 4; i++){ qDebug() << mat48_1_re[i][0] << mat48_1_re[i][1] << mat48_1_re[i][2] << mat48_1_re[i][3] << mat48_1_re[i][4] << mat48_1_re[i][5] << mat48_1_re[i][6] << mat48_1_re[i][7]; }qDebug()<<"\n"; for( int i = 0 ; i < 4; i++){ qDebug() << mat48_2_re[i][0] << mat48_2_re[i][1] << mat48_2_re[i][2] << mat48_2_re[i][3] << mat48_2_re[i][4] << mat48_2_re[i][5] << mat48_2_re[i][6] << mat48_2_re[i][7]; }qDebug()<<"\n"; */ //Matrix_mult484(mat48_1_re,mat48_1_im, mat84_tmp_re,mat84_tmp_im, mat44_tmp_re,mat44_tmp_im); /* for( int i = 0 ; i < 4 ; i++){ for( int j = 0 ; j < 4 ; j++){ mat44_tmp_re[i][1] = 1; } } */ }
/* ** Function: verify ** ** The following function verifies that the QR factorization C Kernel ** generated the correct matrices, Q and R, where Q*R=A and Q*Q'=I. ** To test this, we'll look for any values in the resulting matrices of ** abs(A-Q*R) and abs(I-Q*Q') larger than our calculated allowable error. ** ** This function will return 1 if the test passed and 0 if it failed. */ int verify(int rows, int cols, float allowable_error, /* QR kernel input matrix. */ struct ComplexFloat * A, /* Output matrices from the QR kernel. */ struct ComplexFloat * Q, struct ComplexFloat * R) { /* Loop counters, temporaries */ int i, j; float temp; /* Flag to tell whether or not the verification passed. */ int passed = 1; /* Variable to hold the maximum error from each test. */ float max_error = 0.0; /* Pointer for the resulting matrix of Q*R. */ ComplexFloat * Q_x_R; /* Pointer for the resulting matrix of Q'. */ ComplexFloat * Q_herm; /* Pointer for the resulting matrix of Q*Q'. */ ComplexFloat * Q_x_Q_herm; /* Pointer for the identity matrix, I. */ ComplexFloat * I; /* Data pointers for the input and product matrices. */ ComplexFloat *ptr1, *ptr2; /* Allocate memory for our product matrices, Q_x_R and Q_x_herm_Q. */ Q_x_R = (struct ComplexFloat *)malloc(sizeof(struct ComplexFloat)*rows*cols); Q_herm = (struct ComplexFloat *)malloc(sizeof(struct ComplexFloat) *rows*rows); Q_x_Q_herm = (struct ComplexFloat *)malloc(sizeof(struct ComplexFloat) *rows*rows); /* Allocate memory for the identity matrix, I. */ I = (struct ComplexFloat *)malloc(sizeof(struct ComplexFloat)*rows*rows); /* Compute the product Q*R. */ matrix_multiply(rows, rows, cols, Q_x_R, Q, R); /* Compute the matrix Q'. */ hermitian(rows, rows, Q_herm, Q); /* Compute the product Q*Q'. */ matrix_multiply(rows, rows, rows, Q_x_Q_herm, Q, Q_herm); /* Set I to the identity matrix. */ initialize_I(rows, rows, I); /* Verify the correctness of A-Q*R = 0. */ ptr1 = A; ptr2 = Q_x_R; for(i = 0; i < rows; i++) { if(!passed) { break; } for(j = 0; j < cols; j++) { /* Check to see that the absolute value of the difference */ /* between the two current values of our matrices is within our */ /* allowable error. */ temp = sqrt((ptr1->r - ptr2->r)*(ptr1->r - ptr2->r) + (ptr1->i - ptr2->i)*(ptr1->i - ptr2->i)); if(temp > allowable_error) { #ifdef VERBOSE printf("Q*R=A verification failed: Element %d, %d\n", i, j); printf("Error: %f\n", temp); #endif /* The test failed. Return 0. */ passed = 0; break; } /* Record the maximum error from this test. */ else if(temp > max_error) { max_error = temp; } ptr1++; ptr2++; } } #ifdef VERBOSE if(passed) { printf("Maximum error value from A-Q*R test: %f\n", max_error); } #endif /* Verify the correctness of I-Q*Q' = 0. */ max_error = 0.0; ptr1 = I; ptr2 = Q_x_Q_herm; for(i = 0; i < rows; i++) { if(!passed) { break; } for(j = 0; j < rows; j++) { /* Check to see that the absolute value of the difference */ /* between the two current values of our matrices is within our */ /* allowable error. */ temp = sqrt((ptr1->r - ptr2->r)*(ptr1->r - ptr2->r) + (ptr1->i - ptr2->i)*(ptr1->i - ptr2->i)); if(temp > allowable_error) { #ifdef VERBOSE printf("Q*Q'=I verification failed: Element %d, %d\n", i, j); printf("Error: %f\n", temp); #endif /* The test failed. Return 0. */ passed = 0; break; } /* Record the maximum error from this test. */ else if(temp > max_error) { max_error = temp; } ptr1++; ptr2++; } } #ifdef VERBOSE if(passed) { printf("Maximum error value from I-Q*Q' test: %f\n", max_error); } #endif /* Free allocated memory */ free(Q_x_R); free(Q_herm); free(Q_x_Q_herm); free(I); return passed; }