cwt and visualization

Hello,

I'm new to this mailing list and to MNE. I think so far it is really great!

I have a few questions concerning the usage of the cwt_morlet
function; I want to plot a continuous wavelet transform from a single
EEG channel. I have a raw multi-channel .fif file, approximately 300s
long with a sampling frequency of 512 Hz. I'm interested in a
frequency range of approximately 0-45 Hz. How can I achieve this in
the simplest way possible? Specifically,

1. what datatype is the first parameter (X)? I tried the variable from
read_raw_fif, but that gives me "'tuple' object has no attribute
'shape'". I also tried raw[4][0], which seems to work. But is this
really the correct approach?
2. is freqs simply a list of integers with the frequencies of
interest? If the length is > 1, I get a Value Error ("Maximum allowed
size exceeded"). Does this mean I have to resample my raw data until
it works?
3. when it worked, it created an np.ndarray with numbers with complex
parts. Do I see it correctly that the complex parts show the phase
while the real part shows the power value?
4. how can I visualize the result?

Sorry for these basic questions. Help would be much appreciated!

Nico

Hi Nico,

You can check how to apply and plot time frequency analyses in this example:
http://martinos.org/mne/stable/auto_examples/time_frequency/plot_time_frequency_simulated.html

The main function boils down to:

import numpy as np
from mne.time_frequency import tfr_morlet
freqs = np.linspace(5, 45, 20) # an array of floats
power = tfr_morlet(epochs, freqs=freqs, n_cycles=5, return_itc=False)
power.plot([0])

If you wish to use arrays directly, instead of mne `Epochs` objects as
above, you can indeed use cwt_morlet:

import numpy as np
import matplotlib.pyplot as plt
from mne.time_frequency import cwt_morlet
n_signal, n_time = 10, 10000
X = np.random.rand(n_signal, n_time)
tfr = cwt_morlet(X, sfreq=1000, freqs = np.linspace(5, 45, 20), decim=10)
power = np.abs(tfr)
channel = 5
plt.matshow(power[channel], origin='lower', cmap='viridis', aspect='auto')
plt.show()

Hope that helps,

Best,

Jean-R?mi

Hello Jean-R?mi,

thanks a lot! The code for cwt_morlet you provided worked. However,
the y-axis labeling doesn't show the frequencies but the position of
the analyzed frequency in the array. For example:

when freqs = [0, 20, 60], then the y-axis will be labeled 0, 1, 2
instead of 0, 20, 60.

Is there a way around it? While at this issue, the x-axis shows
seconds*sfreq, but I'd like to be labeled as seconds.

In other words: Is there a way to change the axis labeling without
changing the content?

I hope you can help me with this one.

Thanks,
Nico

Quoting JR KING <jeanremi.king at gmail.com>:

This is a matplotlib issue not an MNE one.

Look for the 'extent' parameter in plt.imshow or plt.matshow(), and set the
ticks with axis.set_xticks() axis.set_ticklabels()

HTH

JR

Thank you. And sorry for this question, my bad.

Nico

Quoting JR KING <jeanremi.king at gmail.com>: