0
$\begingroup$

I am trying to create time-frequency representation of my brain signal. I would like to create the data for frequencies from 0hz - 120hz (so it can cover, delta, theta, alpha, beta, low-gamma and high-gamma frequency bands).

Here is my code:

First, I visualize my brain signal:

ax1.plot(list(range(stc_broca_tmp2.shape[1])), brain_signal, linewidth=3, color='blue')

Results:

enter image description here

brain_signal.shape

(353191,)

Then I use the following code to compute its time-frequency representation:

t = np.linspace(0, signal_length, signal_length, endpoint=False)
#brain_signal = stc_broca[3, :]
widths = np.arange(0, 130)
cwtmatr = signal.cwt(brain_signal, signal.ricker, widths)
plt.imshow(cwtmatr, extent=[0, signal_length, 0, 130], cmap='PRGn', aspect='auto',
           vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max())
plt.show()

However, I get the following error:

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in 2 #brain_signal = stc_broca[3, :] 3 widths = np.arange(0, 130) ----> 4 cwtmatr = signal.cwt(brain_signal, signal.ricker, widths) 5 plt.imshow(cwtmatr, extent=[0, signal_length, 0, 130], cmap='PRGn', aspect='auto', 6 vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max())

/usr/local/lib/python3.6/dist-packages/scipy/signal/wavelets.py in cwt(data, wavelet, widths, dtype, **kwargs) 478 N = int(N) 479 wavelet_data = np.conj(wavelet(N, width, **kwargs)[::-1]) --> 480 output[ind] = convolve(data, wavelet_data, mode='same') 481 return output

/usr/local/lib/python3.6/dist-packages/scipy/signal/signaltools.py in convolve(in1, in2, mode, method) 1276 # fastpath to faster numpy.convolve for 1d inputs when possible 1277 if _np_conv_ok(volume, kernel, mode): -> 1278 return np.convolve(volume, kernel, mode) 1279 1280 return correlate(volume, _reverse_and_conj(kernel), mode, 'direct')

<array_function internals> in convolve(*args, **kwargs)

~/.local/lib/python3.6/site-packages/numpy/core/numeric.py in convolve(a, v, mode) 813 raise ValueError('a cannot be empty') 814 if len(v) == 0: --> 815 raise ValueError('v cannot be empty') 816 mode = _mode_from_name(mode) 817 return multiarray.correlate(a, v[::-1], mode)

ValueError: v cannot be empty

My brain signal is not empty. Why do I receive such an error?

Thanks in advance

$\endgroup$
1
  • $\begingroup$ This is a programming question better suited for StackOveflow. I also strongly discourage using PyWavelets's or Scipy's CWT. $\endgroup$ Jul 25 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.