⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 patch.mobile

📁 ns2网络仿真中超宽带的实现
💻 MOBILE
📖 第 1 页 / 共 5 页
字号:
diff -Naur --ignore-matching-lines='Version Date' --ignore-matching-lines=cvsroot --ignore-matching-lines=CVSROOT /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mobile/mod_codedppm.cc mobile/mod_codedppm.cc--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mobile/mod_codedppm.cc	1970-01-01 01:00:00.000000000 +0100+++ mobile/mod_codedppm.cc	2004-02-17 12:09:40.000000000 +0100@@ -0,0 +1,227 @@+/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */++/* ======================================================================+   Pulse Position Modulation with Punctured Codes+   ====================================================================== */++// XXX hack: all these parameters depend on Tc = 0.7ns, but Tc actually depends on PHY::frequency_range_+// --> use fixed FREQUENCY_RANGE for now (this assume Durisi's Tf actually has 100 slots)++// P_DELTA is delta * frequency range from Durisi+#define P_DELTA 0.1984+#define GAMMA -0.6183++#define PPM_TABLE_ROWS 41++#include "mod_codedppm.h"+#include <math.h>+#include <stdlib.h>+#include <random.h>+#include "modulation.h"+#include "packet.h"+#include "mac.h"+#include "mac-ifcontrol.h"++#include "ppm.cc"++double CodedPPM::PPM_erasure_table[MODULATION_NUM_CODES] = {+        {1.000000},+        {0.250000},+        {0.150000},+        {0.125000},+        {0.100000},+        {0.090000},+        {0.090000},+        {0.080000},+        {0.750000},+        {0.750000},+        {0.750000},+        {0.070000},+        {0.070000},+        {0.070000},+        {0.070000},+        {0.070000},+        {0.067500},+        {0.067500},+        {0.067500},+        {0.065000},+        {0.065000},+        {0.065000},+        {0.065000},+        {0.065000},+        {0.060000},+        {0.060000},+        {0.060000},+        {0.060000},+        {0.060000},+        {0.060000}+};++double CodedPPM::PPM_rate_table[MODULATION_NUM_CODES] = {+ 8.0/9.0,+ 8.0/10.0,+ 8.0/11.0,+ 8.0/12.0,+ 8.0/13.0,+ 8.0/14.0,+ 8.0/15.0,+ 8.0/16.0,+ 8.0/17.0,+ 8.0/18.0,+ 8.0/19.0,+ 8.0/20.0,+ 8.0/21.0,+ 8.0/22.0,+ 8.0/23.0,+ 8.0/24.0,+ 8.0/25.0,+ 8.0/26.0,+ 8.0/27.0,+ 8.0/28.0,+ 8.0/29.0,+ 8.0/30.0,+ 8.0/31.0,+ 8.0/32.0,+ 1.0/5.0,+ 1.0/6.0,+ 1.0/7.0,+ 1.0/8.0,+ 1.0/9.0,+ 1.0/10.0+};++/*+static double PPM_rate_table[MODULATION_NUM_CODES] = {+	8.0/9.0, 4.0/5.0,  2.0/3.0,  4.0/7.0,+	1.0/2.0, 4.0/9.0,  4.0/10.0, 4.0/11.0,+	1.0/3.0, 4.0/13.0, 2.0/7.0,  4.0/15.0,+	1.0/4.0+};+*/++static class ModulationCodedPPMClass: public TclClass {+public:+        ModulationCodedPPMClass() : TclClass("Modulation/CodedPPM") {}+        TclObject* create(int, const char*const*) {+                return (new CodedPPM);+        }+} class_ModulationCodedPPM;++double CodedPPM::SNRtoBER(double SNR, int code)+{+	double ber = 1.0;+	int row = 0;++	// outside table+	if (SNR < PPM_ber_table[code][0][0])+		return 1.0;++	// determine table row (SNR)+	while ((PPM_ber_table[code][row][0] < SNR) && (row < PPM_TABLE_ROWS))+		++row;++	// determine success for each of the codes with the given SNR+	if (row == 0)+		ber = PPM_ber_table[code][0][1];+	else if (row == PPM_TABLE_ROWS)+		ber = PPM_ber_table[code][PPM_TABLE_ROWS-1][1];+	else // linear interpolation+		ber = PPM_ber_table[code][row-1][1] + +			(PPM_ber_table[code][row-1][1] - PPM_ber_table[code][row][1]) *+			(SNR - PPM_ber_table[code][row-1][0]) / (PPM_ber_table[code][row-1][0] - PPM_ber_table[code][row][0]);+	return ber;+}++int CodedPPM::calcBestCode(int code, double SNR, double x, int pktsize) {+	double per, ber;+	int best = code;++	do {+		--best;+		if (best < 0)+			break;+		ber = SNRtoBER(SNR, best);+		per = 1.0 - pow(1 - ber, pktsize * 8.0);+	} while (x >= per);+	// the last one didn't work so the best code is the next more powerful one+	best += 1;+	if (best > MODULATION_NUM_CODES - 1)+		best = MODULATION_NUM_CODES - 1;+	return best;+}++int CodedPPM::BitError(double receivedPower, double interferencePower, double noisePower, Packet* p, double erasure)+{+	hdr_cmn *hdr = HDR_CMN(p);++	double bitErrorProbability, packetErrorProbability;+	int numErrors;+	int code = HDR_MAC_IFControl(p)->code_id_;++	//XXX: interferencePower multiplied by 1/Tf (== bitrate_) at PHY (only for CodedPPM)+	double SNR = receivedPower / (P_DELTA * (1.0 - GAMMA)*(1.0 - GAMMA) * interferencePower + 2 * noisePower * (1.0 - GAMMA));++	// HACK for CACDMA (margin *=2  ~3dB)+	// power at rx = (min_SNR * margin)(N+I)    (with min_SNR = 4dB)+	// at sender /= channel gain+	cacdma_power_ = ((pow(10,4.0/10.0) * 2) * (receivedPower/SNR)) / (receivedPower / p->txinfo_.getTxPr());++	// convert to dB+	SNR = 10 * log10(SNR);++	// shift due to erasures+	SNR -= erasure;++	//double y = sqrt(SNR/2);+	//double bitErrorProbability = 0.5*erfc(y);++	bitErrorProbability = SNRtoBER(SNR, code);+	packetErrorProbability = 1.0 - pow(1 - bitErrorProbability, hdr->size() * 8.0);++	double x = Random::uniform();+	if (x < packetErrorProbability) {+		numErrors = 1;+		best_code_ = -1; // "best code" invalid since packet had errors+	} else {+		numErrors = 0;+		best_code_ = calcBestCode(code, SNR, x, hdr->size());+	}++	struct hdr_mac *mh = HDR_MAC(p); // XXX only for debugging+	printf("%.9f %i -> %i (no. %i) SNR %.3f [%.2f / (%.2f + %.2f) dBm], BER %.3e PER %.4f (%i bytes) -> %s PPM code %i best %i\n",+	       Scheduler::instance().clock(), mh->macSA_, mh->macDA_, hdr->uid(), SNR, +	       10.0 * log10(receivedPower) + 30, 10.0 * log10(interferencePower) + 30, 10.0 * log10(noisePower) + 30,+	       bitErrorProbability, packetErrorProbability, hdr->size(),+	       numErrors == 0 ? "ok" : "err", code, best_code_);++	return numErrors;+}++/* not used! */+int CodedPPM::BitError(double Pr)+{+	double Pe;			// probability of error+	double x;+	int nbit = 0;			// number of bit errors tolerated++	if(nbit == 0) {+		Pe = 0; //ProbBitError(Pr);+	}+	else {+		Pe = 0; //ProbBitError(Pr, nbit);+	}++	// quick check+	if(Pe == 0.0)+		return 0;		// no bit errors++	// scale the error probabilty+	Pe *= 1e3;++	x = (double)(((int)Random::uniform()) % 1000);++	if(x < Pe)+		return 1;		// bit error+	else+		return 0;		// no bit errors+}diff -Naur --ignore-matching-lines='Version Date' --ignore-matching-lines=cvsroot --ignore-matching-lines=CVSROOT /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mobile/mod_codedppm.h mobile/mod_codedppm.h--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mobile/mod_codedppm.h	1970-01-01 01:00:00.000000000 +0100+++ mobile/mod_codedppm.h	2004-02-17 12:09:42.000000000 +0100@@ -0,0 +1,43 @@+/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */++#ifndef __mod_codedppm_h__+#define __mod_codedppm_h__++#include "packet.h"+#include "modulation.h"+#include <assert.h>++#define MODULATION_NUM_CODES 30+#define PPM_CONVERSION_COEFFICIENT (1.0/2.8)++class CodedPPM : public Modulation {++public:+	virtual int BitError(double Pr);+	virtual int BitError(double receivedPower, double interferencePower, double noisePower, Packet* p) {+		return BitError(receivedPower, interferencePower, noisePower, p, 0);+	}+	virtual int BitError(double receivedPower, double interferencePower, double noisePower, Packet* p, double erasure);+	inline int bestCode() { return best_code_; }+	inline double CACDMApower() { return cacdma_power_; }+	inline double ppm_erasure(int code) { +		assert((code >= 0) && (code < MODULATION_NUM_CODES));+		return PPM_CONVERSION_COEFFICIENT * PPM_erasure_table[code];+	}+	inline double ppm_rate(int code) { +		assert((code >= 0) && (code < MODULATION_NUM_CODES));+		return PPM_rate_table[code];+	}++protected:+	int calcBestCode(int code, double SNR, double x, int pktsize);+	double SNRtoBER(double SNR, int code);++	int best_code_;+	double cacdma_power_;+	static double PPM_rate_table[];+	static double PPM_erasure_table[];+};++#endif /* __mod_codedppm_h__ */+diff -Naur --ignore-matching-lines='Version Date' --ignore-matching-lines=cvsroot --ignore-matching-lines=CVSROOT /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mobile/modulation.cc mobile/modulation.cc--- /home/rmerz/NS/ns-allinone-2.26/ns-2.26/mobile/modulation.cc	2003-02-26 23:08:59.000000000 +0100+++ mobile/modulation.cc	2004-01-30 16:22:59.000000000 +0100@@ -36,8 +36,45 @@ #include <math.h> #include <stdlib.h> #include <random.h>-//#include <debug.h>-#include <modulation.h>+//#include <rng.h>+#include "modulation.h"+#include "packet.h"+#include "mac.h"+#include "mac-802_11.h"++// static class ModulationClass: public TclClass {+// public:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -