def smooth_fft(dx, spec, sigma):
"""Basic math for FFT convolution with a gaussian kernel.
:param dx:
The wavelength or velocity spacing, same units as sigma
:param sigma:
The width of the gaussian kernel, same units as dx
:param spec:
The spectrum flux vector
"""
# The Fourier coordinate
ss = rfftfreq(len(spec), d=dx)
# Make the fourier space taper; just the analytical fft of a gaussian
taper = np.exp(-2 * (np.pi ** 2) * (sigma ** 2) * (ss ** 2))
ss[0] = 0.01 # hack
# Fourier transform the spectrum
spec_ff = np.fft.rfft(spec)
# Multiply in fourier space
ff_tapered = spec_ff * taper
# Fourier transform back
spec_conv = np.fft.irfft(ff_tapered)
return spec_conv
评论列表
文章目录