====== 11. Numerické výpočty ====== ===== Korelace a autokorelace ===== import matplotlib.pyplot as plt import numpy as np # inicializace generatoru nahodnych cisel np.random.seed(0) # ziskani dvou nahodnych vektoru x, y = np.random.randn(2, 100) # handle na kreslici plochu fig = plt.figure() # subplot - konfigurace XYZ znamena X radku, Y sloupcu, poradi Z ax1 = fig.add_subplot(211) ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2) ax1.grid(True) ax1.axhline(0, color='black', lw=2) ax2 = fig.add_subplot(212, sharex=ax1) ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2) ax2.grid(True) ax2.axhline(0, color='black', lw=2) plt.show() ===== Spektrum signálu ===== import matplotlib.pyplot as plt import numpy as np np.random.seed(0) dt = 0.01 Fs = 1/dt t = np.arange(0, 10, dt) s = 0.1*np.sin(2*np.pi*t) # pro ziskani ruseni v sinu odkomentujte nasledujici kod # nse = np.random.randn(len(t)) # r = np.exp(-t/0.05) # cnse = np.convolve(nse, r)*dt # cnse = cnse[:len(t)] # s = 0.1*np.sin(2*np.pi*t) + cnse plt.subplot(3, 2, 1) plt.plot(t, s) plt.subplot(3, 2, 3) plt.magnitude_spectrum(s, Fs=Fs) plt.subplot(3, 2, 4) plt.magnitude_spectrum(s, Fs=Fs, scale='dB') plt.subplot(3, 2, 5) plt.angle_spectrum(s, Fs=Fs) plt.subplot(3, 2, 6) plt.phase_spectrum(s, Fs=Fs) plt.show()