def runSimulation(): totalResults = [] for file in files: print "Working on: " + file.split('/')[-2] # Initial data --------------------------------------------------------------- importer = Importer() importedData = importer.getInputData(file, samplingInterval) #PredictedData --------------------------------------------------------------- predictor = DRPredictor() predictedData = predictor.getPredictedData(importedData, predictionInterval, \ samplingInterval) for threshold in thresholds: #Transmitted packets and data --------------------------------------------- transmitter = DRTransmitter(heartbeat) transmittedPackets = transmitter.getTransmittedPackets(threshold, predictedData) reconstructor = Reconstructor() transmittedData = reconstructor.getReconstructedData(transmittedPackets) result = PartAResult() result.movementType = findMovementType(file) result.threshold = threshold result.txRate = calculateTransmissionRate(importedData, transmittedPackets) result.txError = calculateError(importedData, transmittedData) totalResults.append(result) return totalResults
def simulateSynch(): totalResults = [] for file in files: print "Working on: " + file.split('/')[-2] # Initial data --------------------------------------------------------------- importer = Importer() importedData = importer.getInputData(file, samplingInterval) #PredictedData --------------------------------------------------------------- predictor = DRPredictor() predictedData = predictor.getPredictedData(importedData, predictionInterval, \ samplingInterval) for txRate in txRates: #Transmitted packets and data --------------------------------------------- transmitter = SynchTransmitter() transmittedPackets = transmitter.getTransmittedPackets(int(txRate), predictedData) reconstructor = Reconstructor() transmittedData = reconstructor.getReconstructedData(transmittedPackets) result = PartBResult() result.movementType = findMovementType(file) result.threshold = 0 result.txRate = txRate result.txError = calculateError(importedData, transmittedData) totalResults.append(result) return totalResults
def transmitData(inputFile, logDir, predictionInterval, samplingInterval, heartbeat, drThreshold, delay, jitter, packetLoss): # Import data print "Importing data..." importer = Importer() rawInputData = importer.getInputData(inputFile, samplingInterval) exportData(logDir + "RawInputData.txt", rawInputData) # Filtering input data print "Filtering data..." samplingFreq = int(1e3 / samplingInterval) taps = 80 bands = [0.0, 10, 11, 50.0] weights = [1, 0] coefficients = scipy.signal.remez(taps, bands, weights, Hz=samplingFreq) gain = 1.0 / sum(coefficients) filteredInputData = filterData(rawInputData, logDir, "cc", samplingInterval, coefficients)[0] filteredInputData = amplifyData(filteredInputData, gain) exportData(logDir + "FilteredInputData.txt", filteredInputData) # Create the prediction vectors print "Creating the prediction vectors..." predictor = DRPredictor() predictedData = predictor.getPredictedData(filteredInputData, predictionInterval, samplingInterval) exportData(logDir + "PredictionData.txt", predictedData) # Run the transmission algorithm print "Simulating the transmission algorithm..." transmitter = DRTransmitter(heartbeat) drTxPackets = transmitter.getTransmittedPackets(drThreshold, predictedData) exportData(logDir + "DRTxPackets.txt", drTxPackets) # Simulate the transmission of the packets print "Simulating the network..." network = Network() drRxPackets = network.getReceivedPackets(drTxPackets, delay, jitter, packetLoss) exportData(logDir + "DRRxPackets.txt", drRxPackets) # Receive the packets print "Receiving the packets..." receiver = Receiver() drRxFilteredPackets = receiver.getFilteredData(drRxPackets) exportData(logDir + "DRRxData.txt", drRxFilteredPackets) return [ rawInputData, filteredInputData, predictedData, drTxPackets, drRxPackets, drRxFilteredPackets ]
def transmitData(inputFile, logDir, predictionInterval, samplingInterval, heartbeat, drThreshold, delay, jitter, packetLoss): # Import data print "Importing data..." importer = Importer() rawInputData = importer.getInputData(inputFile, samplingInterval) exportData(logDir + "RawInputData.txt", rawInputData) # Filtering input data print "Filtering data..." samplingFreq = int(1e3/samplingInterval) taps = 80 bands = [0.0, 10, 11, 50.0] weights = [1, 0] coefficients = scipy.signal.remez(taps, bands, weights, Hz=samplingFreq) gain = 1.0 / sum(coefficients) filteredInputData = filterData(rawInputData, logDir, "cc", samplingInterval, coefficients)[0] filteredInputData = amplifyData(filteredInputData, gain) exportData(logDir + "FilteredInputData.txt", filteredInputData) # Create the prediction vectors print "Creating the prediction vectors..." predictor = DRPredictor() predictedData = predictor.getPredictedData(filteredInputData, predictionInterval, samplingInterval) exportData(logDir + "PredictionData.txt", predictedData) # Run the transmission algorithm print "Simulating the transmission algorithm..." transmitter = DRTransmitter(heartbeat) drTxPackets = transmitter.getTransmittedPackets(drThreshold, predictedData) exportData(logDir + "DRTxPackets.txt", drTxPackets) # Simulate the transmission of the packets print "Simulating the network..." network = Network() drRxPackets = network.getReceivedPackets(drTxPackets, delay, jitter, packetLoss) exportData(logDir + "DRRxPackets.txt", drRxPackets) # Receive the packets print "Receiving the packets..." receiver = Receiver() drRxFilteredPackets = receiver.getFilteredData(drRxPackets) exportData(logDir + "DRRxData.txt", drRxFilteredPackets) return [rawInputData, filteredInputData, predictedData, drTxPackets, drRxPackets, drRxFilteredPackets]
def simulateADR(): totalResults = [] for file in files: print "Working on: " + file.split('/')[-2] # Initial data --------------------------------------------------------------- importer = Importer() importedData = importer.getInputData(file, samplingInterval) #PredictedData --------------------------------------------------------------- predictor = DRPredictor() predictedData = predictor.getPredictedData(importedData, predictionInterval, \ samplingInterval) for index, delay in enumerate(delays): delayList = [delay] * len(predictedData) jitter = jitters[index] jitterList = [jitter] * len(predictedData) transmitter = ADRTransmitter(heartbeat) transmittedPackets = transmitter.getTransmittedPackets(minThreshold, maxThreshold, maxDelay, maxJitter, \ delayList, jitterList, \ predictedData) reconstructor = Reconstructor() transmittedData = reconstructor.getReconstructedData(transmittedPackets) result = PartBResult() result.movementType = findMovementType(file) result.threshold = 0 result.txRate = calculateTransmissionRate(importedData, transmittedPackets) result.txError = calculateError(importedData, transmittedData) result.delay = delay result.jitter = jitter result.packetLoss = 0 totalResults.append(result) return totalResults
simulationNumber = 1 inputFile = dataRoot + movement + "/Simulation" + str(simulationNumber) + "/positionLog.txt" # Test parameters samplingInterval = 1 # Viewing parameters plotTimeDomain = True plotFreqDomain = True plotPhaseResponse = True lowerFreqBound = -30 upperFreqBound = 30 # Import data importer = Importer() data = importer.getInputData(inputFile, samplingInterval) # Split data into components time = range(0, len(data) * samplingInterval, samplingInterval) x = [] y = [] z = [] for sample in data: x.append(sample.position.x) y.append(sample.position.y) z.append(sample.position.z) # Do the fft on the signals -> output is complex number fftX = scipy.fft(x) fftY = scipy.fft(y)
delay = 150 jitter = 80 packetLoss = 0 # Viewing parameters plotTimeDomain = True plotFreqDomain = True plotPhaseResponse = True useDb = True lowerBoundTime = 17000 #17000 upperBoundTime = 22000 #22000 lowerBoundFreq = 0 upperBoundFreq = 400 for fileName in files: # Import data print "Importing data..." importer = Importer() inputData = importer.getInputData(fileName, samplingInterval) print "First: " + str(inputData[0]) print "Last: " + str(inputData[-1]) print # ---Code unfinsihed--- # Not sure how to accomplish this task # a) Stitching together different data sets seems like it would cause high frequency noise # TODO-> Look into this problem and solve if applicable to the paper
dataRoot = "/Users/fstakem/Data/Movements_5_1_08/" root = "/Users/fstakem/Research/PhD/2010_Research/OptimalFiltering/" logDir = root + "code/log/" outputDir = root + "code/output/" movement = "Stacking" inputFile = inputFile = dataRoot + movement + "/Simulation" + str( 1) + "/positionLog.txt" # Parameters for all algorithms samplingInterval = 10 numPoints = 131072 # Importing the raw data print "Importing data..." importer = Importer() rawInputData = importer.getInputData(inputFile, samplingInterval) s.exportData(logDir + "RawInputData.txt", rawInputData) # Filtering input data print "Filtering data..." samplingFreq = int(1e3 / samplingInterval) taps = 80 bands = [0.0, 10, 11, 50.0] weights = [1, 0] coefficients = scipy.signal.remez(taps, bands, weights, Hz=samplingFreq) gain = 1.0 / sum(coefficients) filteredInputData = s.filterData(rawInputData, logDir, "cc", samplingInterval, coefficients)[0] filteredInputData = s.amplifyData(filteredInputData, gain) s.exportData(logDir + "FilteredInputData.txt", filteredInputData)