Check this code that I'm using to set the power based on the circular distance in meters:
Usage: set coverage [CellCoverage 1 1 $MAX_X $MAX_Y $OVERLAP] set power [SetPt $coverage] Phy/WirelessPhy set Pt_ $power $ns node-config -rxPower $power -txPower $power ------------- ################################################################### ################################################################### ### generic POWER functions # # Given overlaping area, calculate the desired coverage # expects a BOUNDING BOX for the cell, with the mobile in the center # proc CellCoverage { x1 y1 x2 y2 overlap} { set d2 [expr ($x2-$x1)*($x2-$x1) + ($y2-$y1)*($y2-$y1)] set d [expr sqrt($d2)] ;# Hipotenusa set ret [expr ($overlap + $d) / 2] puts "D2: $d2 D: $d RET: $ret" return $ret } # # Given overlaping area, calculate the desired coverage # expects a QUARTER BOUNDING BOX for the cell, with the mobile in the 0,0 position (lower left corner) # proc HalfCellCoverage { x1 y1 x2 y2 overlap } { return [expr [CellCoverage $x1 $y1 $x2 $y2 $overlap] * 2] } # # Calculate Necessary Transmission Power Pt for given coverage # # See /mobile/tworayground.cc # proc SetPt { coverage } { set Gt [Antenna/OmniAntenna set Gt_] set Gr [Antenna/OmniAntenna set Gr_] set ht [Antenna/OmniAntenna set Z_] set hr [Antenna/OmniAntenna set Z_] set RXThresh [Phy/WirelessPhy set RXThresh_] set L [Phy/WirelessPhy set L_] set Pt_ [Phy/WirelessPhy set Pt_] set freq_ [Phy/WirelessPhy set freq_] set lambda [expr 300000000 / $freq_] set crossover_dist [expr (4 * 3.1415926535897 * $ht * $hr) / $lambda ]; puts "old pt: $Pt_ RXThresh: $RXThresh lambda: $lambda \t\t crosshover: $crossover_dist coverage: $coverage" if { [expr $coverage < $crossover_dist] } { puts ">>> Using Friis formula <<<" set M [expr $lambda / (4.0 * 3.1415926535897 * $coverage)] set Pt [expr $RXThresh * ($L / ($Gt*$Gr*$M*$M))] puts " RET: $Pt" } else { puts ">>> Using TwoRay formula <<<" #Calculate input power necessary to have, at dist $coverage, output power = $RXThresh set d4 [expr pow($coverage,4)] set Pt [expr $RXThresh * (($L*$d4) / ($Gt*$Gr*$ht*$ht*$hr*$hr))] puts "D4: $d4 RET: $Pt" } #debug 1 return $Pt } # /* # * Friis free space equation: # * # * Pt * Gt * Gr * (lambda^2) # * P = -------------------------- # * (4 * pi * d)^2 * L # */ # from /mobile/tworayground.cc: # # TwoRayGround formula # power = Pt * Gt * Gr * (hr * hr * ht * ht) / (d * d * d * d * L); # # > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Ashish Sangwan > Sent: quinta-feira, 13 de Julho de 2006 14:59 > To: Q. R. Iqbal > Cc: ns-users@ISI.EDU > Subject: Re: [ns] Transmission and Interference Range > > > Hi , > > I didnot know about these three transmit power levels. Thanks Iqbal for > that. > I wanted to have Interference Range(Carrier Sense Range) to be twice the > Communication Range. So I achieved by calculating CSThresh_ value by > following formula > Pt * Gt * Gr * (hr * hr * ht * ht) / {(Required interference range) ^ 4} > > --Ashish > > On 7/13/06, Q.R.Iqbal <[EMAIL PROTECTED]> wrote: > > > > Hi there > > > > I think there is no other cleaner or easiar way to do that unless you > > modify the code. > > > > One thing you have to be aware of is that by modifying the transmission > > range, you are only changing the receiver threshold, A distance from > > which a receiver can receive. > > > > Again there are three different transmit power levels that are given for > > the wavelan Modem > > > > 40m 8.5872e-4 > > 100m 7.214e-3 > > 250m 02818 > > > > Maybe you need to use one of these parameters, the closest to your > > required transmission range and then calculate the RXthreshold values, > to > > get a better result. > > Also you need to be aware of CSthreshold,. If you are limiting the > node's > > transmission range to 40m or 100m or any value, the CSthreshold value, > > will still be very large, about 550m by default, you might also want to > > tweak that parameter to see if this improves your results > > > > I hope this helps > > > > > Hi, > > > > > > Can you tell me a clean way to change transmission and interference > > ranges > > > in ns-2? > > > I tried the threshold program given ~ns/indep-utils/propagation/ but > > that > > > somehow is not giving correct values. > > > > > > Regards, > > > -- > > > Ashish Sangwan > > > B.Tech, Computer Science & Engineering > > > IIT Delhi > > > > > > -- > > > I do know everything, just not all at once. It's a virtual memory > > problem. > > > > > > > > > Kind regards > > > > Qasim Raza Iqbal > > PhD Candidate, > > ACNRG Lab N504, Office N505 > > Adaptive Communications Networks Research Group, > > School of Engineering And Applied Science > > Aston University > > Birmingham B4 7ET > > United Kingdom > > http://www.ee.aston.ac.uk/research/acrg/index.html > > > > > >