source: proiecte/ptvs/src/vnsim/network/propagation/Ricean.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 3.2 KB
Line 
1/************************************************************************************
2 * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
3 * All rights reserved.
4 * Refer to LICENSE for terms and conditions of use.
5 ***********************************************************************************/
6package vnsim.network.propagation;
7
8
9import java.io.BufferedReader;
10import java.io.FileReader;
11import java.io.File;
12import java.util.StringTokenizer;
13import java.util.Scanner;
14import java.io.IOException;
15
16import vnsim.map.object.Globals;
17
18
19public class Ricean
20{
21        //vectors containig the Gaussian components from the txt file
22        double[] data1,data2;
23        //number of Gaussian components
24        int n;
25       
26        double K;
27        //max velocity of nodes , used in calculating the fm Doppler frequency
28        double maxVelocity;
29       
30        double fm0,fs,dt,fm;
31       
32        public Ricean(String fileName,boolean isUrban) throws IOException
33        {
34                this.K=Globals.RICEAN_K;
35               
36                if(isUrban)
37                        this.maxVelocity=Globals.RICEAN_MAX_VELOCITY_URBAN;
38                else
39                        this.maxVelocity=Globals.RICEAN_MAX_VELOCITY_FREE;
40               
41                this.fm=this.maxVelocity/Globals.DSRC_LAMBDA;
42               
43                this.fm0=this.fs=this.dt=0;
44               
45                this.loadDataFile(fileName);
46        }
47
48        //reading gaussian components from file
49        public void loadDataFile(String fileName) throws IOException
50        {       
51                //Scanner s=new Scanner(new File(fileName));
52               
53                BufferedReader br=new BufferedReader(new FileReader(fileName));
54               
55                this.n=Integer.parseInt(br.readLine());
56                this.fm0=(double)Integer.parseInt(br.readLine());
57                this.fs=(double)Integer.parseInt(br.readLine());;
58               
59                this.data1=new double[this.n];
60                this.data2=new double[this.n];
61               
62                StringTokenizer st;
63               
64                for(int i=0;i<this.n;i++)
65                {
66                        st=new StringTokenizer(br.readLine());
67                       
68                        this.data1[i]=Double.parseDouble(st.nextToken());
69                        this.data2[i]=Double.parseDouble(st.nextToken());
70                }
71        }
72       
73        //calculates the fading and adds it to the received power calculated by Two Ray Ground
74        public double getPr(double Pt,double R,int currentTime)
75        {
76                double Pr, Pr_Rice=0.0, Pr_tot;
77
78                Pr = TwoRay.getPr(Pt,R);
79
80                double time_index;
81                double envelope_fac, tmp_x1, tmp_x2, x1_interp, x2_interp;
82               
83                time_index=currentTime + 2*this.fs * this.fm/this.fm0;
84               
85                time_index-=(double)this.n * Math.floor(time_index/(double)this.n);
86               
87                double X0, X1, X2, X3;
88                int ind0, ind1, ind2, ind3;
89               
90                ind1 = (int)Math.floor(time_index);
91                ind0 = (ind1-1+this.n) % this.n;
92                ind2 = (ind1+1) % this.n;
93                ind3 = (ind1+2) % this.n;
94               
95                X1 = time_index - ind1;
96                X0 = X1+1.0;
97                X2 = X1-1.0;
98                X3 = X1-2.0;
99
100                x1_interp = this.data1[ind0]*X1*X2*X3/(-6.0) +this.data1[ind1]*X0*X2*X3*(0.5) +this.data1[ind2]*X0*X1*X3*(-0.5) +this.data1[ind3]*X0*X1*X2/6.0;
101                       
102                x2_interp = this.data2[ind0]*X1*X2*X3/(-6.0) +this.data2[ind1]*X0*X2*X3*(0.5) +this.data2[ind2]*X0*X1*X3*(-0.5) +this.data2[ind3]*X0*X1*X2/6.0;
103
104                /* Find the envelope multiplicative factor */
105                tmp_x1 = x1_interp + Math.sqrt(2.0 * this.K);
106                tmp_x2 = x2_interp;
107
108                envelope_fac = (tmp_x1*tmp_x1 + tmp_x2*tmp_x2) / 
109                        (2.0 * (this.K+1)); 
110
111                Pr_Rice = envelope_fac;
112
113                Pr_tot = Pr * Pr_Rice;
114
115                return Pr_tot;
116        }
117}
Note: See TracBrowser for help on using the repository browser.