-
Notifications
You must be signed in to change notification settings - Fork 33
/
ExampleCorrelation.py
42 lines (38 loc) · 1.22 KB
/
ExampleCorrelation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
import matplotlib.pyplot as plt
from welib.tools.signal_analysis import *
from numpy.random import seed; seed(0)
# --- Parameters
dt = 1
n = 10000
coeff = 0.95 # 1:full corr, 0: no-corr
nMax = 180
# --- Create a correlated time series
tvec = np.arange(0,n)*dt
ts = correlated_signal(coeff, n)
# --- Compute correlation coefficient
R, tau = correlation(ts, nMax=nMax, dt=dt)
# --- Plot
fig,axes = plt.subplots(2, 1, sharey=False, figsize=(6.4,4.8)) # (6.4,4.8)
fig.subplots_adjust(left=0.12, right=0.95, top=0.95, bottom=0.11, hspace=0.20, wspace=0.20)
ax=axes[0]
# Plot time series
ax.plot(tvec,ts)
ax.set_xlabel('t [s]')
ax.set_ylabel('u [m/s]')
ax.tick_params(direction='in')
# Plot correlation
ax=axes[1]
ax.plot(tau, R ,'-o', label='Computed')
ax.plot(tau, coeff**(tau/dt) ,'--' ,label=r'Theoretical - c$^{\tau/dt}$') # analytical coeff^n trend
ax.set_xlabel(r'$\tau$ [s]')
ax.set_ylabel(r'$R(\tau)$ [-]')
ax.set_title('Signal - Correlation coefficient')
ax.legend()
if __name__=='__main__':
plt.show()
if __name__ == '__test__':
pass
if __name__=="__export__":
from welib.tools.repo import export_figs_callback
export_figs_callback(__file__)