You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import arraymancer
import fftw3
import std/complex
let shape = @[6]
# Use dummy tensor to create plan
var
dummy_input = newTensor[Complex64](shape)
dummy_output = newTensor[Complex64](shape)
var FFT: fftw_plan = fftw_plan_dft(dummy_input, dummy_output, FFTW_FORWARD, FFTW_ESTIMATE)
var inverseFFT: fftw_plan = fftw_plan_dft(dummy_input, dummy_output, FFTW_BACKWARD, FFTW_ESTIMATE)
# Allocate output Tensor
var inputRe = [1.0,2.0,3.0,4.0,5.0,6.0].toTensor.reshape(1, 6)
var inputIm = [0.0,0.0,0.0,0.0,0.0,0.0].toTensor.reshape(1, 6)
var input = map2_inline(inputRe, inputIm):
complex64(x, y)
# initialize output tensors
var output = newTensor[Complex64](shape)
var output_fft = newTensor[Complex64](shape)
var output_ifft = newTensor[Complex64](shape)
fftw_execute_dft(FFT, input, output) # Execute FFT
var outConj = conjugate(output)
# calculate the power of the signal by elementwise multiplication
var sigMag = output*.outConj
# execute inverse fourier transform
fftw_execute_dft(inverseFFT, sigMag, output_ifft) # Execute a plan on new Tensor
fftw_execute_dft(FFT, sigMag, output_fft) # Execute a plan on new Tensor
echo(output_ifft)
echo(output_fft)
Tensor[Complex[system.float64]] of shape "[6]" on backend "Cpu"
(546.0, 0.0) (456.0, 0.0) (402.0, 0.0) (384.0, 0.0) (402.0, 0.0) (456.0, 0.0)
Tensor[Complex[system.float64]] of shape "[6]" on backend "Cpu"
(546.0, 0.0) (456.0, 0.0) (402.0, 0.0) (384.0, 0.0) (402.0, 0.0) (456.0, 0.0)
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: