如何实现对称自相关函数?

How to implement a symmetric autocorelation function?

提问人:Thoth 提问时间:11/2/2023 最后编辑:Thoth 更新时间:11/3/2023 访问量:65

问:

我正在尝试计算这些值:

enter image description here

enter image description here

其中 是复共轭,, , 是信号长度,取范围内的值。*z[n]= exp( 1i* 2* pi* cumsum(wav_file_signal[n])/ wav_fs)t' = t + int(wav_fs/4)Nt

到目前为止,我有这个

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)中内核的一部分。

Python 信号处理

评论

0赞 Yevhen Kuzmovych 11/2/2023
请避免使用具有透明背景的图像。在深色版本的 StackOverflow 中很难阅读。
1赞 Yevhen Kuzmovych 11/2/2023
到目前为止,你尝试了什么?请参阅旅游如何提问
0赞 phydev 11/2/2023
应定义边界条件并将其应用于 。为了选择合适的边界条件,我们需要更多地了解您要解决的问题。z
0赞 Thoth 11/2/2023
我不知道如何开始。信号边缘的合理假设是什么?我们应该用零填充它还是应该避免信号的第一个元素?
1赞 phydev 11/2/2023
请编辑您的问题并添加此信息。尝试更好地将其置于上下文中。无论如何,我不认为这个问题的核心问题与编程有关,并且可能最适合另一个 SE 社区,例如计算科学、数据科学或交叉验证。

答: 暂无答案