martaczaska

Licz

Nov 15th, 2020 (edited)
1,379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.36 KB | None | 0 0
  1. package eti.radio.pr_inz;
  2.  
  3. import javax.imageio.ImageIO;
  4. import javax.swing.*;
  5. import java.lang.Math;
  6. import java.awt.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.image.BufferedImage;
  10. import java.io.File;
  11. import java.io.IOException;
  12.  
  13. public class Licz extends JPanel implements ActionListener {
  14.  
  15.     private JButton wyjscie;
  16.     public BufferedImage tlo_dane;
  17.  
  18.     int wybrane_nw = O2I.nw;
  19.     int wyb_model = Mapa.s;
  20.     double f_c = 10000000; //musi byc bo w log10(double a)
  21.     int d_2D = 100; //m
  22.     int d_2D_IN = 2; //m
  23.     // d_2D = Dane.d_watosc;
  24.     int h_BS = 25; //zrobić jako Slidery
  25.     int h_UT = 1;  ///zrobić jako Slidery
  26.     int h_E = 1; // 1m
  27.     int h = 5; //w metrach, do RMa
  28.     int W = 20; //w metrach, do RMa
  29.     int c = 3*(10^8);
  30.     double sigma_LOS, sigma_NLOS;
  31.     double PL_LOS, PL_NLOS, PL_NLOS2, PL_LOS_O2I, PL_NLOS_O2I;
  32.     double d_BP, d2_BP;
  33.     double d_3D = Math.abs( (h_BS-h_UT)^2 + d_2D^2 );
  34.  
  35.     public Licz(){
  36.         setLayout(null);
  37.  
  38.         d_BP = 4*(h_BS -h_E)*(h_UT -h_E)*f_c/c;
  39.         d2_BP = 2*Math.PI*h_BS*h_UT*f_c/c;
  40.  
  41.         if(wyb_model == 1){ //model Indoor Hotspot - InH
  42.             PL_LOS = 32.4 + 17.3*Math.log10(d_3D) + 20*Math.log10(f_c);     //- path loss for LOS
  43.             PL_NLOS2 = 38.3*Math.log10(d_3D) + 17.3 + 24.9*Math.log10(f_c);
  44.             PL_NLOS = Math.max(PL_LOS, PL_NLOS2);                           //- path loss for NLOS
  45.             sigma_LOS = 3; //dB
  46.             sigma_NLOS = 8.03; //dB
  47.         }
  48.         else if(wyb_model == 2){ //model Urban Macro- UMa
  49.             if( d_2D >= 10 && d_2D <= d_BP){
  50.                 PL_LOS = 28 + 22*Math.log10(d_3D) + 20*Math.log10(f_c);
  51.                 PL_NLOS2 = 13.54 + 39.08*Math.log10(d_3D) + 20*Math.log10(f_c) -6*(h_UT-1.5);
  52.                 PL_NLOS = Math.max(PL_LOS, PL_NLOS2);
  53.             }
  54.             else if(d_2D >= d_BP && d_2D <= 5000){
  55.                 PL_LOS = 28 + 40*Math.log10(d_3D) + 20*Math.log10(f_c) -9*(Math.pow(d_BP,2) + Math.pow((h_BS + h_UT),2));
  56.                 PL_NLOS2 = 13.54 + 39.08*Math.log10(d_3D) + 20*Math.log10(f_c) -6*(h_UT-1.5);
  57.                 PL_NLOS = Math.max(PL_LOS, PL_NLOS2);
  58.             }
  59.             sigma_LOS = 4; //dB
  60.             sigma_NLOS = 6; //dB
  61.         }
  62.         else if(wyb_model == 3){ //model Urban Macro- UMa z O2I
  63.             PL_LOS_O2I = PL_O2I(wybrane_nw, PL_LOS);
  64.             PL_NLOS_O2I = PL_O2I(wybrane_nw, PL_NLOS);
  65.         }
  66.         else if(wyb_model == 4){ //model Urban Micro- UMi
  67.             if( d_2D >= 10 && d_2D <= d_BP){
  68.                 PL_LOS = 32.4 + 21*Math.log10(d_3D) + 20*Math.log10(f_c);
  69.                 PL_NLOS2 = 22.4 + 35.3*Math.log10(d_3D) + 21.3*Math.log10(f_c) -0.3*(h_UT-1.5);
  70.                 PL_NLOS = Math.max(PL_LOS, PL_NLOS2);
  71.             }
  72.             else if(d_2D >= d_BP && d_2D <= 5000){
  73.                 PL_LOS = 32.4 + 40*Math.log10(d_3D) + 20*Math.log10(f_c) -9.5*(Math.pow(d_BP,2) + Math.pow((h_BS + h_UT),2));
  74.                 PL_NLOS2 = 22.4 + 35.3*Math.log10(d_3D) + 21.3*Math.log10(f_c) -0.3*(h_UT-1.5);
  75.                 PL_NLOS = Math.max(PL_LOS, PL_NLOS2);
  76.             }
  77.             sigma_LOS = 4; //dB
  78.             sigma_NLOS = 7.82; //dB
  79.         }
  80.         else if(wyb_model == 5){ //model Urban Micro- UMi z O2I
  81.  
  82.         }
  83.         else if(wyb_model == 6){ //model Rural Macro- RMa
  84.             if( d_2D >= 10 && d_2D <= d2_BP){
  85.                 PL_LOS = 2*Math.log10((40*Math.PI*d_3D*f_c)/3) + Math.min(Math.pow(0.03*h, 1.72), 10)*Math.log10(d_3D) - Math.min(Math.pow(0.044*h, 1.72), 14.77) + 0.002*Math.log10(h)*d_3D;
  86.                 PL_NLOS2 = 161.04-7.1*Math.log10(W)+7.5*Math.log10(h)-(24.37-3.7*Math.pow(h/h_BS,2)*Math.log10(h_BS) +(43.42-3.1*Math.log10(h_BS))*(Math.log10(d_3D)-3) + 20*Math.log10(f_c)- (3.2*(Math.log10(11.75*h_UT)-4.97)));
  87.                 PL_NLOS = Math.max(PL_LOS, PL_NLOS2);
  88.                 sigma_LOS = 4; //dB
  89.             }
  90.             else if(d_2D >= d2_BP && d_2D <= 21000) {
  91.                 PL_LOS = 2*Math.log10((40*Math.PI*d2_BP*f_c)/3) + Math.min(Math.pow(0.03*h, 1.72), 10)*Math.log10(d2_BP) - Math.min(Math.pow(0.044*h, 1.72), 14.77) + 0.002*Math.log10(h)*d2_BP +40*Math.log10(d_3D/d2_BP);
  92.                 PL_NLOS2 = 161.04-7.1*Math.log10(W)+7.5*Math.log10(h)-(24.37-3.7*Math.pow(h/h_BS,2)*Math.log10(h_BS) +(43.42-3.1*Math.log10(h_BS))*(Math.log10(d_3D)-3) + 20*Math.log10(f_c)- (3.2*(Math.log10(11.75*h_UT)-4.97)));
  93.                 PL_NLOS = Math.max(PL_LOS, PL_NLOS2);
  94.                 sigma_LOS = 6; //dB
  95.             }
  96.             sigma_NLOS = 8; //dB
  97.         }
  98.         else if(wyb_model == 7){ //model Rural Macro- RMa z O2I
  99.             System.out.println("Udało się, yaaaaaaaaaaaaaaaaaaaaaaaaay!");
  100.             //DODATKOWE WZORY PRZEZ PRZENIKI
  101.         }
  102.  
  103.  
  104.  
  105.         File zdj_menu = new File("zdjecia/strona_logo.png");
  106.         try{ tlo_dane = ImageIO.read(zdj_menu); }
  107.         catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
  108.  
  109.         wyjscie = new JButton("Wyjście");
  110.         wyjscie.addActionListener(this);
  111.         wyjscie.setBounds(724, 620, 200, 60);
  112.         wyjscie.setFont(new Font("Sitka Text", Font.BOLD, 25));
  113.         wyjscie.setBackground(Color.white);
  114.  
  115.         add(wyjscie);
  116.     }
  117.  
  118.     public double PL_O2I(int n, double pl){
  119.         double L_szklo = 2 + 0.2*f_c; //dB
  120.         double L_beton = 5 + 4*f_c; //dB
  121.         double PL_przeniki = 0;
  122.         double PL_tw, PL_in, sigma_P;
  123.         double N = 5;  // !!!!!!!!!!!!!!!!!!! ZMIENIĆ
  124.         PL_in = 0.5*d_2D_IN;
  125.  
  126.         if(n == 0){ //nisko stratny model
  127.             PL_tw = 5 - Math.log10(0.3*Math.pow(10, (-L_szklo/10)) + 0.7*Math.pow(10, (-L_beton/10)));
  128.             sigma_P = 4.4; //dB
  129.             PL_przeniki = pl + PL_tw + PL_in + N;
  130.         }
  131.         else if(n == 1){ ////wysoko stratny model
  132.             PL_tw = 5 - Math.log10(0.7*Math.pow(10, (-L_szklo/10)) + 0.3*Math.pow(10, (-L_beton/10)));
  133.             sigma_P = 4.4; //dB
  134.             PL_przeniki = pl + PL_tw + PL_in + N;
  135.         }
  136.         return PL_przeniki;   //WYWALA BŁĄD, CZEMU?
  137.     }
  138.  
  139.     public void actionPerformed(ActionEvent e){
  140.         Object source = e.getSource();
  141.         if(source == wyjscie){
  142.             System.exit(0);
  143.         }
  144.     }
  145.  
  146.     public void paintComponent(Graphics graphic) {
  147.         Graphics2D g2d = (Graphics2D) graphic;
  148.         g2d.drawImage(tlo_dane, 0, 0, this);
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment