plt.plot(time_s, sig); plt.grid() plt.ylabel('Signal (nd)'); plt.subplot(3,1,2) plt.plot(time_s, ampChirp); plt.grid() plt.ylabel('ampitude (nd)'); plt.subplot(3,1,3) plt.plot(time_s, freqChirp_rps * rps2hz); plt.grid() plt.xlabel('Time (s)'); plt.ylabel('Frequency (Hz)') plt.show() #%% Plot the Excitation Spectrum ## Compute Spectrum of each channel optSpect = FreqTrans.OptSpect(freqRate = freqRate_hz) freq_hz, sigDft, Psd_mag = FreqTrans.Spectrum(sig, optSpect) Psd_dB = 20*np.log10(Psd_mag) ## Plot Spectrum plt.figure() plt.plot(freq_hz[0], Psd_dB[0]) plt.xlabel('frequency (Hz)'); plt.ylabel('Spectrum (dB)'); plt.grid() plt.show() #%% Create the output for JSON config timeFinal_s = time_s[-1] timeStart_s = time_s[0]
phSamp = np.random.uniform(-np.pi, np.pi, shapeSamp) samp = rSamp * np.exp(1j * phSamp) TEstSamp = np.zeros(shapeSamp, dtype='complex') for iSamp in range(nSamp): TEstSamp[..., iSamp] = TEstNom + TEstUnc * samp[..., iSamp] #%% if False: #%% optTemp = FreqTrans.OptSpect(dftType = 'czt', scaleType = 'density', freqRate = freqRate_rps, smooth = ('box', 3), winType = 'bartlett', detrendType = 'linear') optTemp.freq = freqGap_rps _, _, SnnN = FreqTrans.Spectrum(z, optTemp) [iOut, iIn] = [0,0] fig = plt.figure(); plt.grid(True) plt.plot(freq_hz[iIn], mag2db(Szz[iOut, iIn]), '.b', label = 'Estimate Nominal [MIMO]') plt.plot(freq_hz[iIn, sigIndx[iIn]], mag2db(Szz[iOut, iIn, sigIndx[iIn]]), '.r:', label = 'Estimate Nominal [SIMO]') plt.xlabel('Frequency [Hz]') plt.ylabel('Power Spectral Density [dB]') plt.legend() plt.xlim([1,5]) plt.ylim([0,20]) fig.set_tight_layout(True) fig.set_size_inches([6.4,2.4]) if False:
ax[iChan].set_xlabel('Time (s)') #%% Plot the Excitation Spectrum ## Compute Spectrum of each channel optFFT = FreqTrans.OptSpect(freqRate = freqRate_hz * hz2rps, winType = ('tukey', 0.0), smooth = ('box', 1)) optCZT = FreqTrans.OptSpect(dftType = 'czt', freqRate = freqRate_hz * hz2rps, winType = ('tukey', 0.0), smooth = ('box', 1)) freq_fft = [] P_dB_fft = [] freq_czt = [] P_dB_czt = [] for iChan, sig in enumerate(sigList): freq_rps_fft, _, P_fft = FreqTrans.Spectrum(sig, optFFT) freq_fft.append(freq_rps_fft * rps2hz) P_dB_fft.append(20*np.log10(P_fft)) optCZT.freq = freqElem_rps[sigIndx[iChan]] freq_rps_czt, _, P_czt = FreqTrans.Spectrum(sig, optCZT) freq_czt.append(freq_rps_czt * rps2hz) P_dB_czt.append(20*np.log10(P_czt)) nChan = len(P_dB_fft) plt.figure() for iChan in range(0, nChan): plt.subplot(nChan, 1, iChan+1) plt.plot(freq_fft[iChan].T, P_dB_fft[iChan].T, '-k', label='FFT Pxx') plt.plot(freq_czt[iChan].T, P_dB_czt[iChan].T, '.r-', label='CZT Pxx')
#optSpec.scaleType = 'density' optSpec.winType = ('tukey', 0.0) optSpec.freq = np.linspace(0, 0.05*np.pi, numSampMin-1) sig = np.ones(numSampMax) noiseSamples = np.random.randn(numSampMax) noiseLev = 0.0 sig += noiseLev * noiseSamples P_theshold_dB = -12 plt.figure() binList = [] for numSamp in numSampList: numSamp = int(numSamp) theta, sigDft, P_mag = FreqTrans.Spectrum(sig[0:numSamp], optSpec) P_mag = np.abs(P_mag / np.max(P_mag)) P_dB = 20*np.log10(P_mag[0]) bins = theta[0] * len(optSpec.freq[0]) / (2*np.pi) plt.plot(bins, P_dB, '-', label = 'Window: ' + str(optSpec.winType) + ' Over Sample: ' + str(numSamp/numSampMin)) bin_theshold = 2 * np.interp(-P_theshold_dB, -P_dB, bins) plt.plot(bin_theshold/2, P_theshold_dB, '*') binList.append( bin_theshold ) plt.xlabel('Normalized Bin') plt.ylabel('Normalized Power (dB)') plt.ylim(bottom = -60, top = 10) plt.xlim(left = 0.0)
# FRF Estimate stride = 10 lenX = len(time_s) / stride lenFreq = optTemp.freq.shape[-1] lenFreqN = optTempN.freq.shape[-1] numSeg = int(lenX) t_s = np.zeros(numSeg) PwwList = np.zeros((numSeg, numChan, lenFreq)) PwwNList = np.zeros((numSeg, numChan, lenFreqN)) for iSeg in range(0, numSeg): iEnd = iSeg * stride print(100 * iSeg / numSeg) _, _, Pww = FreqTrans.Spectrum(exc[:, 0:iEnd + 1], optTemp) _, _, PwwN = FreqTrans.Spectrum(exc[:, 0:iEnd + 1], optTempN) t_s[iSeg] = time_s[iEnd + 1] PwwList[iSeg, ] = Pww PwwNList[iSeg, ] = PwwN #%% Plot N = len(time_s) #PwwList[:,] = np.nan #PwwNList[:,] = np.nan PwwListMag = np.abs(PwwList[:, 0, :]) PwwNListMag = np.abs(PwwNList[:, 0, :])
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()) optSpecN = FreqTrans.OptSpect(dftType='czt', freqRate=freqRate_rps, smooth=('box', 7), winType=('tukey', 0.0)) optSpecN.freq = freqNull_rps SyyList = [] for iSeg in range(0, len(oDataSegs)): _, _, SyyNull = FreqTrans.Spectrum(ySensList[iSeg], optSpecN) SyyList.append(SyyNull) _, _, Sxx = FreqTrans.Spectrum(vExcList[iSeg], optSpec) _, _, SxxNull = FreqTrans.Spectrum(vExcList[iSeg], optSpecN) print(np.sum(SxxNull, axis=-1) / np.sum(Sxx, axis=-1)) from Core import Environment ft2m = 0.3049 m2ft = 1 / ft2m b_ft = 4 # levelList = ['light', 'moderate', 'severe'] levelList = ['light', 'moderate']