Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Modula 3 12.02 KB | None | 0 0
  1. Simulation Begin
  2.  
  3. ! Common math functions - declaration **********;
  4.  
  5.   Boolean PDF_values;
  6.   Real pi;
  7.  
  8.   Real Procedure Integral(Real Procedure F(Real X), Real A, Real B);
  9.   Begin
  10.     Real Sum;
  11.     Real DX;
  12.     Sum := 0;
  13.     DX := 0.5;
  14.     While A < B do
  15.       Begin
  16.         Sum := Sum + F(A);
  17.         A := A + DX;
  18.       End;
  19.     Integral := Sum * DX;
  20.   End of Integral;
  21.  
  22.   Real Procedure ErrorFunction(Real X);
  23.   Begin
  24.     ErrorFunction := If X <> 0 Then (X/abs(X)) * (sqrt(1-exp((-x**2*(4/pi+((8*(pi-3))/(3*pi*(4-pi)))*x**2))/(1+((8*(pi-3))/(3*pi*(4-pi)))*x**2)))) Else 0;
  25.   End of ErrorFunction;
  26.  
  27.   Real Procedure Logarithm(Real X, Real B);
  28.   Begin
  29.     Logarithm := ln(x) / ln(b);
  30.   End of Logarithm;
  31.  
  32. ! Traffic Distribution - declaration **********;
  33.  
  34.   Real R;
  35.   Real am;              ! max altitude of traffic distribution;
  36.   Real ah;              ! probe reciever altitude;
  37.   Real Ko, Rp;          ! total traffic count within Rp = Ko;
  38.   Real R1o, fxx;
  39.   Real Dm, D1, Da;
  40.   Real K, Rfo, Rf, R1, tq;
  41.   Real Ro, muu, sigmau;
  42.  
  43.   Real Procedure pt(Real R);
  44.   Begin
  45.     pt := K * (R/Rf**2) * exp((-1/2)*(R/Rf)**2);
  46.   End of pt;
  47.  
  48.   Real Procedure Nf(Real R);
  49.   Begin
  50.     Nf := Integral(pt,0,R);
  51.   End of Nf;
  52.  
  53.   Real Procedure N1_(Real R);
  54.   Begin
  55.     N1_ := (Nf(R1)*(R**tq))/R1;
  56.   End of N1_;
  57.  
  58.   Real Procedure N1(Real R);
  59.   Begin
  60.     N1 := Integral(N1_,0,R);
  61.   End of N1;
  62.  
  63.   Real Procedure N2(Real R);
  64.   Begin
  65.     N2 := Integral(pt,R1,R) + N1(R1);
  66.   End of N2;
  67.  
  68.   Real Procedure Nt(Real R);
  69.   Begin
  70.     If R <= R1 Then
  71.       Nt := N1(R)
  72.     Else
  73.       Nt := N2(R)
  74.   End of Nt;
  75.  
  76. ! Received Signal - declaration **********;
  77.  
  78.   Real U;
  79.   Real MTL;
  80.  
  81.   Real Procedure Uo(Real Ro, Real R);
  82.   Begin
  83.     Uo := If R <> 0 Then muu + 20 * Logarithm((Ro/R),10) Else 0;
  84.   End;
  85.  
  86.   Real Procedure Fu(Real Ro, Real R, Real U);
  87.   Begin
  88.     Fu := 0.5 - 0.5 * ErrorFunction((1/sqrt(2))*((U-Uo(Ro,R))/(sigmau)));
  89.   End;
  90.  
  91.   Real Procedure W1_(Real R);
  92.   Begin
  93.     W1_ := ((Nf(R1)*(R**tq))/(R1))*Fu(Ro,R,U);
  94.   End of W1_;
  95.  
  96.   Real Procedure W1(Real Ro_new, Real R_new, Real U_new);
  97.   Begin
  98.     Real U_old, R_old, Ro_old;
  99.     Ro_old := Ro;
  100.     R_old := R;
  101.     U_old := U;
  102.     Ro := Ro_new;
  103.     R := R_new;
  104.     U := U_new;
  105.     W1 := Integral(W1_,0,R);
  106.     R := R_old;
  107.     Ro := Ro_old;
  108.     U := U_old;
  109.   End of W1;
  110.  
  111.   Real Procedure W2_(Real R);
  112.   Begin
  113.     W2_ := pt(R) * Fu(Ro,R,U);
  114.   End of W2_;
  115.  
  116.   Real Procedure W2(Real Ro_new, Real R_new, Real U_new);
  117.   Begin
  118.     Real R_old, Ro_old, U_old;
  119.     Ro_old := Ro;
  120.     R_old := R;
  121.     U_old := U;
  122.     R := R_new;
  123.     Ro := Ro_new;
  124.     U := U_new;
  125.     W2 := Integral(W2_,R1,R) + W1(Ro,R1,U);
  126.     R := R_old;
  127.     Ro := Ro_old;
  128.     U := U_old;
  129.   End of W2;
  130.  
  131.   Real Procedure Wt(Real Ro, Real R, Real U);
  132.   Begin
  133.     If R <= R1 Then
  134.       Wt := W1(Ro,R,U)
  135.     Else
  136.       Wt := W2(Ro,R,U)
  137.   End;
  138.  
  139. ! Fruit Distribution - declaration **********;
  140.  
  141.   Real Ra;
  142.   Real gamaa, gamas;
  143.   Real sr, ss, fs, h, ft, ks;
  144.   Real M, g, a, msi;
  145.   Real ENV, ar, SA;
  146.   Real iag, zag, isg, zsg;
  147.   Real tsr, ao, rt, d;
  148.   Real tr;
  149.   Real ist, zst, iat, iatt, zat;
  150.   Real ia, is_, za, zs, zsl;
  151.  
  152.   Real Procedure Ntc(Real rt);
  153.   Begin
  154.     Ntc := Nt(R) * ft * d;
  155.   End;
  156.  
  157.   Real Procedure fza(Real Ro, Real R, Real U);
  158.   Begin
  159.     fza := za * Wt(Ro,R,U);
  160.   End;
  161.  
  162.   Real Procedure fzs(Real Ro, Real R, Real U);
  163.   Begin
  164.     fzs := zs * Wt(Ro,R,U);
  165.   End;
  166.  
  167.   Real Procedure fr(Real Ro, Real R, Real U);
  168.   Begin
  169.     fr := If fzs(Ro,R,U) <> 0 Then fza(Ro,Rp,U)/fzs(Ro,R,U) Else 0;
  170.   End;
  171.  
  172.   Real Procedure fzsl(Real Ro, Real R, Real U);
  173.   Begin
  174.     fzsl := zsl * Wt(Ro,R,U);
  175.   End;
  176.  
  177. ! Decoder - declaration **********;
  178.  
  179.   Real Tls, Tss, Ta, Tsy, pf;
  180.  
  181.   Real Procedure psy(Real Ro, Real R, Real U);
  182.   Begin
  183.     psy := exp(-(Ta+Tsy)*za*(Wt(Ro,R,U-gamas)-Wt(Ro,R,U-gamaa)));
  184.   End;
  185.  
  186.   Real Procedure p1a(Real Ro, Real R, Real U);
  187.   Begin
  188.     p1a := (Tls+Ta)*za*Wt(Ro,R,U-gamaa)*pf;
  189.   End;
  190.  
  191.   Real Procedure p2a(Real Ro, Real R, Real U);
  192.   Begin  
  193.     p2a := 0.5*(((Tls+Ta)*za*Wt(Ro,R,U-gamaa)*pf)**2)*psy(Ro,R,U);
  194.   End;
  195.  
  196.   Real Procedure pa(Real Ro, Real R, Real U);
  197.   Begin
  198.      pa := exp(-(Tls+Ta)*za*Wt(Ro,R,U-gamaa))*(1+p1a(Ro,R,U)+p2a(Ro,R,U));
  199.   End;
  200.  
  201.   Real Procedure ps(Real Ro, Real R, Real U);
  202.   Begin
  203.      ps := exp(-(Tls+Ta)*za*Wt(Ro,R,U-gamas))*exp(-(Tls+Tls)+zsl*Wt(Ro,R,U-gamas));
  204.   End;
  205.  
  206.   Real Procedure p(Real Ro, Real R, Real U);
  207.   Begin
  208.     p := pa(Ro,R,U)*ps(Ro,R,U);
  209.   End;
  210.  
  211. ! Receiver - declaration **********;
  212.  
  213.   Real T, st, had, S;
  214.   Real mu, sigmac, ny;
  215.  
  216.   Real Procedure So(Real Ro, Real R, Real mu);
  217.   Begin
  218.     So := If R <> 0 Then mu + 20 * Logarithm(Ro/R,10) Else 0;
  219.   End;
  220.  
  221.   Real Procedure pS_(Real Ro, Real R, Real S, Real mu, Real sigma);
  222.   Begin
  223.     pS_ := (1/(ro*sqrt(2*pi)))*(exp(-0.5*((S-So(Ro,R,mu))/(sigma))**2));
  224.   End;
  225.  
  226.   Real Procedure pb(Real S);
  227.   Begin
  228.     pb := 1 - 0.5 * exp(-(10*((MTL+S)/(10)))/(2));
  229.   End;
  230.  
  231.   Real Procedure Pd(Real S);
  232.   Begin
  233.     Pd := pb(S)**had;
  234.   End;
  235.  
  236.   Real Procedure Ps__(Real S, Real T);
  237.   Begin
  238.     Ps__ := 0.5 + 0.5 * ErrorFunction((sqrt(2)/2)*((MTL+S-T)/(st)));
  239.   End;
  240.  
  241.   Real Procedure Pm(Real S, Real T);
  242.   Begin
  243.     Pm := Ps__(S,T)*Pd(S);
  244.   End;
  245.  
  246. ! Predicted Performance Model - declaration **********;
  247.  
  248.   Real Sm, Rdp, sigma;
  249.  
  250.   Real Procedure Pr_(Real S);
  251.   Begin
  252.     Pr_ := pS_(Ro,Ra,S,mu,sigma)*p(Ro,Rp,S)*Pm(S,T)*ny;
  253.   End;
  254.  
  255.   Real Procedure Pr(Real Ro_new, Real Ra_new, Real S_new, Real mu_new, Real sigma_new);
  256.   Begin
  257.     Real Ro_old, Ra_old, S_old, mu_old, sigma_old;
  258.     Ro_old := Ro;
  259.     Ra_old := Ra;
  260.     S_old := S;
  261.     mu_old := mu;
  262.     sigma_old := sigma;
  263.     Ro := Ro_new;
  264.     Ra := Ra_new;
  265.     S := S_new;
  266.     mu := mu_new;
  267.     sigma := sigma_new;
  268.     Pr := Integral(Pr_,S,Sm);
  269.     Ro := Ro_old;
  270.     Ra := Ra_old;
  271.     S := S_old;
  272.     mu := mu_old;
  273.     sigma := sigma_old;
  274.   End;
  275.  
  276.   Real Procedure Prr(Real Ro, Real Ra, Real S, Real mu, Real sigma);
  277.   Begin
  278.     Real SUM;
  279.     SUM := 0;
  280.     For S := -5 step 1 until Sm do
  281.     Begin
  282.       SUM := SUM + pS_(Ro,Ra,S,mu,sigma)*p(Ro,Rp,S)*Pm(S,T)*ny;
  283.     End;
  284.     Prr := SUM*200;
  285.   End;
  286.  
  287. ! Common math functions - initalisation **********;
  288.  
  289.   PDF_values := TRUE;
  290.   pi := 3.14159265358979323846;
  291.  
  292. ! Traffic Distribution - initialisation **********;
  293.  
  294.   am := 40000;
  295.   ah := 40000;
  296.   Ko := 500;
  297.   Rp := 400;
  298.   R1o := 30;
  299.   fxx := 0.24;
  300.   tq := 0.2;
  301.  
  302.   Dm := 1.23 * sqrt(am);          
  303.   D1 := 1.23 * sqrt(ah);          
  304.   Da := 2 * D1;                  
  305.   K := (D1 / Dm) * Ko;            
  306.   Rfo := fxx * Rp * sqrt(Dm/D1);
  307.   Rf := Rfo * Da / Rp;            
  308.   R1 := R1o * Da /Rp;  
  309.  
  310. ! Received Signal - initialisation **********;
  311.  
  312.   Ro := 95;
  313.   sigmau := 3;
  314.   muu := 0;
  315.   MTL := -84;
  316.  
  317. ! Fruit Distribution - initalisation **********;
  318.  
  319.   Ra := Ro;
  320.   gamaa := 3;
  321.   gamas := 7;
  322.   sr := 0.01;
  323.   ss := 1;
  324.   fs := 0.5;
  325.   h := 0.8;
  326.   !ft := fs * h;
  327.   ft := 0.4;
  328.   ks := 1;
  329.   M := 40;
  330.   g := 0.025;
  331.   a := 1;
  332.   msi := 1;
  333.   ENV := 2000;
  334.   ar := fs * a;
  335.   SA := If ENV <= 1999 Then 0 Else ar;
  336.   iag := (4-3*g)*M;
  337.   zag := (4-(3+SA)*g)*M;
  338.   isg := (0.33/msi)*a*g*M;
  339.   zsg := isg * fs;
  340.   tsr := 0.85;
  341.   ao := 2;
  342.   rt := 40;
  343.   d := 1;
  344.   tr := If Ntc(rt) <> 0 Then (1*Ntc(6)+tsr*(Ntc(rt)-Ntc(6)))/Ntc(rt) Else 0;
  345.   !tr := (1*Ntc(6)+tsr*(Ntc(rt)-Ntc(6)))/Ntc(rt);
  346.   ist := tr * ks * Ntc(rt);
  347.   zst := fs * (ist + ss);
  348.   iat := ao * Ntc(rt);
  349.   iatt := If iat >= 40 Then 40 Else iat;
  350.   zat := iatt * (1 - fs);
  351.   ia := iag + iatt;
  352.   is_ := isg + ist;
  353.   za := zag + zat;
  354.   zs := zsg + zst;
  355.   zsl := sr * fs;
  356.  
  357. ! Decoder - initialisation **********;
  358.  
  359.   Tls := 120*(1/10)**6;
  360.   Tss := 64*(1/10)**6;
  361.   Ta := 20.3*(1/10)**6;
  362.   Tsy := 8*(1/10)**6;
  363.   pf := 1 - (Tsy + Ta)/(Tls + Ta) * 0.2;
  364.  
  365. ! Receiver - initialisation **********;
  366.  
  367.   T := 0;
  368.   st := 0.5;
  369.   had := 112;
  370.   mu := 0;
  371.   sigmac := 2;
  372.   ny := 0.95;
  373.   MTL := 11;
  374.  
  375. ! Predicted Performance Model - initialisation **********;
  376.  
  377.   Sm := 20 * Logarithm(Ro/2,10) + 2 * sigmac;
  378.   Rdp := 100;
  379.  
  380. ! Traffic Distribution - init and graph data output **********;
  381.  
  382.   OutText("*** Traffic Distribution ***");
  383.   OutImage;
  384.   OutText("R     Nt(R)");
  385.   OutImage;
  386.  
  387.   ah := 40000;
  388.   D1 := 246;
  389.   Rp := 400;
  390.   Ro := 95;
  391.   muu := 0;
  392.   sigmau := 3;
  393.   am := 40000;
  394.  
  395.   For R := 0 step 25 until 500 do
  396.   Begin
  397.     OutInt(R,3);
  398.     OutText("   =");
  399.     OutReal(Nt(R),8,15);
  400.     OutImage;
  401.   End;
  402.  
  403.   OutImage;
  404.  
  405. ! Received Signal - initalisation and graph data output **********;  
  406.  
  407.   ah := 22000;
  408.   D1 := 182;
  409.   Rp := 400;
  410.   Ro := 95;
  411.   muu := 0;
  412.   sigmau := 3;
  413.   am := 40000;
  414.  
  415.   OutText("*** Received Signal ***");
  416.   OutImage;
  417.   !OutText("R     Nt(R)              Wt(Ro,R,0)         Wt(Ro,R,-3)        Wt(Ro,R,-7)");
  418.   OutText("R     Wt(Ro,R,0)         Wt(Ro,R,-3)        Wt(Ro,R,-7)");
  419.   OutImage;
  420.  
  421.   For R := 0 step 25 until 250 do
  422.   Begin
  423.     OutInt(R,3);
  424.     !OutText("   =");
  425.     !OutReal(Nt(R),8,15);
  426.     OutText("   =");
  427.     OutReal(Wt(Ro,R,0),8,15);
  428.     OutText("   =");
  429.     OutReal(Wt(Ro,R,-3),8,15);
  430.     OutText("   =");
  431.     OutReal(Wt(Ro,R,-7),8,15);
  432.     OutImage;
  433.   End;
  434.  
  435.   OutImage;
  436.  
  437. ! Fruit Distribution - initalisation and graph data output **********;
  438.  
  439.   If PDF_values Then
  440.   Begin
  441.     MTL := -84;
  442.     Rp := 400;
  443.     ah := 22000;
  444.     Ro := 95;
  445.     muu := 0;
  446.     sigmau := 3;
  447.     M := 40;
  448.     msi := 1;
  449.     SA := 0.5;
  450.     rt := 40;
  451.     fs := 0.5;
  452.     ft := 0.4;
  453.     tsr := 0.85;
  454.     ao := 2;
  455.     ks := 1;
  456.     ss := 1;
  457.     ia := 186;
  458.     is_ := 12.7;
  459.     za := 171;
  460.     zs := 6.8;
  461.     zsl := 0;
  462.   End;
  463.  
  464.   OutText("*** Fruit Distribution ***");
  465.   OutImage;
  466.   OutText("U+MTL fza(Ro,400,U)      fzs(Ro,400,U)      fzsl(Ro,400,U)");
  467.   OutImage;
  468.  
  469.   For U := -10 step 2.5 until 30 do
  470.   Begin
  471.     OutInt(U+MTL,3);
  472.     OutText("   =");
  473.     OutReal(fza(Ro,Rp,U),8,15);
  474.     OutText("   =");
  475.     OutReal(fzs(Ro,Rp,U),8,15);
  476.     OutText("   =");
  477.     OutReal(fzsl(Ro,Rp,U),8,15);
  478.     OutImage;
  479.   End;
  480.  
  481.   OutImage;
  482.  
  483. ! Decoder - initalisation and graph data output **********;
  484.  
  485.   gamaa := 3;
  486.   gamas := 7;
  487.   MTL := -84;
  488.  
  489.   OutText("*** Decoder ***");
  490.   OutImage;
  491.   OutText("U+MTL p(Ro,400,U)        pa(Ro,400,U)       ps(Ro,400,U)");
  492.   OutImage;
  493.  
  494.   For U := -10 step 2.5 until 30 do
  495.   Begin
  496.     OutInt(U+MTL,3);
  497.     OutText("   =");
  498.     OutReal(p(Ro,Rp,U),8,15);
  499.     OutText("   =");
  500.     OutReal(pa(Ro,Rp,U),8,15);
  501.     OutText("   =");
  502.     OutReal(ps(Ro,Rp,U),8,15);
  503.     OutImage;
  504.   End;
  505.  
  506.   OutImage;
  507.  
  508. ! Receiver - initalisation and graph data output **********;
  509.  
  510.   MTL := 11;
  511.   Rp := 400;
  512.   ah := 22000;
  513.   Ro := 95;
  514.   Ra := Ro;
  515.   mu := 0;
  516.   sigmac := 2;
  517.   sigmau := 3;
  518.   muu := 0;
  519.  
  520.   If PDF_values Then
  521.   Begin
  522.     fs := 0.5;
  523.     ft := 0.4;
  524.     ks := 1;
  525.     ss := 1;
  526.     M := 40;
  527.     mu := 0;
  528.     za := 170.8;
  529.     zs := 6.8;
  530.     zsl := 0.005;
  531.   End;
  532.  
  533.   OutText("*** Receiver ***");
  534.   OutImage;
  535.   OutText("S     Pm(S,T)            p(Ro,Rp,S)*Pm(S,T) pS(Ro,Ra,S,mu,roc)");
  536.   OutImage;
  537.  
  538.   For S := -6 step 1 until 10 do
  539.   Begin
  540.     OutInt(S,3);
  541.     OutText("   =");
  542.     OutReal(Pm(S,T),8,15);
  543.     OutText("   =");
  544.     OutReal(p(Ro,Rp,S)*Pm(S,T),8,15);
  545.     OutText("   =");
  546.     OutReal(pS_(Ro,Ra,S,mu,sigmac),8,15);
  547.     OutImage;
  548.   End;
  549.  
  550.   OutImage;
  551.  
  552. ! Predicted Performance Model - initalisation and graph data output **********;
  553.  
  554.   Ro := 95;
  555.   mu := 0;
  556.   sigmac := 2;
  557.   ah := 22000;
  558.   muu := 0;
  559.   sigmau := 3;
  560.   gamaa := 3;
  561.   gamas := 7;
  562.   ny := 0.95;
  563.  
  564.   OutText("*** Predicted Performance Model ***");
  565.   OutImage;
  566.   OutText("Ra    Prr(Ro,Ra,-5,0,0.5) Prr(Ro,Ra,-5,3.3,0.5) Prr(Ro,Ra,-5,-3.3,0.5)");
  567.   OutImage;
  568.    
  569.   For Ra := 0 step 5 until 100 do
  570.   Begin
  571.     OutInt(Ra,3);
  572.     OutText("   =");
  573.     OutReal(Prr(Ro,Ra,-5,0,0.5),8,15);
  574.     OutText("    =");
  575.     OutReal(Prr(Ro,Ra,-5,3.3,0.5),8,15);
  576.     OutText("      =");
  577.     OutReal(Prr(Ro,Ra,-5,-3.3,0.5),8,15);
  578.     OutImage;
  579.   End;
  580.  
  581. End of Program;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement