import numpy as np
def freq_domain_xcorr(signal1, signal2):
# 频率域互相关
n = len(signal1) + len(signal2) - 1
freq_domain_xcorr_result = np.fft.ifft(
np.fft.fft(signal1, n=n) * np.conj(np.fft.fft(signal2, n=n))
)
return freq_domain_xcorr_result.real
# 示例信号
signal1 = np.array([1, 2, 3, 4])
signal2 = np.array([0, 1, 0.5, 2])
# 计算频率域互相关
freq_domain_xcorr_result = freq_domain_xcorr(signal1, signal2)
print(freq_domain_xcorr_result)