提问人:Thoth 提问时间:11/2/2023 最后编辑:Thoth 更新时间:11/3/2023 访问量:65
如何实现对称自相关函数?
How to implement a symmetric autocorelation function?
问:
我正在尝试计算这些值:
其中 是复共轭,, , 是信号长度,取范围内的值。*
z[n]= exp( 1i* 2* pi* cumsum(wav_file_signal[n])/ wav_fs)
t' = t + int(wav_fs/4)
N
t
到目前为止,我有这个
import numpy as np
# Example usage
fs = 100 # Sample rate
Ts = 1 / fs # Time step
N = 1000 # Length of the signal
t = np.arange(0, N) * Ts # Time vector
f0 = 5 # Fundamental frequency of the signal
# Generate a noisy signal for testing
z = np.sin(2 * np.pi * f0 * t) + 0.5 * np.random.randn(N)
tau_lim = 30
taus = np.arange(-tau_lim, tau_lim + 1)
alphas = round(fs / (4 * np.max(np.abs(z))))
tau_delta = round(fs / (4 * f0))
Rx = np.zeros((len(z), len(taus)))
R_1_result = np.zeros(len(z))
R_2_result = np.zeros(len(z))
z = np.exp(1j * 2 * np.pi * alphas * np.cumsum(z) / fs)
# Circular shift function
def circular_shift(signal, shift_amount):
return np.roll(signal, shift_amount)
for i, tau in enumerate(taus):
# R_1_backward_shift = z[:len(z) - abs(tau)]
# R_1_forward_shift = z[abs(tau):]
R_1_backward_shift = circular_shift(z, - abs(tau))
R_1_forward_shift = circular_shift(z, abs(tau))
R_1_length = len(R_1_forward_shift) # R_1 and R_2 have the same length
R_1_result = R_1_forward_shift * np.conj(R_1_backward_shift)
# R_2_backward_shift = z[:len(z) - abs(tau) - tau_delta]
# R_2_forward_shift = z[abs(tau) + tau_delta:]
R_2_backward_shift = circular_shift(z, - abs(tau) - tau_delta)
R_2_forward_shift = circular_shift(z, abs(tau) + tau_delta)
R_2_length = len(R_2_forward_shift)
R_2_result = R_2_forward_shift * np.conj(R_2_backward_shift)
你能请别人评估代码的正确性吗?
R_z
实际上是等式(8)中内核的一部分。
答: 暂无答案
评论
z