diff --git a/swash/processing/r_test.py b/swash/processing/r_test.py index c052c86..5a67f1c 100644 --- a/swash/processing/r_test.py +++ b/swash/processing/r_test.py @@ -4,7 +4,7 @@ from numpy import random import scipy.signal as sgl yi = random.normal(size=2**20) -yr = 0.3 * np.roll(yi, -(2**10)) +yr = np.roll(yi, -(2**10)) figy, axy = plt.subplots() axy.plot(np.arange(2**10, 2**11), yi[2**10 : 2**11]) @@ -14,8 +14,8 @@ figf, axf = plt.subplots() axf.plot(*sgl.welch(yi)) axf.plot(*sgl.welch(yr)) -eta = yi + yr -u = -yi + yr +eta = lambda r: yi + r * yr +u = lambda r: -yi + r * yr def puv(eta, u): @@ -30,21 +30,20 @@ def puv(eta, u): figr, axr = plt.subplots() -axr.plot(*puv(eta, u), label="Without noise") -axr.plot( - *puv( - eta + 0.4 * random.normal(size=2**20), u + 0.4 * random.normal(size=2**20) - ), - label="With noise" -) +for r in np.arange(0, 1.1, 0.1): + axr.plot(*puv(eta(r), u(r)), c="k") + Rn = puv( + eta(r) + 0.4 * random.normal(size=2**20), + u(r) + 0.4 * random.normal(size=2**20), + ) + axr.plot( + *Rn, + c="#ff6600", + ) + axr.annotate(f"{r=:.1f}", (Rn[0][0], Rn[1][0]), bbox={"boxstyle": "square", "facecolor": "w"}) axr.grid() axr.autoscale(True, "x", tight=True) axr.set(ylim=(0, 1), ylabel="R", xlabel="f") -axr.legend(loc="lower left") - -axpsd = axr.twinx() -axpsd.plot(*sgl.welch(eta), label=r"PSD ($\eta$)", c="k", alpha=0.2, lw=1) -axpsd.legend(loc="lower right") -axpsd.set(ylabel="PSD") +axr.legend(("No noise", "40% noise"), loc="lower left") plt.show()