0% found this document useful (0 votes)
107 views2 pages

Shannons Model

This Java class models Shannon's theorem for calculating maximum data rate (MDR) given bandwidth and signal-to-noise ratio (S/N). It contains private variables for bandwidth and S/N, get/set methods for these values, and a method to calculate and return MDR to two decimal places using the bandwidth and S/N values. It overrides the toString method to return a string representation of the object's properties.

Uploaded by

rans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views2 pages

Shannons Model

This Java class models Shannon's theorem for calculating maximum data rate (MDR) given bandwidth and signal-to-noise ratio (S/N). It contains private variables for bandwidth and S/N, get/set methods for these values, and a method to calculate and return MDR to two decimal places using the bandwidth and S/N values. It overrides the toString method to return a string representation of the object's properties.

Uploaded by

rans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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() + "]";
}
}

You might also like