unwrap=True) gainTaEstUnc_mag = FreqTrans.Gain(TaEstUnc, magUnit='mag') if False: for iPlot, io in enumerate(ioArray): iOut, iIn = io outName = outPlot[iOut] inName = inPlot[iIn] fig = 80 + iPlot fig = FreqTrans.PlotBode(freqLin_hz, gainTaLinNom_mag[iOut, iIn], phaseTaLinNom_deg[iOut, iIn], coher_nd=np.ones_like(freqLin_hz), fig=fig, color='k', label='Linear') fig = FreqTrans.PlotBode(freq_hz[0], gainTaEstNom_mag[iOut, iIn], phaseTaEstNom_deg[iOut, iIn], TaEstCoh[iOut, iIn], gainUnc_mag=gainTaEstUnc_mag[iOut, iIn], fig=fig, color='b', label='Estimation (MIMO)') fig = FreqTrans.PlotBode(freq_hz[0, sigIndx[iIn]], gainTaEstNom_mag[iOut, iIn, sigIndx[iIn]], phaseTaEstNom_deg[iOut, iIn, sigIndx[iIn]], TaEstCoh[iOut, iIn, sigIndx[iIn]],
#%% Bode Plot # Linear Model Gain and Phase gainTLinNom_mag, phaseTLinNom_deg = FreqTrans.GainPhase(TLinNom, magUnit = 'mag', unwrap = True) gainTLinUnc_mag = FreqTrans.Gain(TLinUnc, magUnit = 'mag') # Estimated Gain and Phase gainTEstNom_mag, phaseTEstNom_deg = FreqTrans.GainPhase(TEstNom, magUnit = 'mag', unwrap = True) gainTEstUnc_mag = FreqTrans.Gain(TEstUnc, magUnit = 'mag') np.mean(gainTEstUnc_mag, axis = -1) / np.mean(gainTLinUnc_mag, axis = -1) # should be 1 if scaled correctly if False: for iPlot, [iOut, iIn] in enumerate(ioArray): fig = None fig = FreqTrans.PlotBode(freqLin_hz, gainTLinNom_mag[iOut, iIn], phaseTLinNom_deg[iOut, iIn], coher_nd = cohTLin_mag[iOut, iIn], gainUnc_mag = None, fig = fig, dB = True, color='k', label='Linear Nominal' + ' [$u_' + str(iIn+1) + '$ to ' + '$z_' + str(iOut+1) + '$]') fig = FreqTrans.PlotBode(freqLin_hz, gainTLinUnc_mag[iOut, iIn], None, coher_nd = None, gainUnc_mag = None, fig = fig, dB = True, color='k', linestyle='--', label='Linear Uncertainty' + ' [$u_' + str(iIn+1) + '$ to ' + '$z_' + str(iOut+1) + '$]') fig = FreqTrans.PlotBode(freq_hz[iIn], gainTEstNom_mag[iOut, iIn], phaseTEstNom_deg[iOut, iIn], coher_nd = cohTEst_mag[iOut, iIn], gainUnc_mag = None, fig = fig, dB = True, color='b', linestyle='None', marker='.', label='Estimate Nominal' + ' [$u_' + str(iIn+1) + '$ to ' + '$z_' + str(iOut+1) + '$]') fig = FreqTrans.PlotBode(freq_hz[iIn], gainTEstUnc_mag[iOut, iIn], None, coher_nd = None, gainUnc_mag = None, fig = fig, dB = True, color='r', linestyle='None', marker='.', label='Estimate Uncertainty' + ' [$u_' + str(iIn+1) + '$ to ' + '$z_' + str(iOut+1) + '$]') # fig = FreqTrans.PlotBode(freq_hz[iIn, sigIndx[iIn]], gainTEstNom_mag[iOut, iIn, sigIndx[iIn]], phaseTEstNom_deg[iOut, iIn, sigIndx[iIn]], coher_nd = cohTEst_mag[iOut, iIn, sigIndx[iIn]], gainUnc_mag = gainTEstUnc_mag[iOut, iIn, sigIndx[iIn]], fig = fig, dB = True, color='b', linestyle='None', marker='.', label='Estimate [SIMO]') # fig = FreqTrans.PlotBode(freq_hz[iIn, sigIndx[iIn]], gainTEstUnc_mag[iOut, iIn, sigIndx[iIn]], None, coher_nd = None, gainUnc_mag = None, fig = fig, dB = True, color='b', linestyle='None', marker='.', label='Estimate [SIMO]') ax = fig.get_axes() # handles, labels = ax[0].get_legend_handles_labels() # handles = [(handles[0], handles[2]), (handles[1], handles[3])] # labels = [labels[0], labels[1]] # ax[0].legend(handles, labels) # ax[0].set_xlim([1,10])
# Linear Model Gain and Phase gainToLinNom_mag, phaseToLinNom_deg = FreqTrans.GainPhase(ToLinNom, magUnit = 'mag', phaseUnit = 'deg', unwrap = True) gainToLinUnc_mag = FreqTrans.Gain(ToLinUnc, magUnit = 'mag') cohToLin_mag = np.ones_like(ToLinUnc) # Estimated gainToEstNom_mag, phaseToEstNom_deg = FreqTrans.GainPhase(ToEstNom, magUnit = 'mag', phaseUnit = 'deg', unwrap = True) gainToEstUnc_mag = FreqTrans.Gain(ToEstUnc, magUnit = 'mag') # Estimation Uncertain Response cohToEst_mag = ToEstCoh # Estimation Coherence cohToEstMin = np.min(cohToEst_mag, axis = (0, 1)) if False: for iPlot, [iOut, iIn] in enumerate(ioArray): fig = 20 + iPlot fig = FreqTrans.PlotBode(freqLin_hz, gainToLinNom_mag[iOut, iIn], phaseToLinNom_deg[iOut, iIn], coher_nd = cohToLin_mag[iOut, iIn], gainUnc_mag = gainToLinUnc_mag[iOut, iIn], fig = fig, dB = True, color='k', label='Linear Model') fig = FreqTrans.PlotBode(freq_hz[iIn], gainToEstNom_mag[iOut, iIn], phaseToEstNom_deg[iOut, iIn], coher_nd = cohToEst_mag[iOut, iIn], gainUnc_mag = gainToEstUnc_mag[iOut, iIn], fig = fig, dB = True, color='b', label='Estimate [MIMO]') fig = FreqTrans.PlotBode(freq_hz[iIn, sigIndx[iIn]], gainToEstNom_mag[iOut, iIn, sigIndx[iIn]], phaseToEstNom_deg[iOut, iIn, sigIndx[iIn]], coher_nd = cohToEst_mag[iOut, iIn, sigIndx[iIn]], gainUnc_mag = gainToEstUnc_mag[iOut, iIn, sigIndx[iIn]], fig = fig, dB = True, color='g', label='Estimate [SIMO]') ax = fig.get_axes() handles, labels = ax[0].get_legend_handles_labels() handles = [handles[0], handles[3], handles[1], handles[4], handles[2], handles[5]] labels = [labels[0], labels[3], labels[1], labels[4], labels[2], labels[5]] ax[0].legend(handles, labels) fig.suptitle('$T_o$ : ' + '$r_{Exc}$[' + str(iIn) + '] to ' + '$z$[' + str(iOut) + ']') #%% Sigma - Output Stability I2 = np.repeat([np.eye(2)], LoLinNom.shape[-1], axis=0).T
fig=fig, fmt='*', label=oDataSegs[iSeg]['Desc']) fig.suptitle(inName + ' to ' + outName, size=20) ax = fig.get_axes() ax[0].set_xlim(-3, 1) ax[0].set_ylim(-2, 2) #%% Bode Plots if True: for iIn, inName in enumerate(inPlot): for iOut, outName in enumerate(outPlot): fig = None for iSeg in range(0, len(oDataSegs)): fig = FreqTrans.PlotBode(freq_hz[iIn], gain_mag[iSeg][iOut, iIn], phase_deg[iSeg][iOut, iIn], C[iSeg][iOut, iIn], gainUnc_mag=gainUnc_mag[iSeg][iOut, iIn], dB=False, fig=fig, fmt='*--', label=oDataSegs[iSeg]['Desc']) fig.suptitle(inName + ' to ' + outName, size=20)
plt.ylabel('Output') plt.legend() plt.grid(True) #%% Bode Progression if False: gainLin_mag, phaseLin_deg = FreqTrans.GainPhase(TLinFinal, magUnit = 'mag', unwrap = False) gainRefine_mag, phaseRefine_deg = FreqTrans.GainPhase(TuzRefine, magUnit = 'mag', unwrap = False) gainFinal_mag, phaseFinal_deg = FreqTrans.GainPhase(TuzFinal, magUnit = 'mag', unwrap = False) gainFinalMean_mag = np.mean(gainFinal_mag, axis=0) phaseFinalMean_deg = np.mean(phaseFinal_deg, axis=0) phaseFinalMean_deg = np.mean(phaseFinal_deg, axis=0) CuzFinalMean = np.mean(CuzFinal, axis=0) fig = None fig = FreqTrans.PlotBode(freqExcFinal_rps * rps2hz, gainLin_mag.squeeze(), phaseLin_deg.squeeze(), coher_nd = np.ones_like(gainLin_mag).squeeze(), gainUnc_mag = None, fig = fig, dB = True, linestyle = '-', color='k', label='Linear Model') fig = FreqTrans.PlotBode(freqExc_rps * rps2hz, gainRefine_mag[0], phaseRefine_deg[0], coher_nd = CuzRefine[0], gainUnc_mag = None, fig = fig, dB = True, linestyle = ':', color='b', label='First iteration') fig = FreqTrans.PlotBode(freqExc_rps * rps2hz, gainRefine_mag[-1], phaseRefine_deg[-1], coher_nd = CuzRefine[-1], gainUnc_mag = None, fig = fig, dB = True, linestyle = '-', color='b', label='Last Refinement iteration') for iFinal, t in enumerate(timeFinal_s): fig = FreqTrans.PlotBode(freqExcFinal_rps * rps2hz, gainFinal_mag[iFinal], phaseFinal_deg[iFinal], coher_nd = CuzFinal[iFinal], gainUnc_mag = None, fig = fig, dB = True, linestyle = ':', color='r', label='Final Estimates') fig = FreqTrans.PlotBode(freqExcFinal_rps * rps2hz, gainFinalMean_mag, phaseFinalMean_deg, coher_nd = CuzFinalMean, gainUnc_mag = None, fig = fig, dB = True, linestyle = '-', color='r', label='Final Merge') ax = fig.get_axes() ax[-1].set_ylim(0, 1)
fig = FreqTrans.PlotNyquist(np.asarray([-1 + 0j]), TUnc=np.asarray([0.4 + 0.4j]), fig=fig, fmt='*r', label='Critical Region') fig.suptitle(inName + ' to ' + outName, size=20) ax = fig.get_axes() ax[0].set_xlim(-3, 1) ax[0].set_ylim(-2, 2) #%% Bode Plots if False: #%% for iOut, outName in enumerate(outPlot): for iIn, inName in enumerate(inPlot): fig = None for iSeg in range(0, len(oDataSegs)): # fig = FreqTrans.PlotBode(freq_hz[0], gain_mag[iSeg][iOut, iIn], phase_deg[iSeg][iOut, iIn], C[iSeg][iOut, iIn], gainUnc_mag = gainUnc_mag[iSeg][iOut, iIn], fig = fig, fmt = rtsmSegList[iSeg]['fmt'] + '*-', label = oDataSegs[iSeg]['Desc']) fig = FreqTrans.PlotBode(freq_hz[0], gain_mag[iSeg][iOut, iIn], phase_deg[iSeg][iOut, iIn], C[iSeg][iOut, iIn], fig=fig, fmt=rtsmSegList[iSeg]['fmt'] + '*-', label=oDataSegs[iSeg]['Desc']) fig.suptitle(inName + ' to ' + outName, size=20)
label='Critical Region') fig.suptitle(inName + ' to ' + outName, size=20) ax = fig.get_axes() ax[0].set_xlim(-3, 1) ax[0].set_ylim(-2, 2) #%% Bode Plots if True: for iOut, outName in enumerate(outPlot): for iIn, inName in enumerate(inPlot): fig = 80 + 3 * iOut + iIn fig = FreqTrans.PlotBode(freqLin_hz, gainLin_mag[iOut, iIn], phaseLin_deg[iOut, iIn], coher_nd=np.ones_like(freqLin_hz), fig=fig, fmt='k', label='Linear') fig = FreqTrans.PlotBode(freq_hz[0, sigIndx[iIn]], gain_mag[iOut, iIn, sigIndx[iIn]], phase_deg[iOut, iIn, sigIndx[iIn]], C[iOut, iIn, sigIndx[iIn]], fig=fig, fmt='bo', label='Estimated SIMO') fig = FreqTrans.PlotBode(freq_hz[0], gain_mag[iOut, iIn], phase_deg[iOut, iIn], C[iOut, iIn], fig=fig,
magUnit='mag', phaseUnit='deg', unwrap=True) gainTiEstUnc_mag = FreqTrans.Gain( TiEstUnc, magUnit='mag') # Estimation Uncertain Response cohTiEst_mag = TiEstCoh # Estimation Coherence cohTiEstMin = np.min(cohTiEst_mag, axis=(0, 1)) if True: for iPlot, [iOut, iIn] in enumerate(ioArray): fig = 20 + iPlot fig = FreqTrans.PlotBode(freqLin_hz, gainTiLinNom_mag[iOut, iIn], phaseTiLinNom_deg[iOut, iIn], coher_nd=cohTiLin_mag[iOut, iIn], gainUnc_mag=None, fig=fig, dB=True, color='k', label='Linear Model') fig = FreqTrans.PlotBode(freqLin_hz, gainTiLinUnc_mag[iOut, iIn], None, coher_nd=None, gainUnc_mag=None, fig=fig, dB=True, color='k', linestyle='--', label='Linear Model')
if False: for iPlot, [iOut, iIn] in enumerate(ioArray): fig = 20 + iPlot for iSeg in range(0, len(oDataSegs)): gain_mag = gainLaEstNomList_mag[iSeg][iOut, iIn] phase_deg = phaseLaEstNomList_deg[iSeg][iOut, iIn] coher_nd = LaEstCohList[iSeg][iOut, iIn] gainUnc_mag = gainLaEstUncList_mag[iSeg][iOut, iIn] fig = FreqTrans.PlotBode(freq_hz[iIn], gain_mag, phase_deg, coher_nd, gainUnc_mag, fig=fig, dB=True, color=rtsmSegList[iSeg]['color'], label=oDataSegs[iSeg]['Desc']) # fig.suptitle(inName + ' to ' + outName, size=20) #%% Turbulence optSpecE = FreqTrans.OptSpect(dftType='czt', freqRate=freqRate_rps, smooth=('box', 7), winType=('tukey', 0.0)) optSpecE.freq = np.asarray(freqExc_rps) optSpecE.freqInterp = np.sort(optSpecE.freq.flatten())
fig = FreqTrans.PlotNyquist(np.asarray([-1 + 0j]), TUnc=np.asarray([0.4 + 0.4j]), fig=fig, fmt='*r', label='Critical Region') fig.suptitle(inName + ' to ' + outName, size=20) ax = fig.get_axes() ax[0].set_xlim(-3, 1) ax[0].set_ylim(-2, 2) #%% Bode Plots if False: for iOut, outName in enumerate(outPlot): for iIn, inName in enumerate(inPlot): fig = None for iSeg in range(0, len(oDataSegs)): fig = FreqTrans.PlotBode(freq_hz[0], gainLiEstNomList_mag[iSeg][iOut, iIn], phaseLiEstNomList_deg[iSeg][iOut, iIn], LiEstCohList[iSeg][iOut, iIn], fig=fig, color=rtsmSegList[iSeg]['color'], linestyle='-', label=oDataSegs[iSeg]['Desc']) fig.suptitle(inName + ' to ' + outName, size=20)