<jupyter_start><jupyter_text>Generating dataIn this notebook we generate the data used further in the example. A shear frame 9 floors is used in the example, and we assume Rayleigh damping, defined by 5% in the first and last mode. We generate data for two cases, a stocastic case and a combined stochastic-deterministic case.The output is assumed to be accelerations at each floor together with white, zero mean, independent measurement noise. Stochastic caseThe load (input) is stochastic and consists of zero mean independent white process noise applied to all floors<jupyter_code># Create a shear frame
sf = strid.utils.ShearFrame(9, 1e3, 1e7)
sf.set_rayleigh_damping_matrix([sf.get_natural_frequency(1), sf.get_natural_frequency(sf.n)], [.05]*2)

# Determine the time discretization and period
Tmax = 1. / strid.w2f(sf.get_natural_frequency(1))
fmax = strid.w2f(sf.get_natural_frequency(sf.n))
T = 1000*Tmax
fs = 5 * fmax
t = np.arange(0., T, 1/fs)

# Define loads on system
## Unmeasureable: Stochastic loads on all floors (Process noise)
w = np.random.normal(size=(sf.n, t.size)) * 1e-1

## Load matrix, f
F = w.copy()

# Simulate response, accelerations at each floor measured
y0, _, _ = sf.simulate(t, F)

noise_std = y0.std()

# Add measurement noise
v = np.random.normal(size=y0.shape)*noise_std
y = y0 + v

plt.figure("Accelerations measured at top floor")
plt.plot(t, y[-1], label="w/noise")
plt.plot(t, y0[-1], label="wo/noise")
plt.legend()
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")

plt.figure("PSD of accelerations at top floor")
for yi in [y[-1], y0[-1]]:
    freqs, Gyy = scipy.signal.welch(yi, fs, nperseg=2**10)
    plt.semilogy(freqs, Gyy)
    

for n in range(1, 1+sf.n):
    plt.axvline(strid.w2f(sf.get_natural_frequency(n)), alpha=.3)
plt.ylabel('PSD')    
plt.xlabel('Frequency (Hz)')
true_frequencies = np.array([sf.get_natural_frequency(i)/(2*np.pi) for i in range(1, sf.n+1)])
true_damping = np.array([sf.get_rayleigh_damping_ratio(i) for i in range(1, sf.n+1)])
true_modeshapes = np.array([sf.get_mode_shape(i) for i in range(1, sf.n+1)])

np.savez("results/data-stochastic.npz", 
         y=y, fs=fs, 
         true_frequencies=true_frequencies,
         true_damping=true_damping,
         true_modeshapes=true_modeshapes
        )<jupyter_output><empty_output><jupyter_text>Combined deterministic stochastic caseIn addition to the stochastic (unmeasureable) loading, a deterministic (measured) loading is applied to the structure. The load is assumed to be random applied to the top floor which goes from zero to twice the highest natural frequency of the shear frame<jupyter_code>u = scipy.signal.chirp(t, 1., T, fmax*2, method='quadratic').reshape(1, -1)

## Load matrix, f
F = w.copy() # Stochastic loading
F[-1] += u[0] # Deterministic loading to top floor

# Simulate response, accelerations at each floor measured
y0, _, _ = sf.simulate(t, F)

# Add measurement noise
y = y0 + v

plt.figure("Loads")
plt.plot(t, u[0], label="Deterministic")
plt.plot(t, w[-1], label="Stochastic - top floor")

plt.figure("Accelerations at top floor - Combined")
plt.plot(t, y[-1], label="w/noise")
plt.plot(t, y0[-1], label="wo/noise")
plt.legend()
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")

plt.figure("PSD of accelerations at top floor - Combined")
for yi in [y[-1], y0[-1],]:
    freqs, Gyy = scipy.signal.welch(yi, fs, nperseg=2**9)
    plt.semilogy(freqs, Gyy)
    

for n in range(1, 1+sf.n):
    plt.axvline(strid.w2f(sf.get_natural_frequency(n)), alpha=.3)
plt.ylabel('PSD')    
plt.xlabel('Frequency (Hz)')
np.savez("results/data-combined.npz", 
         u=u, y=y, fs=fs, 
         true_frequencies=true_frequencies,
         true_damping=true_damping,
         true_modeshapes=true_modeshapes
        )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13589403973509934, 'fraction_numerical': 0.018543046357615896, 'mean_word_length': 4.544787077826725, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '444360', 'license': '0BSD', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1366, 'n_words': 371, 'path': 'examples/01-shear-frame/00-generating-data.ipynb', 'repo_name': 'olavguddal/strid', 'size': '3775'}