快速线性插值和上采样 [英] Swift Linear Interpolation and UpSampling

查看:317
本文介绍了快速线性插值和上采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一连串的指标采样不均.我想对这些指标进行线性插值和上采样,以达到特定的采样频率.我曾尝试使用Accelerate Framework和SIMD框架,但我不确定该怎么做.

I have a stream of metrics that are unevenly sampled. I want to linearly interpolate and upsample these metrics to a specific sampling frequency. I have tried to use the Accelerate Framework and the SIMD framework but I am not really sure what to do.

问题本身如下:

let original_times:[Double] = [0.0, 2.0, 3.0, 6.0, 10.0]
let original_values: [Double] = [50.0, 20.0, 30.0, 40.0, 10.0]
let new_times:[Double] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]

所以我正在寻找一种通过某种线性插值方法查找new_values的方法.

So I am looking for a way to find the new_values through some sort of linear interpolation method.

推荐答案

vDSP_vgenpD将为您完成这项工作.将原始时间和值传递给它,它将使用插值填充一个数组.例如:

vDSP_vgenpD will do the job for you. Pass it the original times and values, and it will populate an array with the interpolated values. For example:

import Accelerate

let original_times:[Double] =    [0.0,  2.0,  3.0,  6.0, 10.0]
let original_values: [Double] = [50.0, 20.0, 30.0, 40.0, 10.0]

var new_values = [Double](repeating: 0,
                          count: 11)

let stride = vDSP_Stride(1)

vDSP_vgenpD(original_values, stride,
            original_times, stride,
            &new_values, stride,
            vDSP_Length(new_values.count),
            vDSP_Length(original_values.count))

您可以使用以下方法获取时间/值元组数组:

You can get an array of time / value tuples with:

let result = new_values.enumerated().map{ return $0 }

看起来像:

这篇关于快速线性插值和上采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆