def get_pca_vector(target_psd_matrix):
"""
Returns the beamforming vector of a PCA beamformer.
:param target_psd_matrix: Target PSD matrix
with shape (..., sensors, sensors)
:return: Set of beamforming vectors with shape (..., sensors)
"""
# Save the shape of target_psd_matrix
shape = target_psd_matrix.shape
# Reduce independent dims to 1 independent dim
target_psd_matrix = np.reshape(target_psd_matrix, (-1,) + shape[-2:])
# Calculate eigenvals/vecs
eigenvals, eigenvecs = np.linalg.eigh(target_psd_matrix)
# Find max eigenvals
vals = np.argmax(eigenvals, axis=-1)
# Select eigenvec for max eigenval
beamforming_vector = np.array(
[eigenvecs[i, :, vals[i]] for i in range(eigenvals.shape[0])])
# Reconstruct original shape
beamforming_vector = np.reshape(beamforming_vector, shape[:-1])
return beamforming_vector
评论列表
文章目录