Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
import java.util.Scanner;
import java.util.Arrays;
public class Exceptionintransrecev {
/**
* @param args the command line arguments
*/
while (i<z){
n[i]=(int)(Y.charAt(i));
i++;
int Noise[][]=noisy(BiPolar);
for(int row=0;row<BiPolar.length;row++){
System.out.print("Noisy added packet: [");
for(int col=0;col<BiPolar[0].length;col++){
System.out.print(Noise[row][col]+" ");
}
System.out.print("]");
System.out.println();
int error[][]=Error(BiPolarDem);
for (int Z=0;Z<BiPolarDem.length;Z++){
if(error[Z][0]==0){
System.out.print("Packet "+Z+": No error");
}
else{
System.out.print("Packet "+Z+": error");
}
System.out.println();
}
System.out.print(P[y]+" ");
}
System.out.print("]");
System.out.println();
int Numbiterror=0;
double Bit;
for(int y=0;y<N.length;y++){
if(N[y]!=P[y]){
Numbiterror=Numbiterror+1;
}
}
char []Z;
Z=new char[7];
Bit=N.length/Numbiterror;
double BER;
BER=1/Bit;
System.out.print("BER: ");
System.out.println(BER);
int count=0;
for(int m=0;m<7;m++){
if(Z[m]!=Y.charAt(m)){
count=count+1;
}
}
double V1,CER;
V1=7/count;
CER=1/V1;
System.out.print("CER: ");
System.out.println(CER);
System.out.println();
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBounds occurs");
System.out.println("Length of characters should be equal to 7");
System.exit(0);
}
}
public static int[] Chartobits(int[]n){
int j; int k; int con; int m;int fillN; int endOfBit = -7;
int []Bin= new int [7];
int X;
int N[]= new int [49];
con=((k%2)==0? 0 : 1);
k=k/2;
Bin[m]=con;
}
}
endOfBit+=7;
for (X=6,fillN=(endOfBit); X>=0 ;X--,fillN++){
//System.out.print(Bin[X]);
N[fillN]=Bin[X];
}
//System.out.println();
}
return(N);
}
public static int[][] Packetize(int N[]){
int F; int R; int i;
if (F<=0){
while (F<=0){
System.out.println("Packet size cannot be negative, re-enter packet
size");
F= inputPacketize.nextInt();
}
}
if((N.length)%F==0){
R= ((N.length)/F);
}
else{
R= (((N.length)/F)+1);
}
int pack[][]= new int [R][F];
for (int count=0; count<(N.length);count++){
}
}
return (pack);
if(Parry[i][j]==0){
BiPolar[i][j]= -1;
}
else{
BiPolar[i][j]= 1;}
try{
if (BiPolar[i][j]!=1 && BiPolar[i][j]!=-1)
throw new IllegalArgumentException ("Bipolar modulated
data can take only -1 or +1");
catch(IllegalArgumentException e){
System.out.println("IllegalArgumentException occurs");
System.exit(0);
}
}
}
return(BiPolar);
}
public static int[][]noisy(int BiPolar[][]){
int W=BiPolar[0].length;
int[]m= new int[BiPolar.length];
for(int w=0;w<BiPolar.length;w++){
Scanner stdin=new Scanner(System.in);
try{
System.out.print("Enter the level of noise: ");
m[w]=stdin.nextInt();
if (m[w]>4)
throw new ArrayIndexOutOfBoundsException ("Maximum amplitude of noisy
corrupted data should be less than 5");
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println(e);
System.exit(0);
}
double[]r;
r=new double[55];
if(m[2]<=1){
for(int u=0;u<W;u++){
r[u]=(Math.random() * 1.2* (Math.random() > 0.5 ? 1 : -1));
}}
if(m[3]>=2){for(int u=0;u<W;u++){
r[u] = (Math.random() * 1.6* (Math.random() > 0.5 ? 1 : -1));
}}
else{for(int u=0;u<W;u++){
r[u] =(Math.random() * 2.0* (Math.random() > 0.5 ? 1 : -1));
}
}
int E=(BiPolar.length);
int T=(BiPolar[0].length);
}
}
return(Noisy);
}
}
return(Bipolardem);
}
public static int[][]Error(int Bipolardem[][]){
int X=Bipolardem.length;int B;
int Z=Bipolardem[0].length;
int error[][]=new int[X][1];
for(int k=0;k<X;k++){
int sum1=0;
for(int n=0;n<Z;n++){
B=Bipolardem[k][n];
sum1+=B;
}
error[k][0]=sum1%2;
}
return(error);
}
}
return(Remparry);
}
public static int[] bitstreams (int Remparry[][]){
int T=(Remparry[0].length);
int R=(Remparry.length);
int P[]=new int [50];
int y;
for( y=0;y<50;y++){
for(int i=0;i<R;i++){
for(int j=0;j<T;j++){
P[y]=Remparry[i][j];
y++;
}
}
}
return(P);
}
}