-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
Matteo edited this page Oct 7, 2020
·
5 revisions
import neurokit as nk
import pandas as pd
# Read an EDF file
recording = nk.io.read_edf('data/demo.edf')
# Calculate the spectrogram
f, t, S = nk.signal.spectrogram(recording.data, window=15, overlap=.75)
time = recording.meta['date'] + pd.to_timedelta(t, unit='s')
# Plot the spectrogram from 0 to 40 Hz using a decibel scale for power.
nk.vis.plot_spectrogram(f, time, S, fmax=40, scale='db')
from neurokit.signal.gmw import MorseWavelet
import numpy as np
# Read the recording file and keep only the first 60 seconds.
recording = nk.io.read_edf('data/demo.edf').slice(0, 60)
wavelet = MorseWavelet(beta=30, gamma=3)
time = recording.meta['date'] + recording.data.index
# Calculate the scales for the wavelet transform
_f = np.logspace(np.log2(0.1), np.log2(rec_sample.data.frequency / 2), base=2, num=100)
scales = wavelet.central_freq(1) / _f
signal = rec_sample.data['EEG R1(Fp2)'].values # the signal we need to analyze
# Compute the continuous wavelet transform
freqs, W = wavelet.cwt(signal, scales=scales, dt=1 / rec_sample.data.frequency)
# When plotting, remember to set a proper scale. For wavelet transforms you
# usually want to use a linear scale instead of decibels.
nk.vis.plot_spectrogram(freqs, time, np.abs(W), scale='linear')