I want to linearly interpolate some metrics that are captured at times that fluctuate, to fixed timing intervals.
let original_times:[Double] = [0.0,1.3,2.2,3.4,4.2,5.5,6.6,7.2,8.4,9.5,10.0]
let metric_1:[Double] = [4,3,6,7,4,5,7,4,2,7,2]
let wanted_times:[Double] = [0,1,2,3,4,5,6,7,8,9,10]
//linearly resample metric_1 (with corresponding sampling times 'original_times') to fixed time interval times 'wanted_times'
Accelerate
offers vDSP_vlint but I'm struggling to figure out how to implement it for my application.
func vDSP_vlint(_ __A: UnsafePointer<Float>, _ __B: UnsafePointer<Float>, _ __IB: vDSP_Stride, _ __C: UnsafeMutablePointer<Float>, _ __IC: vDSP_Stride, _ __N: vDSP_Length, _ __M: vDSP_Length)
I don't understand the math you want to do 100%, but I do understand how to use Accelerate. I created a function which makes it easier to call this Accelerate function and shows you how it works.
EDIT: Alright, I wrapped my head around your problem, I understand now what you want to do. Was pretty fun to do, I came up with this:
The vars are necessary for Accelerate. I don't know how
calculateB
could be done with Accelerate, I mean it's possible I think, but it's a pain to search for the correctvDSP
functions...Another solution to the problem, 100% Accelerate:
Here's another solution without using any of the Accelerate stuff
And then you can run it by just doing the following:
This example above will output: