<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from nitime . lazy import scipy_fftpack as fftpack <EOL> def wfmorlet_fft ( f0 , sd , sampling_rate , ns = <NUM_LIT:5> , nt = None ) : <EOL> """<STR_LIT>""" <EOL> if nt == None : <EOL> st = <NUM_LIT:1.> / ( <NUM_LIT> * np . pi * sd ) <EOL> nt = <NUM_LIT:2> * int ( ns * st * sampling_rate ) + <NUM_LIT:1> <EOL> f = fftpack . fftfreq ( nt , <NUM_LIT:1.> / sampling_rate ) <EOL> wf = <NUM_LIT:2> * np . exp ( - ( f - f0 ) ** <NUM_LIT:2> / ( <NUM_LIT:2> * sd ** <NUM_LIT:2> ) ) * np . sqrt ( sampling_rate / <EOL> ( np . sqrt ( np . pi ) * sd ) ) <EOL> wf [ f < <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> wf [ f == <NUM_LIT:0> ] /= <NUM_LIT:2> <EOL> return wf <EOL> def wmorlet ( f0 , sd , sampling_rate , ns = <NUM_LIT:5> , normed = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> st = <NUM_LIT:1.> / ( <NUM_LIT> * np . pi * sd ) <EOL> w_sz = float ( int ( ns * st * sampling_rate ) ) <EOL> t = np . arange ( - w_sz , w_sz + <NUM_LIT:1> , dtype = float ) / sampling_rate <EOL> if normed == '<STR_LIT>' : <EOL> w = np . exp ( - t ** <NUM_LIT:2> / ( <NUM_LIT> * st ** <NUM_LIT:2> ) ) * np . exp ( <EOL> <NUM_LIT> * np . pi * f0 * t ) / np . sqrt ( np . sqrt ( np . pi ) * st * sampling_rate ) <EOL> elif normed == '<STR_LIT>' : <EOL> w = np . exp ( - t ** <NUM_LIT:2> / ( <NUM_LIT> * st ** <NUM_LIT:2> ) ) * np . exp ( <EOL> <NUM_LIT> * np . pi * f0 * t ) * <NUM_LIT:2> * sd * np . sqrt ( <NUM_LIT:2> * np . pi ) / sampling_rate <EOL> else : <EOL> assert <NUM_LIT:0> , '<STR_LIT>' % normed <EOL> return w <EOL> def wlogmorlet_fft ( f0 , sd , sampling_rate , ns = <NUM_LIT:5> , nt = None ) : <EOL> """<STR_LIT>""" <EOL> if nt == None : <EOL> st = <NUM_LIT:1.> / ( <NUM_LIT> * np . pi * sd ) <EOL> nt = <NUM_LIT:2> * int ( ns * st * sampling_rate ) + <NUM_LIT:1> <EOL> f = fftpack . fftfreq ( nt , <NUM_LIT:1.> / sampling_rate ) <EOL> sfl = np . log ( <NUM_LIT:1> + <NUM_LIT:1.> * sd / f0 ) <EOL> wf = ( <NUM_LIT:2> * np . exp ( - ( np . log ( f ) - np . log ( f0 ) ) ** <NUM_LIT:2> / ( <NUM_LIT:2> * sfl ** <NUM_LIT:2> ) ) * <EOL> np . sqrt ( sampling_rate / ( np . sqrt ( np . pi ) * sd ) ) ) <EOL> wf [ f < <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> wf [ f == <NUM_LIT:0> ] /= <NUM_LIT:2> <EOL> return wf <EOL> def wlogmorlet ( f0 , sd , sampling_rate , ns = <NUM_LIT:5> , normed = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> st = <NUM_LIT:1.> / ( <NUM_LIT> * np . pi * sd ) <EOL> w_sz = int ( ns * st * sampling_rate ) <EOL> wf = wlogmorlet_fft ( f0 , sd , sampling_rate = sampling_rate , nt = <NUM_LIT:2> * w_sz + <NUM_LIT:1> ) <EOL> w = fftpack . fftshift ( fftpack . ifft ( wf ) ) <EOL> if normed == '<STR_LIT>' : <EOL> w /= w . real . sum ( ) <EOL> elif normed == '<STR_LIT>' : <EOL> w /= w . real . max ( ) <EOL> elif normed == '<STR_LIT>' : <EOL> w /= np . sqrt ( ( w ** <NUM_LIT:2> ) . sum ( ) ) <EOL> else : <EOL> assert <NUM_LIT:0> , '<STR_LIT>' % normed <EOL> return w </s>
