#plt.plot(time_s, uExc[1], time_s, v[1], time_s, fb[1], time_s, pqrDist[1])

#%% Estimate the frequency response function
optSpec = FreqTrans.OptSpect(dftType='czt',
                             freqRate=freqRate_rps,
                             smooth=('box', 3),
                             winType=('tukey', 0.0),
                             detrendType='Linear',
                             interpType='linear')

# Excited Frequencies per input channel
optSpec.freq = freqChan_rps

# FRF Estimate
freq_rps, Teb, Ceb, Pee, Pbb, Peb = FreqTrans.FreqRespFuncEst(
    uExc, fb, optSpec)
_, Tev, Cev, _, Pvv, Pev = FreqTrans.FreqRespFuncEst(uExc, v, optSpec)

freq_hz = freq_rps * rps2hz

# Form the Frequency Response, T = Teb @ Tev^-1
T = np.zeros_like(Tev, dtype=complex)
C = np.zeros_like(Tev, dtype=float)

for i in range(T.shape[-1]):
    T[..., i] = (Teb[..., i].T @ np.linalg.inv(Tev[..., i].T)).T

sigmaNom_mag, _ = FreqTrans.Sigma(T)  # Singular Value Decomp

# Coherence
C = Ceb
예제 #2
0
freqGap_rps = optSpec.freq.flatten()[0:-1] + 0.5 * np.diff(
    optSpec.freq.flatten())
optSpec.freqNull = freqGap_rps
optSpec.freqNullInterp = True

# FRF Estimate
freq_rps = []
freq_hz = []
T = []
TUnc = []
C = []
for iSeg, seg in enumerate(oDataSegs):

    freq, Tey, Cey, Pee, Pyy, Pey, TeyUnc, Pee_N, Pyy_N = FreqTrans.FreqRespFuncEstNoise(
        eList[iSeg], outList[iSeg], optSpec)
    freq, Teu, Ceu, _, Puu, Peu = FreqTrans.FreqRespFuncEst(
        eList[iSeg], uList[iSeg], optSpec)

    # Form the Frequency Response
    freq_hz = freq * rps2hz

    # Form the Frequency Response
    T_seg = np.zeros_like(Tey)
    TUnc_seg = np.zeros_like(Tey)

    for i in range(T_seg.shape[-1]):
        T_seg[..., i] = (Tey[..., i] @ np.linalg.inv(Teu[..., i]))
        TUnc_seg[..., i] = (TeyUnc[..., i] @ np.linalg.inv(Teu[..., i]))

    T.append(T_seg)
    TUnc.append(np.abs(TUnc_seg))
    C.append(Cey)
예제 #3
0
#%% Estimate the frequency response function
# Define the excitation frequencies
freqRate_hz = 50
freqRate_rps = freqRate_hz * hz2rps
optSpec = FreqTrans.OptSpect(dftType = 'czt', freqRate = freqRate_rps, smooth = ('box', 3), winType = ('tukey', 0.2), detrendType = 'Linear')

# Excited Frequencies per input channel
optSpec.freq = np.asarray(freqExc_rps)

# FRF Estimate
T = []
C = []
for iSeg, seg in enumerate(oDataSegs):

    freq_rps, Teb, Ceb, Pee, Pbb, Peb = FreqTrans.FreqRespFuncEst(vExcList[iSeg], vFbList[iSeg], optSpec)
    _       , Tev, Cev, _  , Pvv, Pev = FreqTrans.FreqRespFuncEst(vExcList[iSeg], vCmdList[iSeg], optSpec)

    freq_hz = freq_rps * rps2hz

    # Form the Frequency Response
    T_seg = np.empty_like(Tev)

    for i in range(T_seg.shape[-1]):
        T_seg[...,i] = Teb[...,i] @ np.linalg.inv(Tev[...,i])


    T.append( T_seg )

#    C.append(Cev)
    C.append(Ceb)
예제 #4
0
                                              time_s,
                                              ampInit,
                                              ampFinal,
                                              freqType='linear',
                                              ampType='linear',
                                              initZero=1)

# Simulate the excitation through the system
time_s, y, _ = signal.lsim(sys, x, time_s)
y = np.atleast_2d(y)

# Estimate the transfer function
optSpec = FreqTrans.OptSpect(freqRate=freqRate_rps,
                             smooth=('box', 1),
                             winType=('tukey', 0.0))
freq_rps, Txy, Cxy, Pxx, Pyy, Pxy = FreqTrans.FreqRespFuncEst(x, y, optSpec)
gain_dB, phase_deg = FreqTrans.GainPhase(Txy)
freq_hz = freq_rps * rps2hz

freq_hz = np.squeeze(freq_hz)
gain_dB = np.squeeze(gain_dB)
phase_deg = np.unwrap(np.squeeze(phase_deg) * deg2rad) * rad2deg
Cxy = np.squeeze(Cxy)

#%% Multisine signal with CZT
numChan = 1
numCycles = 1

freqMinDes_rps = freqInit_rps * np.ones(numChan)
freqMaxDes_rps = freqFinal_rps * np.ones(numChan)
freqStepDes_rps = (10 / freqRate_hz) * hz2rps
예제 #5
0
                             freqRate=freqRate_rps,
                             smooth=('box', 3),
                             winType=('tukey', 0.2),
                             detrendType='Linear')

# Excited Frequencies per input channel
optSpec.freq = np.asarray(freqExc_rps)

# FRF Estimate
freq_rps = []
freq_hz = []
T = []
C = []
for iSeg, seg in enumerate(oDataSegs):

    freq, Tey, Cey, Pee, Pyy, Pey = FreqTrans.FreqRespFuncEst(
        eList[iSeg], outList[iSeg], optSpec)
    freq, Teu, Ceu, _, Puu, Peu = FreqTrans.FreqRespFuncEst(
        eList[iSeg], uList[iSeg], optSpec)

    # Form the Frequency Response
    freq_hz = freq * rps2hz

    # Form the Frequency Response
    T_seg = np.zeros_like(Tey)

    for i in range(T_seg.shape[-1]):
        T_seg[..., i] = Tey[..., i] @ np.linalg.inv(Teu[..., i])

    T.append(T_seg)
    C.append(Cey)
        plt.figure(1)
        plt.plot(time_s, pCmd, time_s, pOut)


#%% Plot the Excitation Spectrum
optSpec = FreqTrans.OptSpect(dftType = 'czt', freqRate = freqRate_hz * hz2rps, freq = freqExc_rps, smooth = ('box', 3), winType = 'rect')

plt.figure(2)
TxyList = []
CxyList = []
PxxList = []
PyyList = []
PxyList = []
for i, pOut in enumerate(pOutList):
    pCmd = pCmdList[i]
    freq_rps, Txy, Cxy, Pxx, Pyy, Pxy = FreqTrans.FreqRespFuncEst(pCmd, pOut, optSpec)
    gain_dB, phase_deg = FreqTrans.GainPhase(Txy)
    freq_hz = freq_rps * rps2hz

    freq_hz = np.squeeze(freq_hz)
    gain_dB = np.squeeze(gain_dB)
    phase_deg = np.squeeze(phase_deg)
    Cxy = np.squeeze(Cxy)
    # Cxy = np.squeeze(np.abs(Cxy)**2)

    TxyList.append(Txy)
    CxyList.append(Cxy)
    PxxList.append(Pxx)
    PyyList.append(Pyy)
    PxyList.append(Pxy)
예제 #7
0
optSpec = FreqTrans.OptSpect(dftType='czt',
                             freqRate=freqRate_rps,
                             smooth=('box', 3),
                             winType=('tukey', 0.2),
                             detrendType='Linear')

# Excited Frequencies per input channel
optSpec.freq = np.asarray(freqExc_rps)

# FRF Estimate
LiEstNomList = []
LiEstCohList = []
svLiEstNomList = []
for iSeg, seg in enumerate(oDataSegs):

    freq_rps, Teb, Ceb, Pee, Pbb, Peb = FreqTrans.FreqRespFuncEst(
        vExcList[iSeg], vExcList[iSeg] + vFbList[iSeg], optSpec)
    # _       , Tev, Cev, _  , Pvv, Pev = FreqTrans.FreqRespFuncEst(vExcList[iSeg], vCmdList[iSeg], optSpec)

    freq_hz = freq_rps * rps2hz

    I3 = np.repeat([np.eye(3)], Teb.shape[-1], axis=0).T
    SaEstNom = Teb  # Sa = I + Teb
    SaEstCoh = Ceb  # Cxy = np.abs(Sxy)**2 / (Sxx * Syy) = (np.abs(Sxy) / Sxx) * (np.abs(Sxy) / Syy)

    # T = TNom = (uCtrl + uExc) / uExc - uNull / uExc
    # Li = inv(TNom + TUnc) - I = LiEstNom + LiEstUnc
    # LiEstNom = -I + TNom^-1
    # LiEstUnc = -(I + TNom^-1 * TUnc)^-1 * TNom^-1 * TUnc * TNom^-1
    LiEstNom = np.zeros_like(SaEstNom, dtype=complex)
    LiEstCoh = np.zeros_like(SaEstCoh)