Python中的GCC-PHAT互相关 [英] GCC-PHAT cross correlation in Python

查看:532
本文介绍了Python中的GCC-PHAT互相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python中实现GCC-PHAT.

I am trying to implement GCC-PHAT in python.

该方法类似于以下两个链接: link1 link2

The approach is similar to the following two links: link1 and link2

似乎GCC-PHAT和使用FFT的正常互相关之间的唯一区别是幅度的除法.

It seems the only difference between GCC-PHAT and normal cross-correlation using FFT is the division by the magnitude.

这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import rfft, irfft, fftfreq, fft, ifft

def xcorr_freq(s1,s2):
    pad1 = np.zeros(len(s1))
    pad2 = np.zeros(len(s2))
    s1 = np.hstack([s1,pad1])
    s2 = np.hstack([pad2,s2])
    f_s1 = fft(s1)
    f_s2 = fft(s2)
    f_s2c = np.conj(f_s2)
    f_s = f_s1 * f_s2c
    denom = abs(f_s)
    denom[denom < 1e-6] = 1e-6
    f_s = f_s / denom  # This line is the only difference between GCC-PHAT and normal cross correlation
    return np.abs(ifft(f_s))[1:]

我已经通过注释掉fs = fs / denom进行了检查.对于宽带信号,该函数产生的结果与普通互相关的结果相同.

I have checked by commenting out fs = fs / denom The function produces the same result as normal cross correlation for a wide band signal.

这是一个示例测试代码,该代码显示了上面的GCC-PHAT代码比正常互相关的效果更差:

Here is a sample test code which shows the GCC-PHAT code above performs worse than normal cross-correlation:

LENG = 500
a = np.array(np.random.rand(LENG))
b = np.array(np.random.rand(LENG))
plt.plot(xcorr_freq(a,b))
plt.figure()
plt.plot(np.correlate(s1,s2,'full'))

这是GCC-PHAT的结果:

Here is the result with GCC-PHAT:

这是具有正常互相关的结果:

Here is the result with normal cross-correlation:

由于GCC-PHAT应该为宽带信号提供更好的互相关性能,所以我知道我的代码有问题.任何帮助,我们将不胜感激!

Since GCC-PHAT should give better cross-correlation performance for wide band signal, I know there is something wrong with my code. Any help is very appreciated!

推荐答案

不要只用噪音来喂食GCC-PHAT.给它一个信号+噪音.检查GCC-PHAT和未加权相关如何随信噪比的变化进行比较.

do not feed the GCC-PHAT with only noise. Give it a signal + noise. Check how GCC-PHAT and unweighted correlation compare as signal-to-noise ratio varies.

这篇关于Python中的GCC-PHAT互相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆