Analiza coerenței a două semnale

De la YO3ITI
Sari la navigare Sari la căutare

Se observă componenta coerentă de 10Hz; restul e zgomot.

import numpy as np
import matplotlib.pyplot as plt
# https://matplotlib.org/gallery/index.html

# Fixarea stării aleatorii (pentru reproductibilitate)
np.random.seed(19680801)

dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t))  # white noise 1
nse2 = np.random.randn(len(t))  # white noise 2

# Două semnale cu o componentă coerentă de 10Hz și o componentă aleatorie
# componenta coerentă va fi afișată ca un vârf pe grafic; restul e zgomot
s1 = np.sin(2 * np.pi * 10 * t) + nse1
s2 = np.sin(2 * np.pi * 10 * t) + nse2

axs: object
fig, axs = plt.subplots(2, 1)
axs[0].plot(t, s1, t, s2)
axs[0].set_xlim(0, 2)
axs[0].set_xlabel('timp')
axs[0].set_ylabel('s1 și s2')
axs[0].grid(True)

cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
axs[1].set_ylabel('coerența')
axs[1].set_xlabel('frecvența')

fig.tight_layout()
plt.show()