Stockwell transform for an arbitrarily signal

Hello,

I am trying to perform the time-frequency analysis of a signal through Stockwell transform with the use of the MNE package. I am getting a TypeError: inst must be Epochs or Evoked.

Is there any way to use the package for the analysis of any signal or it has to be Epochs or Evoked signal?

Thank you in advance!

from mne.time_frequency import tfr_stockwell
import numpy as np
from scipy.signal import chirp

# create a signal
t = np.linspace(0, 10, 5001)
amp = chirp(t, f0=12.5, f1=2.5, t1=10, method='linear')

fmin = 0  # Hz
fmax = 25  # Hz

# perform the S-transform
power, itc = tfr_stockwell(amp, fmin=fmin, fmax=fmax, decim=4, n_jobs=1,
                           width=.3, return_itc=True)

power.plot([0], baseline=(-0.5, 0), mode=None, title='S-transform (power)')

itc.plot([0], baseline=None, mode=None, title='S-transform (ITC)')

use this function https://mne.tools/stable/generated/mne.time_frequency.tfr_array_stockwell.html

Alex

Thank you, Alex! It should be working just fine!

from mne.time_frequency import tfr_array_stockwell
import matplotlib.pyplot as plt

from scipy.signal import chirp
import numpy as np

# create a signal
t = np.linspace(0, 10, 5001)
amp = chirp(t, f0=12.5, f1=2.5, t1=10, method='linear')

amp_array = np.expand_dims(amp, axis=[0,1])  # Add dimensions to signal

fmin = 0
fmax = 25

Fs = 1/(t[1]-t[0])

# S-transform
power, itc, freqs = tfr_array_stockwell(amp_array, sfreq=Fs,
                                        fmin=fmin, fmax=fmax, 
                                        # decim=1, n_jobs=1,
                                        width=.3, return_itc=True)#,
                                        # n_fft=len(t))
x, y = np.meshgrid(t, freqs)

fig, ax = plt.subplots(3, 1, sharex=True)

ax[0].plot(t,amp)
ax[1].pcolormesh(x, y, power[0], shading='nearest')
ax[2].pcolormesh(x, y, itc[0], shading='nearest')

fig.tight_layout()
plt.show()

Figure 2021-05-20 134714