-
Notifications
You must be signed in to change notification settings - Fork 5
/
weighted.py
70 lines (58 loc) · 1.74 KB
/
weighted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Author: Eric Bezzam
# Date: July 15, 2016
"""
Modified by Kuan-Lin Chen on Sat Mar 5 2022
"""
import numpy as np
from pyroomacoustics.doa.music import *
class Weighted(MUSIC):
def __init__(
self,
L,
fs,
nfft,
c=343.0,
num_src=1,
mode="far",
r=None,
azimuth=None,
colatitude=None,
frequency_normalization=False,
**kwargs
):
super().__init__(
L,
fs,
nfft,
c,
num_src,
mode,
r,
azimuth,
colatitude,
frequency_normalization,
**kwargs
)
def _process(self, X):
self.Pssl = np.zeros((self.num_freq, self.grid.n_points))
C_hat = self._compute_correlation_matricesvec(X)
self.Pssl = self._compute_spatial_spectrumvec(C_hat)
if self.frequency_normalization:
self._apply_frequency_normalization()
self.grid.set_values(np.squeeze(np.sum(self.Pssl, axis=1) / self.num_freq))
def _compute_spatial_spectrumvec(self, cross):
mod_vec = np.transpose(
np.array(self.mode_vec[self.freq_bins, :, :]), axes=[2, 0, 1]
)
denom = np.matmul(
np.conjugate(mod_vec[..., None, :]), np.matmul(cross, mod_vec[..., None])
)
return abs(denom[..., 0, 0])
def _compute_spatial_spectrum(self, cross, k):
P = np.zeros(self.grid.n_points)
for n in range(self.grid.n_points):
Dc = np.array(self.mode_vec[k, :, n], ndmin=2).T
Dc_H = np.conjugate(np.array(self.mode_vec[k, :, n], ndmin=2))
denom = np.dot(np.dot(Dc_H, cross), Dc)
P[n] = abs(denom)
return P