Created
April 24, 2014 13:57
-
-
Save dengemann/11255522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
from mne.time_frequency.tfr import _time_frequency, single_trial_power | |
from mne.time_frequency import morlet | |
#Initial discrete temporal signal: | |
delta = 0.001 # time sampling (in sec) | |
nbTrials = 1 | |
times = np.arange(0, 1, delta) | |
data = np.zeros((nbTrials, len(times))) | |
Frq = 10 # signal of Frq Hz | |
for ind, t in enumerate(times): | |
for i in range(nbTrials): | |
data[i][ind] = np.sin(2 * np.pi * Frq * t) | |
plt.figure() | |
#Draw the temporal signal: | |
plt.subplots_adjust(0.12, 0.08, 0.96, 0.94, 0.2, 0.43) | |
plt.subplot(2, 1, 1) | |
plt.plot(times, data[0]) | |
plt.xlabel('time (sec)') | |
plt.ylabel('amplitude') | |
plt.title('Signal of '+str(Frq)+'Hz') | |
plt.xlim(times[0], times[-1]) | |
plt.ylim(-1, 1) | |
#Time-frequency transform: | |
deltaF = 1 | |
freqs = np.arange(5, 30, deltaF) | |
#Draw of the time-frequency PSD: | |
plt.subplot(2, 1, 2) | |
n_cycles = freqs.astype(float) / (np.arange(len(freqs)) + 4.5) | |
resultPSD = single_trial_power(data[None], 1e3, freqs, n_cycles=n_cycles) | |
resultPSD = np.squeeze(resultPSD) | |
plt.imshow(resultPSD, aspect='auto', origin='lower', | |
extent=[times[0], times[-1], freqs[0], freqs[-1]]) | |
plt.title('PSD') | |
plt.xlabel('time (sec)') | |
plt.ylabel('frequency (Hz)') | |
plt.colorbar() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment