import scipy as sp
import scipy.io as sio
import numpy as np
import matplotlib.pyplot as plt
def MAC(a,b):
"""
Compute MAC similatiry criterion between complex vectors a and b
Parameters
----------
a : np.array, 1 or 2D (2nd dimension should be frequency)
Complex vector.
b : np.array, 1 or 2D (2nd dimension should be frequency)
Complex vector.
Returns
-------
MAC_out : np.array, 1D
MAC similartity (0<MAC<1).
"""
if len(a.shape) == 1:
MAC_out = np.abs(np.inner(a,np.conj(b)))**2/(np.abs(np.inner(a,np.conj(a)))*np.abs(np.inner(b,np.conj(b))))
elif len(a.shape) == 2:
MAC_out = np.zeros(a.shape[1],dtype = float)
for fi in range(a.shape[1]):
MAC_out[fi] = np.abs(np.inner(a[:,fi],np.conj(b[:,fi])))**2/(np.abs(np.inner(a[:,fi],np.conj(a[:,fi])))*np.abs(np.inner(b[:,fi],np.conj(b[:,fi]))))
return MAC_out
def VP(fPos, sPos, fe, se, vpPos):
""" Implement Virtual Point transformation for single connection
Args:
H (3D np.array (M x N x f), dtype=complex):
FRF matrix
fPos (2D np.array (N x 3), dtype=real):
x, y, z coordinates of force positions
sPos (2D np.array (M x 3), dtype=real):
x, y, z coordinates of sensor positions
fe (2D np.array (N x 3), dtype=real):
ex, ey, ez orientation of applied forces
se (2D np.array (M x 3), dtype=real):
ex, ey, ez orientation of sensors
vpPos (1D np.array (3 x 1), dtype=real):
x, y, z position of virtual points
"""
fRPos = fPos-vpPos # Force position relative to VP
sRPos = sPos-vpPos # Sensor position relative to VP
Rs = np.zeros((sPos.shape[0], 6))
for si in range(sPos.shape[0]):
# Build transformation matrix for each response point
Rsi = np.array([[1, 0, 0, 0, sRPos[si, 2], -sRPos[si, 1]],
[0, 1, 0, -sRPos[si, 2], 0, sRPos[si, 0]],
[0, 0, 1, sRPos[si, 1], -sRPos[si, 0], 0]])
# Sensor displacement due to Virtual Point displacement
# (1x6 vector for each sensor):
Rs[si, :] = se[si, :]@Rsi
Ts = np.linalg.pinv(Rs)
Rf = np.zeros((fPos.shape[0], 6))
for fi in range(fPos.shape[0]):
# Build transformation matrix for each response point
Rfi = np.array([[1, 0, 0, 0, fRPos[fi, 2], -fRPos[fi, 1]],
[0, 1, 0, -fRPos[fi, 2], 0, fRPos[fi, 0]],
[0, 0, 1, fRPos[fi, 1], -fRPos[fi, 0], 0]])
# Sensor displacement due to Virtual Point displacement
# (1x6 vector for each sensor):
Rf[fi, :] = Rfi.T@fe[fi, :].T
Tf = np.linalg.pinv(Rf)
return Ts, Tf, Rs, Rf
# Load data
nf = 27
nr = 26
temp = sio.loadmat('Data/Test1/f1.mat')
f = temp["Data1_X_MT_FRF_H1_10Xplus_29Zplus_Imag"]
H = np.zeros((f.shape[0], nr, nf), dtype=complex)
COH = np.zeros((f.shape[0], nr, nf), dtype=complex)
for i in range(1,nf):
temp = sio.loadmat('Data/Test1/f' + str(i) + '.mat')
for j in range(1,nr):
H[:,j-1,i-1] = (temp['Data1_MT_FRF_H1_' + str(j) + 'Xplus_29Zplus_Real'] + 1j*temp['Data1_MT_FRF_H1_' + str(j) +'Xplus_29Zplus_Imag']).squeeze()
COH[:,j-1,i-1] = (temp['Data1_MT_Coherence_' + str(j) + 'Xplus_29Zplus'] + 1j*temp['Data1_MT_Coherence_' + str(j) +'Xplus_29Zplus']).squeeze()
# Built TMs
E1 = np.array([[0, 0, -1],[1, 0, 0],[0, -1, 0]])
E2 = np.array([[0, -1, 0],[0, 0, 1],[-1, 0, 0]])
E3 = np.array([[1, 0, 0],[0, 1, 0],[0, 0, 1]])
R1 = np.array([-15, -25, 20])*1e-3
R2 = np.array([-25, 15, 20])*1e-3
R3 = np.array([15, 25, 5])*1e-3
sPos = np.stack((R1,R1,R1,R2,R2,R2,R3,R3,R3))
se = np.vstack((E1,E2,E3))
e1 = np.array([0,0,-1])
e2 = np.array([0,0,-1])
e3 = np.array([0,0,-1])
e4 = np.array([0,0,-1])
e5 = np.array([0,1, 0])
e6 = np.array([0,-1,0])
e7 = np.array([0,-1,0])
e8 = np.array([-1,0,0])
e9 = np.array([-1,0,0])
r1 = np.array([-15, 0, 35])*1e-3
r2 = np.array([0, 15, 35])*1e-3
r3 = np.array([15, 0, 35])*1e-3
r4 = np.array([0, -15, 35])*1e-3
r5 = np.array([15, -20, 20])*1e-3
r6 = np.array([-15, 20, 20])*1e-3
r7 = np.array([15, 20, 20])*1e-3
r8 = np.array([20, 15, 25/2])*1e-3
r9 = np.array([20, -15, 25/2])*1e-3
fe = np.stack((e1,e2,e3,e4,e5,e6,e7,e8,e9))
fPos = np.stack((r1,r2,r3,r4,r5,r6,r7,r8,r9))
Ts_c, Tf_c, Rs, Rf = VP(fPos, sPos, fe, se, np.array([0,0,0]))
Tr = sp.linalg.block_diag(Ts_c,np.eye(6),np.eye(11))
Tf = sp.linalg.block_diag(Tf_c,np.eye(18))
Hvp = Tr@H@Tf.T
Yba_all = Hvp[:,12:,:6]@np.linalg.inv(Hvp[:,:6,:6])@Hvp[:,:6,6:]
Yba_xyz = Hvp[:,12:,:3]@np.linalg.inv(Hvp[:,:3,:3])@Hvp[:,:3,6:]
Yba_zαβ = Hvp[:,12:,2:5]@np.linalg.inv(Hvp[:,2:5,2:5])@Hvp[:,2:5,6:]
ICC_all = np.zeros((f.shape[0]),dtype=complex)
ICC_xyz = np.zeros((f.shape[0]),dtype=complex)
ICC_zαβ = np.zeros((f.shape[0]),dtype=complex)
for i in range(f.shape[0]):
ICC_all[i] = MAC(Hvp[i, 12:, 6:].flatten(), Yba_all[i,:,:].flatten())
ICC_xyz[i] = MAC(Hvp[i, 12:, 6:].flatten(), Yba_xyz[i,:,:].flatten())
ICC_zαβ[i] = MAC(Hvp[i, 12:, 6:].flatten(), Yba_zαβ[i,:,:].flatten())
Uc = Hvp[:,:6,6:]
Ua = Hvp[:,6:12,6:]
Ub = Hvp[:,12:,6:]
T = Ub @ np.linalg.pinv(np.concat((Ua,Uc),axis=1)) # Transmissibility matrix - constrained at interface
Tba = T[:, :, :6] # Sub-transmissibility a->b
Tba_= Ub @ np.linalg.pinv(Ua) #
TICC_all = 1 - 2 * np.linalg.norm(Tba, axis=(1, 2),ord='fro')**2 / (np.linalg.norm(Tba, axis=(1, 2),ord='fro')**2 + np.linalg.norm(Tba_, axis=(1, 2), ord='fro')**2)
Uc_xyz = Hvp[:,:3,6:]
T = Ub @ np.linalg.pinv(np.concat((Ua,Uc_xyz),axis=1)) # Transmissibility matrix - constrained at interface
Tba = T[:, :, :6] # Sub-transmissibility a->b
Tba_= Ub @ np.linalg.pinv(Ua) #
TICC_xyz = 1 - 2 * np.linalg.norm(Tba, axis=(1, 2),ord='fro')**2 / (np.linalg.norm(Tba, axis=(1, 2),ord='fro')**2 + np.linalg.norm(Tba_, axis=(1, 2), ord='fro')**2)
Uc_zαβ = Hvp[:,2:5,6:]
T = Ub @ np.linalg.pinv(np.concat((Ua,Uc_zαβ),axis=1)) # Transmissibility matrix - constrained at interface
Tba = T[:, :, :6] # Sub-transmissibility a->b
Tba_= Ub @ np.linalg.pinv(Ua) #
TICC_zαβ = 1 - 2 * np.linalg.norm(Tba, axis=(1, 2),ord='fro')**2 / (np.linalg.norm(Tba, axis=(1, 2),ord='fro')**2 + np.linalg.norm(Tba_, axis=(1, 2), ord='fro')**2)