<jupyter_start><jupyter_text>Phase correlationsIn this notebook we play around with linear phase correlations of white noise.<jupyter_code>from plotly import tools
from plotly import offline as py
from plotly import graph_objs as go
from plotly import figure_factory as ff

py.init_notebook_mode(connected=True)<jupyter_output><empty_output><jupyter_text>In order to create linear phase correlated white noise we start with normal white noise $(x_1,\dots,x_n)$. The real fourier transform is given through $(X_0,\dots,X_{n/2})$. $X_0$ equals the signal mean and should not be modified. We can write $X_i=|X_i|e^{i\phi_i}$. Now we apply the transform,$$\phi_i=\phi_{i+j}+\phi+\eta_i$$,wherein $phi\in[-\pi,+\pi[$ is a constant, $\eta_i$ a noise term. With regard to the index shift $i+j$ we apply the circular condition $i+j = i+j-n/2$ if $i+j>n/2-1$.<jupyter_code>def correlate_phases(x, offset, phase, noise):
    X = np.fft.rfft(x)
    
    phi = np.arctan2(X.imag, X.real)
    phi[1:] = np.roll(phi[1:], -offset) + phase + noise
    
    X = np.abs(X) * np.exp(1j * phi)
    
    return np.fft.irfft(X)
x = np.random.normal(0, 1, 100)

n = np.random.normal(0, 0.5, 50)

y1 = correlate_phases(x, 1, 0, n)
y2 = correlate_phases(x, 1, np.pi, n)
layout = go.Layout(
    legend=dict(orientation='h')
)

figure = go.Figure([
    go.Scatter(y=x, name='white noise'),
    go.Scatter(y=y1, name='phase correlated (δ=0)'),
#    go.Scatter(y=y2, name='phase correlated (δ=π)'),    
], layout)

py.iplot(figure)<jupyter_output><empty_output><jupyter_text>If we apply the linear phase correlation without constant phase offset. We find that there are areas where the signal has large overlap with the original uncorrelated white noise.<jupyter_code>layout = go.Layout(
    legend=dict(orientation='h')
)

figure = go.Figure([
    go.Scatter(y=x, name='white noise'),
    go.Scatter(y=y2, name='phase correlated (δ=π)'),    
], layout)

py.iplot(figure)<jupyter_output><empty_output><jupyter_text>When using a constant phase offset to obtain the linear phase correlated white noise the local similarity is reduced compared to the previous time series. However, global structural features are still similar.<jupyter_code>z1 = correlate_phases(x, 1, 0, n)
z2 = correlate_phases(x, 2, 0, n)
layout = go.Layout(
    legend=dict(orientation='h')
)

figure = go.Figure([
    go.Scatter(y=x, name='white noise'),
    go.Scatter(y=z1, name='phase correlated (i=1)'),
    go.Scatter(y=z2, name='phase correlated (i=2)'),    
], layout)

py.iplot(figure)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1392898946547015, 'fraction_numerical': 0.015606710885680842, 'mean_word_length': 4.736017897091722, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '65553', 'license': 'Apache-2.0', 'n_tokens_mistral': 954, 'n_tokens_neox': 911, 'n_words': 257, 'path': 'notebooks/noise/Phase Correlations.ipynb', 'repo_name': 'bodokaiser/complex-systems', 'size': '2563'}