Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.33 KB | None | 0 0
  1. ================== SHANNONSTHEOREM ============================
  2. package network;
  3.  
  4. import javax.swing.JOptionPane;
  5.  
  6. /**
  7.  *
  8.  * @author Houle
  9.  *
  10.  */
  11. public class ShannonsThreorem {
  12.  
  13. //  private double bandwidth; //initializing  bandwidth
  14.     //private double signalToNoise; //initializing signaltonoise
  15.     private ShannonsModel test;
  16.     /** the constructor
  17.      */
  18.     public ShannonsThreorem(){ //constructor
  19.         super();
  20.     }
  21.  
  22.     /** this sets private bandwidth to public h to protect bandwidth
  23.      * @param h
  24.      */
  25.     public void setBandwidth(double h){ //setting h to the value of bandwidth
  26.         test.setBandwidth(h);
  27.     }
  28.  
  29.     /**
  30.      * this sets signaltonoise to snr to protect signaltonoise
  31.      * @param snr
  32.      */
  33.     public void setSignalToNoise(double snr){ //setting snr to the value of signal to noise
  34.         test.setSignalToNoise(snr);
  35.     }
  36.  
  37.     /**
  38.      *  this is shannon's theorem. This is where the the mathematic foruma is run
  39.      * @param bandwidth
  40.      * @param signalToNoise
  41.      * @return
  42.      */
  43.     private double getMaximumDataRate(double bandwidth, double signalToNoise){ //Shannon's theorem
  44.         return (getBandwidth()*Math.log(1+Math.pow(10, getSignalToNoise()/10))/Math.log(2));
  45.     }
  46.  
  47.     /**
  48.      * this grabs a copy of the bandwidth and signal to noise for use in the theorem
  49.      * @return
  50.      */
  51.     public double getMaximumDataRate(){ //getting bandwidth and signaltonoise and putting them in for the Shannon theorem
  52.         return getMaximumDataRate(test.getBandwidth(), test.getSignalToNoise());
  53.     }
  54.  
  55.     /**
  56.      * getBandwidth returns a copy of bandwidth
  57.      * @return
  58.      */
  59.     public double getBandwidth(){ //returning a copy of bandwidth
  60.         return test.getBandwidth();
  61.     }
  62.  
  63.     /**
  64.      * getsignaltonoise gets a copy of signaltonoise
  65.      * @return
  66.      */
  67.     public double getSignalToNoise(){ //returning a copy of signal to noise
  68.         return test.getSignalToNoise();
  69.     }
  70.  
  71.     /**
  72.      * the toString is what will be called instead of the original class toString value
  73.      */
  74.     public String toString(){ //setting a toString value
  75.         return ("Bandwidth is " + getBandwidth() + "Signal to noise is " + getSignalToNoise() + "The maximum data rate is " + getMaximumDataRate());
  76.     }
  77.  
  78.     /**
  79.      * this sets the Joptionpanes to grab information from the user and display it in dialog boxes
  80.      * @param args
  81.      */
  82.     public static void main(String[] args) { //MAIN with option panes to request values
  83.         ShannonsThreorem app = new ShannonsThreorem();
  84.         app.setBandwidth(Double.parseDouble(JOptionPane.showInputDialog("Enter the bandwidth")));
  85.         app.setSignalToNoise(Double.parseDouble(JOptionPane.showInputDialog("Enter signal to noise")));
  86.         JOptionPane.showMessageDialog(null, "Max data rate is " + app.getMaximumDataRate());  //the first value is null because I don't want to add this to a frame
  87.     }
  88.  
  89. }
  90.  
  91.  
  92. ============= SHANNONS MODEL =====================
  93. package network;
  94.  
  95. import javax.swing.JOptionPane;
  96.  
  97. public class ShannonsModel {
  98.     private double bandwidth; //initializing  bandwidth
  99.     private double signalToNoise; //initializing signaltonoise
  100.  
  101.     /** the constructor
  102.      */
  103.     public ShannonsModel(){ //constructor
  104.         super();
  105.     }
  106.  
  107.     /** this sets private bandwidth to public h to protect bandwidth
  108.      * @param h
  109.      */
  110.     public void setBandwidth(double h){ //setting h to the value of bandwidth
  111.         bandwidth = h;
  112.     }
  113.  
  114.     /**
  115.      * this sets signaltonoise to snr to protect signaltonoise
  116.      * @param snr
  117.      */
  118.     public void setSignalToNoise(double snr){ //setting snr to the value of signal to noise
  119.         signalToNoise = snr;
  120.     }
  121.  
  122.     /**
  123.      *  this is shannon's theorem. This is where the the mathematic foruma is run
  124.      * @param bandwidth
  125.      * @param signalToNoise
  126.      * @return
  127.      */
  128.     private double getMaximumDataRate(double bandwidth, double signalToNoise){ //Shannon's theorem
  129.         return (bandwidth*Math.log(1+Math.pow(10, signalToNoise/10))/Math.log(2));
  130.     }
  131.  
  132.     /**
  133.      * this grabs a copy of the bandwidth and signal to noise for use in the theorem
  134.      * @return
  135.      */
  136.     public double getMaximumDataRate(){ //getting bandwidth and signaltonoise and putting them in for the Shannon theorem
  137.         return getMaximumDataRate(getBandwidth(), getSignalToNoise());
  138.     }
  139.  
  140.     /**
  141.      * getBandwidth returns a copy of bandwidth
  142.      * @return
  143.      */
  144.     public double getBandwidth(){ //returning a copy of bandwidth
  145.         return bandwidth;
  146.     }
  147.  
  148.     /**
  149.      * getsignaltonoise gets a copy of signaltonoise
  150.      * @return
  151.      */
  152.     public double getSignalToNoise(){ //returning a copy of signal to noise
  153.         return signalToNoise;
  154.     }
  155.  
  156.     /**
  157.      * the toString is what will be called instead of the original class toString value
  158.      */
  159.     public String toString(){ //setting a toString value
  160.         return ("Bandwidth is " + getBandwidth() + "Signal to noise is " + getSignalToNoise() + "The maximum data rate is " + getMaximumDataRate());
  161.     }
  162.  
  163.     /**
  164.      * this sets the Joptionpanes to grab information from the user and display it in dialog boxes
  165.      * @param args
  166.      */
  167.     public static void main(String[] args) { //MAIN with option panes to request values
  168.         ShannonsThreorem app = new ShannonsThreorem();
  169.         app.setBandwidth(Double.parseDouble(JOptionPane.showInputDialog("Enter the bandwidth")));
  170.         app.setSignalToNoise(Double.parseDouble(JOptionPane.showInputDialog("Enter signal to noise")));
  171.         JOptionPane.showMessageDialog(null, "Max data rate is " + app.getMaximumDataRate());  //the first value is null because I don't want to add this to a frame
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement