Advertisement
NullChips

Untitled

Apr 30th, 2020
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. package ga.tomj.imdcalculator;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class IMDCalculator {
  6.  
  7.  
  8.     //Initiate variables.
  9.     static double rangeMin;
  10.     static double rangeMax;
  11.     static double resolution;
  12.     static double spacing;
  13.     static int freqsNeeded;
  14.     static int count;
  15.     static ArrayList<Double> blockedFreqs = new ArrayList<>();
  16.     static ArrayList<Double> imdProducts = new ArrayList<>();
  17.     static ArrayList<Double> chosenFreqs = new ArrayList<>();
  18.  
  19.     public static void main(String[] args) {
  20.         // Set variables.
  21.         rangeMin = 606.000;
  22.         rangeMax = 613.5;
  23.         resolution = 0.010;
  24.         spacing = 0.150;
  25.         freqsNeeded = 30;
  26.  
  27.         //Set blocked frequencies.
  28.         blockedFreqs.add(608.500);
  29.         blockedFreqs.add(611.000);
  30.         blockedFreqs.add(622.150);
  31.  
  32.         count = 0;
  33.  
  34.         chosenFreqs.add(rangeMin);
  35.  
  36.         while (count + 1 < freqsNeeded) {
  37.  
  38.             if (count + 1 > chosenFreqs.size()) {
  39.                 chosenFreqs.set(count, chosenFreqs.get(count - 1));
  40.             }
  41.  
  42.             if (count > 0) {
  43.                 while (chosenFreqs.get(count) - chosenFreqs.get(count - 1) <= spacing) {
  44.                     chosenFreqs.set(count, chosenFreqs.get(count) + resolution);
  45.                     System.out.println("oh god help me");
  46.                 }
  47.             }
  48.  
  49.             imdProducts.clear();
  50.  
  51.             for (Double d1 : chosenFreqs) {
  52.                 for (Double d2 : chosenFreqs) {
  53.                     if(d1 != d2) {
  54.                         imdProducts.add((2 * d1) - d2);
  55.                         imdProducts.add((2 * d2) - d1);
  56.  
  57.                         imdProducts.add((3 * d1) - (2 * d2));
  58.                         imdProducts.add((3 * d2) - (2 * d1));
  59.                     }
  60.                 }
  61.             }
  62.  
  63.             System.out.println(imdProducts);
  64.  
  65.             boolean allowedFreq = true;
  66.  
  67.             if (blockedFreqs.contains(chosenFreqs.get(count))) {
  68.                 allowedFreq = false;
  69.             }
  70.  
  71.  
  72.             if (count > 0) {
  73.                 for (double d1 : imdProducts) {
  74.                     for (double d2 : chosenFreqs) {
  75.                         if (Math.abs(d1 - d2) <= spacing / 3 || Math.abs(d2 - d1) <= spacing / 3 && d2 != d1) {
  76.                             allowedFreq = false;
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.  
  82.             if (chosenFreqs.get(count) > rangeMax) {
  83.                 System.out.println("Frequency finding finished.");
  84.                 System.out.println(chosenFreqs);
  85.                 break;
  86.             }
  87.  
  88.             if (allowedFreq) {
  89.                 System.out.println("Found frequency " + count);
  90.                 chosenFreqs.add(chosenFreqs.get(count) + resolution);
  91.                 count++;
  92.                 System.out.println(count);
  93.                 System.out.println("didn't get here");
  94.             } else {
  95.                 System.out.println("got here");
  96.                 chosenFreqs.set(count, chosenFreqs.get(count) + resolution);
  97.             }
  98.         }
  99.  
  100.  
  101.         System.out.println("##############");
  102.         System.out.println("Finally chosen frequencies:");
  103.         int i = 1;
  104.         for(double d : chosenFreqs) {
  105.             System.out.println("Frequency " + i + ": " + String.format("%.3f", d));
  106.             i++;
  107.         }
  108.         System.out.println("##############");
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement