jefflovejapan
jefflovejapan

Reputation: 2121

Dimension seems to be off for vDSP.convolve

I'm convolving a vector of length 35 with a kernel of length 13. From what I've read online, I should expect the length of the return value of vDSP.convolve to be 35 - 13 + 1 = 23 but the vector I'm getting back is only length 22. Is there something I might be doing wrong, or is my understanding simply incorrect?

let row: [Float] = [0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621, 0.00019952621]
let kernel: [Float] = [0.057271957, 0.2159676, 0.43973163, 0.6773025, 0.87425536, 0.9854709, 0.0, -0.87425536, -0.6773025, -0.43973163, -0.2159676, -0.057271957, -0.0]
         
let result = vDSP.convolve(row, withKernel: kernel)
XCTAssertEqual(result.count, row.count - kernel.count + 1) // fails -- 22 not equal to 23

For what it's worth, the convolution will "fill up" all 23 slots if I manually set the length of output

var output = [Float](repeating: 0, count: 23)
vDSP.convolve(row, withKernel: kernel, output: &output) // output has no 0-valued elements after the convolution

Upvotes: 1

Views: 64

Answers (0)

Related Questions