Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ================== SHANNONSTHEOREM ============================
- package network;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Houle
- *
- */
- public class ShannonsThreorem {
- // private double bandwidth; //initializing bandwidth
- //private double signalToNoise; //initializing signaltonoise
- private ShannonsModel test;
- /** the constructor
- */
- public ShannonsThreorem(){ //constructor
- super();
- }
- /** this sets private bandwidth to public h to protect bandwidth
- * @param h
- */
- public void setBandwidth(double h){ //setting h to the value of bandwidth
- test.setBandwidth(h);
- }
- /**
- * this sets signaltonoise to snr to protect signaltonoise
- * @param snr
- */
- public void setSignalToNoise(double snr){ //setting snr to the value of signal to noise
- test.setSignalToNoise(snr);
- }
- /**
- * this is shannon's theorem. This is where the the mathematic foruma is run
- * @param bandwidth
- * @param signalToNoise
- * @return
- */
- private double getMaximumDataRate(double bandwidth, double signalToNoise){ //Shannon's theorem
- return (getBandwidth()*Math.log(1+Math.pow(10, getSignalToNoise()/10))/Math.log(2));
- }
- /**
- * this grabs a copy of the bandwidth and signal to noise for use in the theorem
- * @return
- */
- public double getMaximumDataRate(){ //getting bandwidth and signaltonoise and putting them in for the Shannon theorem
- return getMaximumDataRate(test.getBandwidth(), test.getSignalToNoise());
- }
- /**
- * getBandwidth returns a copy of bandwidth
- * @return
- */
- public double getBandwidth(){ //returning a copy of bandwidth
- return test.getBandwidth();
- }
- /**
- * getsignaltonoise gets a copy of signaltonoise
- * @return
- */
- public double getSignalToNoise(){ //returning a copy of signal to noise
- return test.getSignalToNoise();
- }
- /**
- * the toString is what will be called instead of the original class toString value
- */
- public String toString(){ //setting a toString value
- return ("Bandwidth is " + getBandwidth() + "Signal to noise is " + getSignalToNoise() + "The maximum data rate is " + getMaximumDataRate());
- }
- /**
- * this sets the Joptionpanes to grab information from the user and display it in dialog boxes
- * @param args
- */
- public static void main(String[] args) { //MAIN with option panes to request values
- ShannonsThreorem app = new ShannonsThreorem();
- app.setBandwidth(Double.parseDouble(JOptionPane.showInputDialog("Enter the bandwidth")));
- app.setSignalToNoise(Double.parseDouble(JOptionPane.showInputDialog("Enter signal to noise")));
- 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
- }
- }
- ============= SHANNONS MODEL =====================
- package network;
- import javax.swing.JOptionPane;
- public class ShannonsModel {
- private double bandwidth; //initializing bandwidth
- private double signalToNoise; //initializing signaltonoise
- /** the constructor
- */
- public ShannonsModel(){ //constructor
- super();
- }
- /** this sets private bandwidth to public h to protect bandwidth
- * @param h
- */
- public void setBandwidth(double h){ //setting h to the value of bandwidth
- bandwidth = h;
- }
- /**
- * this sets signaltonoise to snr to protect signaltonoise
- * @param snr
- */
- public void setSignalToNoise(double snr){ //setting snr to the value of signal to noise
- signalToNoise = snr;
- }
- /**
- * this is shannon's theorem. This is where the the mathematic foruma is run
- * @param bandwidth
- * @param signalToNoise
- * @return
- */
- private double getMaximumDataRate(double bandwidth, double signalToNoise){ //Shannon's theorem
- return (bandwidth*Math.log(1+Math.pow(10, signalToNoise/10))/Math.log(2));
- }
- /**
- * this grabs a copy of the bandwidth and signal to noise for use in the theorem
- * @return
- */
- public double getMaximumDataRate(){ //getting bandwidth and signaltonoise and putting them in for the Shannon theorem
- return getMaximumDataRate(getBandwidth(), getSignalToNoise());
- }
- /**
- * getBandwidth returns a copy of bandwidth
- * @return
- */
- public double getBandwidth(){ //returning a copy of bandwidth
- return bandwidth;
- }
- /**
- * getsignaltonoise gets a copy of signaltonoise
- * @return
- */
- public double getSignalToNoise(){ //returning a copy of signal to noise
- return signalToNoise;
- }
- /**
- * the toString is what will be called instead of the original class toString value
- */
- public String toString(){ //setting a toString value
- return ("Bandwidth is " + getBandwidth() + "Signal to noise is " + getSignalToNoise() + "The maximum data rate is " + getMaximumDataRate());
- }
- /**
- * this sets the Joptionpanes to grab information from the user and display it in dialog boxes
- * @param args
- */
- public static void main(String[] args) { //MAIN with option panes to request values
- ShannonsThreorem app = new ShannonsThreorem();
- app.setBandwidth(Double.parseDouble(JOptionPane.showInputDialog("Enter the bandwidth")));
- app.setSignalToNoise(Double.parseDouble(JOptionPane.showInputDialog("Enter signal to noise")));
- 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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement