def morlet(sfreq, freqs, n_cycles=7.0, sigma=None, zero_mean=False):
 Ws = list()
 n_cycles = np.atleast_1d(n_cycles)
 if ((n_cycles.size != 1) and (n_cycles.size != len(freqs))):
  raise ValueError('n_cycles should be fixed or defined for each frequency.')
 for (k, f) in enumerate(freqs):
  if (len(n_cycles) != 1):
   this_n_cycles = n_cycles[k]
  else:
   this_n_cycles = n_cycles[0]
  if (sigma is None):
   sigma_t = (this_n_cycles / ((2.0 * np.pi) * f))
  else:
   sigma_t = (this_n_cycles / ((2.0 * np.pi) * sigma))
  t = np.arange(0.0, (5.0 * sigma_t), (1.0 / sfreq))
  t = np.r_[((- t[::(-1)]), t[1:])]
  oscillation = np.exp(((((2.0 * 1j) * np.pi) * f) * t))
  gaussian_enveloppe = np.exp(((- (t ** 2)) / (2.0 * (sigma_t ** 2))))
  if zero_mean:
   real_offset = np.exp(((-2) * (((np.pi * f) * sigma_t) ** 2)))
   oscillation -= real_offset
  W = (oscillation * gaussian_enveloppe)
  W /= (sqrt(0.5) * linalg.norm(W.ravel()))
  Ws.append(W)
 return Ws

def morlet ( sfreq , freqs , n_cycles = 7.0 , sigma = None , zero_mean = False ) : Ws = list ( ) n_cycles = np . atleast_1d ( n_cycles ) if ( ( n_cycles . size != 1 ) and ( n_cycles . size != len ( freqs ) ) ) : raise ValueError ( 'n_cycles should be fixed or defined for each frequency.' ) for ( k , f ) in enumerate ( freqs ) : if ( len ( n_cycles ) != 1 ) : this_n_cycles = n_cycles [ k ] else : this_n_cycles = n_cycles [ 0 ] if ( sigma is None ) : sigma_t = ( this_n_cycles / ( ( 2.0 * np . pi ) * f ) ) else : sigma_t = ( this_n_cycles / ( ( 2.0 * np . pi ) * sigma ) ) t = np . arange ( 0.0 , ( 5.0 * sigma_t ) , ( 1.0 / sfreq ) ) t = np . r_ [ ( ( - t [ : : ( - 1 ) ] ) , t [ 1 : ] ) ] oscillation = np . exp ( ( ( ( ( 2.0 * 1j ) * np . pi ) * f ) * t ) ) gaussian_enveloppe = np . exp ( ( ( - ( t ** 2 ) ) / ( 2.0 * ( sigma_t ** 2 ) ) ) ) if zero_mean : real_offset = np . exp ( ( ( - 2 ) * ( ( ( np . pi * f ) * sigma_t ) ** 2 ) ) ) oscillation -= real_offset W = ( oscillation * gaussian_enveloppe ) W /= ( sqrt ( 0.5 ) * linalg . norm ( W . ravel ( ) ) ) Ws . append ( W ) return Ws
complex morlet wavelet .