-
Notifications
You must be signed in to change notification settings - Fork 2
/
interpolation.go
35 lines (27 loc) · 1.06 KB
/
interpolation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package gdsp
// Interpolate interpolates a real-valued signal using a discrete Fourier transform.
func Interpolate(input Vector, upsampleMultiple int) Vector {
if upsampleMultiple < 2 || len(input)%2 != 0 {
return input
}
fft := FFT(input.ToComplex())
leftHalf := fft[:len(fft)/2]
rightHalf := fft[len(fft)/2:]
paddedFFT := MakeVectorComplex(0.0, len(fft)*(upsampleMultiple-1))
paddedFFT = append(leftHalf, paddedFFT...)
paddedFFT = append(paddedFFT, rightHalf...)
return VSMulC(IFFT(paddedFFT), ComplexRI(upsampleMultiple)).Real()
}
// InterpolateC interpolates a complex-valued signal using a discrete Fourier transform.
func InterpolateC(input VectorComplex, upsampleMultiple int) VectorComplex {
if upsampleMultiple < 2 || len(input)%2 != 0 {
return input
}
fft := FFT(input)
leftHalf := fft[:len(fft)/2]
rightHalf := fft[len(fft)/2:]
paddedFFT := MakeVectorComplex(0.0, len(fft)*(upsampleMultiple-1))
paddedFFT = append(leftHalf, paddedFFT...)
paddedFFT = append(paddedFFT, rightHalf...)
return VSMulC(IFFT(paddedFFT), ComplexRI(upsampleMultiple))
}