Skip to content

Instantly share code, notes, and snippets.

@tclements
Created May 31, 2019 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tclements/d08278b96611a1bf7d6e59382b1e4fc5 to your computer and use it in GitHub Desktop.
Save tclements/d08278b96611a1bf7d6e59382b1e4fc5 to your computer and use it in GitHub Desktop.
Hilbert transform on the GPU with Julia
using GPUArrays, FFTW
"""
hilbert(x)
Computes the analytic representation of x, ``x_a = x + j
\\hat{x}``, where ``\\hat{x}`` is the Hilbert transform of x,
along the first dimension of x.
"""
function hilbert(x::GPUArray{T}) where T<:Real
N = size(x, 1)
Xf = fft(x,1)
Xf[2:div(N,2)+isodd(N),:] .*= 2
Xf[div(N,2)+isodd(N)+1:end,:] .*= 0
out = ifft(Xf,1)
return out
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment