This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import metric | |
(500 * metric.byte) / (4 * metric.Mbps) | |
#0 Need floats else it rounds | |
(500 * metric.byte) / (4.0 * metric.Mbps) | |
#0.001 Notice 4.0 (float) vs 4 (int) | |
size = 500 * metric.byte | |
rate = 4 * metric.Mbps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Bandwidth-Delay Product | |
#AKA "data in flight" | |
#https://d396qusza40orc.cloudfront.net/comnetworks/lect%2F2-1-physical-overview-ink.pdf | |
import metric | |
def bandwidthDelay(rate=0.00 * metric.Mbps, propDelay = (0.00 * metric.ms), unit=metric.byte): | |
return ((float(rate) * propDelay) / unit) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Metric Units https://d396qusza40orc.cloudfront.net/comnetworks/lect%2F2-1-physical-overview-ink.pdf | |
Kbps = pow(10,3) | |
Mbps= pow(10,6) | |
Gbps = pow(10,9) | |
ms = pow(10,-3) | |
us = pow(10,-6) | |
ns = pow(10,-9) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from util import groupBy | |
_4b5bmap = {'11110':'0000', | |
'01001':'0001', | |
'11100':'1110', | |
'11101':'1111'} | |
#"are pre-determined in a dictionary and they are chosen to ensure that there will be at least two transitions per block of bits." | |
#TODO: Get the whole map from http://www.mathworks.com/matlabcentral/fileexchange/27566-4b5b-encoder-line-codificador-de-linea-4b5b/ ? | |
def translate4b5b(bits): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from util import groupBy | |
bits='010010001111' | |
def translateBits(bits): | |
translated = [int(_,2) for _ in groupBy(bits, 3)] | |
return translated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def groupBy(iterable, groupsize=3, strict=True): | |
if strict: | |
assert len(iterable)%groupsize == 0, 'Need evenly divisible' | |
return [iterable[_:_+groupsize] for _ in range(len(iterable))[::groupsize]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
#maximum *symbol* rate is 2B | |
#V signal levels; ignoring noise, max bit rate is: | |
def nyquistLimit(bandwidth=0.00, numSignalLevels=0.00): | |
B=bandwidth | |
V=numSignalLevels | |
numSamplesPerSecond = 0.5#frequency | |
numSecondsPerSample = 1/numSamplesPerSecond #1/frequency |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def shannonCapacity(bandwidth, signal=0.0, noise=0.0, snr=0.0): | |
B = bandwidth | |
S = signal | |
N = noise | |
return B* math.log((1+(snr or S/N)),2) | |
print(shannonCapacity(20, snr=1000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# - - coding: utf-8 - - | |
# This class http://www.w3.org/International/URLUTF8Encoder.java | |
# In Python | |
# To understand how | |
# 新 ("xin", 1st tone, means "new" in Mandarin) | |
# U+65B0 (Unicode codepoint http://unicode-table.com/en/search/?q=%E6%96%B0) | |
# %E6%96%B0 (URL encoding in UTF-8 http://www.url-encode-decode.com/) | |
# Interesting: Not fixed-width! "新" not same size as "T" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BalanceTotal(SuperModel): | |
#... | |
def __getstate__(self): | |
return self.js() | |
def __setstate__(self, state): |
OlderNewer