Sunteți pe pagina 1din 2

package network;

/**
* model of Shannon's Theorem
*/
public class ShannonsModel{

//this is an optional variable for precision


private static final double PRECISION = 100d;

private double bandwidth;


private double signalToNoise;

/**
* create an object of ShannonsTheorem with bandwidth and S/N set to zero
*/
public ShannonsModel(){
bandwidth = 0;
signalToNoise = 0;
}

/**
* get value of bandwidth
* @return value of bandwidth
*/
public double getBandwidth(){
return bandwidth;
}

/**
* set the value of bandwidth, this value cannot be smaller than 0
* @param bandwidth - positive double
* @throws IllegalArgumentException if bandwidth is a negative number
*/
public void setBandwidth( double bandwith){
if( bandwith < 0){
throw new IllegalArgumentException( "ERROR - Bandwidth must be a positive
integer");
}
this.bandwidth = bandwith;
}

/**
* get value of S/N
* @return value of S/N
*/
public double getSignalToNoise(){
return signalToNoise;
}

/**
* set the value of S/N, this value cannot be smaller than 0
* @param signalToNoise - positive double
* @throws IllegalArgumentException if signalToNoise is a negative number
*/
public void setSignalToNoise( double signalToNoise) throws
IllegalArgumentException{
if( signalToNoise < 0){
throw new IllegalArgumentException( "ERROR - S/N must be a positive integer");
}
this.signalToNoise = signalToNoise;
}

/**
* calculate maximum data rate given bandwidth and S/N to two decimal places
* @return calculate maximum data rate to two decimal places
*/
public double getMaximumDataRate(){
double mdr = getMaximumDataRate( getBandwidth(), getSignalToNoise());
//before rounding check if number infinite
if( Double.isInfinite( mdr)){
return Double.POSITIVE_INFINITY;
}
return Math.round( mdr * PRECISION) / PRECISION;
}

/**
* calculate maximum data rate given bandwidth and S/N
* @param bandwidth - number of type double
* @param signalToNoise - number of type double
* @return calculated maximum data rate
*/
private double getMaximumDataRate( double bandwidth, double signalToNoise){
//10 to the power of any number bigger than 308.254715 is infinite
//so any value for signalToNoise that is 3082.54715 will return INFINITY
//the value for signalToNoise is bigger than 308.254715 because it gets divided by
10
return bandwidth * (Math.log( (Math.pow( 10, (signalToNoise / 10)) + 1)) /
Math.log( 2));
}

/**
* create a string representation of ShannnosTheorem Object in following format
* ex: "[Bandwidth=2, S/N=2, MDR=2.74]"
* @return string format of this object
*/
public String toString(){
return "[Bandwidth=" + bandwidth + ", S/N=" + signalToNoise + ", MDR=" +
getMaximumDataRate() + "]";
}
}

S-ar putea să vă placă și