/* This function "order0_dec" written by Marc Fossorier performs order-0 decoding as described by him in his paper. "Gg_t" is the two-dimensional integer array containing the generator matrix of the code. "R" is the length "N" double-valued received vector containing the received real numbers. "out_D" is the result of order-0 decoding. */ # include "def3.h" void order0_dec3(Gg_t,R,out_D) int Gg_t[K3][N]; double R[N],out_D[N]; { double abs_R[N],C[N][2]; int Dd[N],DD[N],GG[K3][N],i,j,Gg[K3][N]; int permutation_final[N],permutation_I[K3],permutation_R[N]; double zero[K3],fabs(); void peterson_I_03(),quick_sort_track_03(); void switch_column_I_03(); void switch_vector_03(),switch_matrix_03(); for (i=0;i < K3;i++) for (j=0;j < N;j++) Gg[i][j] = Gg_t[i][j]; for (i=0;i < N;i++) { abs_R[i] = (double) fabs((double) R[i]); if (i < K3) { permutation_I[i] = i; } permutation_R[i] = i; } quick_sort_track_03(abs_R,permutation_R,0,N-1); /* Note that the permutations returned by qs are from small to big ! */ /* Move the K3 independent most informative symbols to the front */ /* Column operations => Changes the code into an equivalent code */ switch_vector_03(R,permutation_R,N-1); switch_matrix_03(Gg,permutation_R,K3-1,N-1); /* Put into systematic code */ /* Row operations => keeps the code */ peterson_I_03(Gg,zero); /* Obtain the K3 columns of I */ quick_sort_track_03(zero,permutation_I,0,K3-1); /* Switch the rows to obtain the K3 I_rows in the right order => keeps the code */ for (i=0; i changes the code */ switch_column_I_03(GG,Gg,R,permutation_R,permutation_final); /* Compute 2N costs and K3 most probable bits */ for (i=0; i start) /* Unchanged part */ { for(j=0; j 0) /* Copy from R to L dependent columns found in first positions */ { temp[i] = R[i]; for(j=0; j 0) /* Copy I_columns */ { temp[i] = R[i]; for(j=0; j i) /* data not overwritten */ { R[i] = R[permutation[length-i]]; } else { R[i] = temp[permutation[length-i]]; /* data overwritten but stored in temp */ } } } void switch_matrix_03(Gg,permutation,k,n) int Gg[K3][N]; int permutation[]; int k,n; { int i,j; double temp[K3][N]; for (j=0;j<=n;j++) { for (i=0; i<=k; i++) { temp[i][j] = Gg[i][j]; if (permutation[n-j] > j) /* column not overwritten */ { Gg[i][j] = Gg[i][permutation[n-j]]; } else { Gg[i][j] = temp[i][permutation[n-j]]; /* data overwritten but stored in temp */ } } } } void peterson_I_03(Gg,zero) int Gg[K3][N]; double zero[N]; { int i,j,l,m; for (i=0; i left) { ref_val = vals [right]; for(;;) { /* while element smaller than reference value, move left wall upwards */ while (vals [++ascending] < ref_val); /* while element larger than reference value, move right wall downwards */ while (vals [--descending] > ref_val); if (ascending >= descending) break; /* if the walls have not passed each other, exchange values (if not access to function need to save index) */ temp=vals[ascending]; temp2=permutation[ascending]; vals[ascending]=vals[descending]; vals[descending]=temp; permutation[ascending]=permutation[descending]; permutation[descending]=temp2; } temp=vals[ascending]; temp2=permutation[ascending]; vals[ascending]=vals[right]; vals[right]=temp; permutation[ascending]=permutation[right]; permutation[right]=temp2; /* if descending wall has not yet reached left partition, call quick-sort again with this smaller array */ quick_sort_track_03( vals, permutation, left, ascending-1); /* if ascending wall has not yet reached right partition, call quick-sort again with this smaller array */ quick_sort_track_03( vals, permutation, ascending+1, right); } }