[英]How to smooth interpolation of a float array into a bigger array?
I'm stuck with interpolation in Swift.我被 Swift 中的插值卡住了。 Can anyone help me with that?
任何人都可以帮助我吗?
I want to interpolate the float array (say [0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]
) into another array with some given size (for example 128 ).我想将浮点数组(例如
[0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]
)插入另一个具有给定大小(例如128 )的数组中。 I found an article ( Use Linear Interpolation to Construct New Data Points ) that shows, how to achieve this stuff.我找到了一篇文章( 使用线性插值来构造新数据点),它展示了如何实现这些东西。
There are two ways (you can see the results below, how they perform):有两种方法(您可以在下面看到结果,它们的表现如何):
vDSP_vgenp
andvDSP_vgenp
和vDSP_vlint
vDSP_vlint
进行更平滑的(但不是为了我的目的)插值The problem is both techniques don't realize my expectations, which illustrated in Screenshot 3 .问题是这两种技术都没有实现我的期望,如截图 3 所示。 How can I make my interpolated distribution smoother?
如何使插值分布更平滑? I want to see a cube-like curve .
我想看到一个立方体状的曲线。
Initial Plot:初始情节:
Linear Interpolation:线性插值:
import Accelerate
let n = vDSP_Length(128)
let stride = vDSP_Stride(1)
let values: [Float] = [0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]
let indices: [Float] = [0, 11, 23, 34, 46, 58, 69, 81, 93, 104, 116]
var result = [Float](repeating: 0, count: Int(n))
vDSP_vgenp(values, stride, indices, stride, &result, stride, n, vDSP_Length(values.count))
Smooth Interpolation:平滑插值:
import Accelerate
import AVFoundation
let n = vDSP_Length(1024)
let stride = vDSP_Stride(1)
let values: [Float] = [0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]
let denominator = Float(n) / Float(values.count - 1)
let control: [Float] = (0 ... n).map {
let x = Float($0) / denominator
return floor(x) + simd_smoothstep(0, 1, simd_fract(x))
}
var result = [Float](repeating: 0, count: Int(n))
vDSP_vlint(values, control, stride, &result, stride, n, vDSP_Length(values.count))
It seems to me that the vDSP_vqint
quadratic interpolation functions would solve the problem.在我看来,
vDSP_vqint
二次插值函数可以解决这个问题。 See the discussion at https://developer.apple.com/documentation/accelerate/1449942-vdsp_vqint .请参阅https://developer.apple.com/documentation/accelerate/1449942-vdsp_vqint 上的讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.