Skip to content

Instantly share code, notes, and snippets.

@danieljfarrell
Created April 19, 2016 15:33
Show Gist options
  • Select an option

  • Save danieljfarrell/1f1431658dc529beda87a395fe5428d9 to your computer and use it in GitHub Desktop.

Select an option

Save danieljfarrell/1f1431658dc529beda87a395fe5428d9 to your computer and use it in GitHub Desktop.
Experimental reference filtering.
def remove_reference_signal_with_experimental_reference_method_with_extended_FFT(
signal,
reference,
optical_delay_spacing,
ref_calibration=None):
"""Removes reference signal using extended FFT method."""
# transform reference signal to frequency domain
t_points = reference.shape[0]
ref_spec = np.fft.rfft(reference, reference.shape[0]*2)
signal_spec = np.fft.rfft(signal, signal.shape[0]*2)
freq = freq_from_optical_delay(optical_delay_spacing, len(ref_spec))
# apply filter in frequency domain
deconv_spec = signal_spec / ref_spec
# ref_calibration is a data array or None (i.e. Python null data type)
print('Removing reference signal with reference...')
if ref_calibration is not None and len(ref_calibration) > 1:
# Get the y axis
cal = ref_calibration['spec']
# Interpolate the real data from cal onto the current frequency domain grid
real_cal = np.interp(freq,
ref_calibration['freq'],
cal.real,
cal[0].real,
cal[-1].real)
# Interpolate the imag data from cal onto the current frequency domain grid
imag_cal = np.interp(freq,
ref_calibration['freq'],
cal.imag,
cal[0].imag,
cal[-1].imag)
# Apply calibration by multiplication with the interpolated complex array
deconv_spec *= (real_cal + 1j*imag_cal)
# Rather than apply filtering parameter here we
# using the reference signal as the filter.
deconv_spec *= ref_spec
deconv_spec[0] = 0
deconv = np.fft.irfft(deconv_spec, 2*t_points)
deconv = deconv[0:t_points]
return deconv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment