omega=freqLin_rps) TaLinUnc = gainTaLinUnc_mag * np.exp(1j * phaseTaLinUnc_rad) #%% Excitation numExc = 3 numCycles = 3 ampInit = 4.0 * deg2rad ampFinal = ampInit freqMinDes_rps = 0.1 * hz2rps * np.ones(numExc) freqMaxDes_rps = 9.7 * hz2rps * np.ones(numExc) freqStepDes_rps = (10 / freqRate_hz) * hz2rps methodSW = 'zip' # "zippered" component distribution # Generate MultiSine Frequencies freqExc_rps, sigIndx, time_s = GenExcite.MultiSineComponents( freqMinDes_rps, freqMaxDes_rps, freqRate_hz, numCycles, freqStepDes_rps, methodSW) freqNull_rps = freqExc_rps[0:-1] + 0.5 * np.diff(freqExc_rps) # Generate Schroeder MultiSine Signal ampExc_nd = np.linspace(ampInit, ampFinal, len(freqExc_rps)) / np.sqrt( len(freqExc_rps)) vExc, _, sigExc = GenExcite.MultiSine(freqExc_rps, ampExc_nd, sigIndx, time_s, phaseInit_rad=0, boundPhase=1, initZero=1, normalize='peak', costType='Schroeder')
# LoLinNom[...,i] = -np.eye(2) + SoLinNomElem LoLinUnc[...,i] = -inv(np.eye(2) + SoLinNomInvElem @ SoLinUncElem) @ SoLinNomInvElem @ SoLinUncElem @ SoLinNomInvElem #%% Excitation numExc = 2 numCycles = 6 ampInit = 1 ampFinal = 1 freqMinDes_rps = 0.1 * hz2rps * np.ones(numExc) freqMaxDes_rps = 10.3 * hz2rps * np.ones(numExc) freqStepDes_rps = (20 / freqRate_hz) * hz2rps methodSW = 'zip' # "zippered" component distribution # Generate MultiSine Frequencies freqExc_rps, sigIndx, time_s = GenExcite.MultiSineComponents(freqMinDes_rps, freqMaxDes_rps, freqRate_hz, numCycles, freqStepDes_rps, methodSW) # Generate Schroeder MultiSine Signal ampExcit_nd = np.linspace(ampInit, ampFinal, len(freqExc_rps)) / np.sqrt(len(freqExc_rps)) rExc, phaseElem_rad, sigExcit = GenExcite.MultiSine(freqExc_rps, ampExcit_nd, sigIndx, time_s, phaseInit_rad = 0, boundPhase = 1, initZero = 1, normalize = 'peak', costType = 'Schroeder') rExc = rExc / np.std(rExc) rPeak = np.mean(GenExcite.PeakFactor(rExc) * np.std(rExc))**2 # Excited Frequencies per input channel freqChan_rps = freqExc_rps[sigIndx] freqChan_hz = freqChan_rps * rps2hz # Null Frequencies freqGap_rps = freqExc_rps[0:-1] + 0.5 * np.diff(freqExc_rps) freqGap_hz = freqGap_rps * rps2hz
# Constants hz2rps = 2*np.pi rps2hz = 1/hz2rps #%% Define the frequency selection and distribution of the frequencies into the signals freqRate_hz = 50; freqInit_rps = 0.1 * hz2rps freqFinal_rps = 10 * hz2rps timeDur_s = 10.0 ampInit = 1.0 ampFinal = 1.0 time_s = np.linspace(0, timeDur_s, int(timeDur_s * freqRate_hz) + 1) sig, ampChirp, freqChirp_rps = GenExcite.Chirp(freqInit_rps, freqFinal_rps, time_s, ampInit, ampFinal, freqType = 'linear', ampType = 'linear', initZero = 1) ## Results plt.figure() plt.subplot(3,1,1) 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()
rps2hz = 1/hz2rps #%% Define the frequency selection and distribution of the frequencies into the signals numChan = 3 freqRate_hz = 50; timeDur_s = 10.0 numCycles = 1 freqMinDes_rps = (numCycles/timeDur_s) * hz2rps * np.ones(numChan) #freqMaxDes_rps = (freqRate_hz/2) * hz2rps * np.ones(numChan) freqMaxDes_rps = 10 * hz2rps * np.ones(numChan) freqStepDes_rps = (10 / freqRate_hz) * hz2rps methodSW = 'zip' # "zippered" component distribution ## Generate MultiSine Frequencies freqElem_rps, sigIndx, time_s = GenExcite.MultiSineComponents(freqMinDes_rps, freqMaxDes_rps, freqRate_hz, numCycles, freqStepDes_rps, methodSW) timeDur_s = time_s[-1] - time_s[0] ## Generate Schroeder MultiSine Signal ampElem_nd = np.ones_like(freqElem_rps) ## Approximate relative signal amplitude, create flat sigList, phaseElem_rad, sigElem = GenExcite.MultiSine(freqElem_rps, ampElem_nd, sigIndx, time_s, costType = 'Norm2', phaseInit_rad = 0, boundPhase = 1, initZero = 1, normalize = 'peak'); ## Results peakFactor = GenExcite.PeakFactor(sigList) peakFactorRel = peakFactor / np.sqrt(2) print(peakFactorRel) # Signal Power sigPowerRel = (ampElem_nd / max(ampElem_nd))**2 / len(ampElem_nd)
W = FreqTrans.DirichletApprox(np.asarray([binSel])) numChan = 1 freqRate_hz = 50 numCycles = 1 freqMaxDes_rps = 15 * hz2rps * np.ones(numChan) freqStepDes_rps = (20 / 50) * hz2rps tBinWidth = FreqTrans.FreqStep2TimeBin(freqStepDes_rps) timeDur_s = binSel * tBinWidth freqMinDes_rps = (1/timeDur_s) * hz2rps * np.ones(numChan) methodSW = 'zip' # "zippered" component distribution ## Generate MultiSine Frequencies freqExc_rps, sigIndx, time_s = GenExcite.MultiSineComponents(freqMinDes_rps, freqMaxDes_rps, freqRate_hz, numCycles, freqStepDes_rps, methodSW) freqGap_rps = freqExc_rps[0:-1] + 0.5 * np.diff(freqExc_rps) ## Generate Schroeder MultiSine Signal ampExc_nd = np.ones_like(freqExc_rps) ## Approximate relative signal amplitude, create flat sigList, phaseElem_rad, sigElem = GenExcite.MultiSine(freqExc_rps, ampExc_nd, sigIndx, time_s, costType = 'Schroeder', phaseInit_rad = 0, boundPhase = True, initZero = True, normalize = 'rms'); sigPeakFactor = GenExcite.PeakFactor(sigList) ampExc_nd *= 0.5 sigList *= 0.5 # Excited Amplitude per input channel ampChan_nd = ampExc_nd[sigIndx] # Excited Frequencies per input channel freqChan_rps = freqExc_rps[sigIndx]
freqLin_hz = freqLin_rps * rps2hz #%% Chirp signal with FFT freqInit_rps = 0.1 * hz2rps freqFinal_rps = 20 * hz2rps timeDur_s = 10.0 ampInit = 1.0 ampFinal = ampInit time_s = np.linspace(0.0, timeDur_s, int(timeDur_s * freqRate_hz) + 1) # Generate the chirp x, ampChirpX, freqChirp_rps = GenExcite.Chirp(freqInit_rps, freqFinal_rps, 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