Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ga.tomj.imdcalculator;
- import java.util.ArrayList;
- public class IMDCalculator {
- //Initiate variables.
- static double rangeMin;
- static double rangeMax;
- static double resolution;
- static double spacing;
- static int freqsNeeded;
- static int count;
- static ArrayList<Double> blockedFreqs = new ArrayList<>();
- static ArrayList<Double> imdProducts = new ArrayList<>();
- static ArrayList<Double> chosenFreqs = new ArrayList<>();
- public static void main(String[] args) {
- // Set variables.
- rangeMin = 606.000;
- rangeMax = 613.5;
- resolution = 0.010;
- spacing = 0.150;
- freqsNeeded = 30;
- //Set blocked frequencies.
- blockedFreqs.add(608.500);
- blockedFreqs.add(611.000);
- blockedFreqs.add(622.150);
- count = 0;
- chosenFreqs.add(rangeMin);
- while (count + 1 < freqsNeeded) {
- if (count + 1 > chosenFreqs.size()) {
- chosenFreqs.set(count, chosenFreqs.get(count - 1));
- }
- if (count > 0) {
- while (chosenFreqs.get(count) - chosenFreqs.get(count - 1) <= spacing) {
- chosenFreqs.set(count, chosenFreqs.get(count) + resolution);
- System.out.println("oh god help me");
- }
- }
- imdProducts.clear();
- for (Double d1 : chosenFreqs) {
- for (Double d2 : chosenFreqs) {
- if(d1 != d2) {
- imdProducts.add((2 * d1) - d2);
- imdProducts.add((2 * d2) - d1);
- imdProducts.add((3 * d1) - (2 * d2));
- imdProducts.add((3 * d2) - (2 * d1));
- }
- }
- }
- System.out.println(imdProducts);
- boolean allowedFreq = true;
- if (blockedFreqs.contains(chosenFreqs.get(count))) {
- allowedFreq = false;
- }
- if (count > 0) {
- for (double d1 : imdProducts) {
- for (double d2 : chosenFreqs) {
- if (Math.abs(d1 - d2) <= spacing / 3 || Math.abs(d2 - d1) <= spacing / 3 && d2 != d1) {
- allowedFreq = false;
- }
- }
- }
- }
- if (chosenFreqs.get(count) > rangeMax) {
- System.out.println("Frequency finding finished.");
- System.out.println(chosenFreqs);
- break;
- }
- if (allowedFreq) {
- System.out.println("Found frequency " + count);
- chosenFreqs.add(chosenFreqs.get(count) + resolution);
- count++;
- System.out.println(count);
- System.out.println("didn't get here");
- } else {
- System.out.println("got here");
- chosenFreqs.set(count, chosenFreqs.get(count) + resolution);
- }
- }
- System.out.println("##############");
- System.out.println("Finally chosen frequencies:");
- int i = 1;
- for(double d : chosenFreqs) {
- System.out.println("Frequency " + i + ": " + String.format("%.3f", d));
- i++;
- }
- System.out.println("##############");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement