def executeAlgorithm(self): self.predictedData = [] for index, sample in enumerate(self.inputData): if sample.time < self.predictionInterval: # Set initial values predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = Vector() self.predictedData.append(predictionSample) else: shift = index - self.predictionInterval / self.samplingInterval # Calculate velocity deltaPosition = self.inputData[index].position - \ self.inputData[shift].position deltaTime = self.inputData[index].time - \ self.inputData[shift].time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector # Populate data structures predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = velocity self.predictedData.append(predictionSample)
def executeAlgorithm(self): self.predictedData = [] for index, sample in enumerate(self.inputData): if sample.time < self.predictionInterval: # Set initial values predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = Vector() self.predictedData.append( predictionSample ) else: shift = index - self.predictionInterval / self.samplingInterval # Calculate velocity deltaPosition = self.inputData[index].position - \ self.inputData[shift].position deltaTime = self.inputData[index].time - \ self.inputData[shift].time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector # Populate data structures predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = velocity self.predictedData.append( predictionSample )
def calcExtrapolationSample(self, currentSample, targetSample): deltaPosition = targetSample.position - currentSample.position deltaTime = targetSample.time - currentSample.time invDeltaTimeVector = Vector(1 / float(deltaTime), 1 / float(deltaTime), 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector extrapolationSample = PredictionSample() extrapolationSample.sample = deepcopy(currentSample) extrapolationSample.velocity = velocity return extrapolationSample
def calcExtrapolationSample(self, snapSample, targetSample): deltaPosition = targetSample.position - snapSample.position deltaTime = targetSample.time - snapSample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector extrapolationSample = PredictionSample() extrapolationSample.sample = deepcopy(snapSample) extrapolationSample.velocity = velocity return extrapolationSample
def findInterpolationSample(self, currentSample, targetSample): deltaPosition = targetSample.sample.position - \ currentSample.sample.position deltaTime = targetSample.sample.time - \ currentSample.sample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector interpolationSample = PredictionSample() interpolationSample.sample = deepcopy(currentSample.sample) interpolationSample.velocity = velocity return interpolationSample
def findInterpolationSample(self, currentSample, targetSample): deltaPosition = targetSample.position - \ currentSample.position deltaTime = targetSample.time - \ currentSample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector interpolationSample = PredictionSample() interpolationSample.sample = deepcopy(currentSample) interpolationSample.velocity = velocity return interpolationSample
def executeAlgorithm(self): self.reconstructedSignal = [] nextTimeToRecord = 0 timeDiff = self.rawSignal[0].sample.time % self.samplingInterval if timeDiff == 0: self.reconstructedSignal.append( deepcopy(self.rawSignal[0].sample) ) nextTimeToRecord = self.rawSignal[0].sample.time + \ self.samplingInterval else: change = self.samplingInterval - timeDiff newSample = Sample() newSample.time = self.rawSignal[0].sample.time + change newSample.position = deepcopy(self.rawSignal[0].sample.position) self.reconstructedSignal.append(newSample) nextTimeToRecord = newSample.time + self.samplingInterval interpolationSample = PredictionSample() interpolationSample.sample = self.reconstructedSignal[0] interpolationSample.velocity = self.rawSignal[0].velocity for index, predictionSample in enumerate(self.rawSignal): if predictionSample.sample.time == nextTimeToRecord: estimatedSample = self.calculateEstSample(interpolationSample, \ nextTimeToRecord) self.reconstructedSignal.append(estimatedSample) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(estimatedSample, \ targetSample) nextTimeToRecord = nextTimeToRecord + self.samplingInterval elif predictionSample.sample.time > nextTimeToRecord: while predictionSample.sample.time > nextTimeToRecord: estimatedSample = self.calculateEstSample(interpolationSample, \ nextTimeToRecord) self.reconstructedSignal.append(estimatedSample) nextTimeToRecord = nextTimeToRecord + self.samplingInterval if predictionSample.sample.time == nextTimeToRecord: estimatedSample = self.calculateEstSample(interpolationSample, \ nextTimeToRecord) self.reconstructedSignal.append(estimatedSample) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(estimatedSample, \ targetSample) nextTimeToRecord = nextTimeToRecord + self.samplingInterval else: targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(self.reconstructedSignal[-1], \ targetSample)
def findSnapSample(self, currentSample, estimatedSample, targetSample): deltaPosition = targetSample.sample.position - \ currentSample.sample.position deltaPosition.x *= self.snapLimit deltaPosition.y *= self.snapLimit deltaPosition.z *= self.snapLimit snapPosition = currentSample.sample.position + deltaPosition deltaPosition = targetSample.sample.position - snapPosition deltaTime = targetSample.sample.time - \ currentSample.sample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector snapSample = PredictionSample() snapSample.sample = Sample(currentSample.sample.time, snapPosition) snapSample.velocity = velocity return snapSample