def test_pmtm(): data = data_cosine(N=64, A=0.1, sampling=1024, freq=200) res = pmtm(data, 2.5, 4, show=False) res = pmtm(data, 2.5, show=False) res = pmtm(data, 2.5, show=False, method="eigen") res = pmtm(data, 2.5, show=False, method="unity") res = pmtm(data, 2.5, method="eigen", show=True) res = pmtm(data, 2.5, method="adapt", show=True) #res = pmtm(data, 2.5, show=False, method="eigen", show=True) # e and v must be provided together try: res = pmtm(data, 2.5, show=False, e=1, v=None) assert False except: assert True # provide v and e v, e = dpss(64, 4, 2) pmtm(marple_data, NW=4, k=2, v=v, e=e) try: pmtm(marple_data, NW=None, k=2) assert False except: assert True
def dpss_cached(length,half_bandwidth_parameter): ''' Get a collection of DPSS tapers. The number of tapers equals the half bandwidth parameter times two. For legacy reasons the tapers are returned transposed such that the first dimension indexes tapers rather than time. The advantage of using this function is that computing DPSS is expensive. This function caches the results in RAM. Parameters ---------- length : integer length of the domain for which to compute the DPSS half_bandwidth_parameter : number The number of is the half_bandwidth_parameter*2 Returns ------- ndarray: tapers.T a transposed list of DPSS tapers ndarray: taper eigenvalues ( weights ) ''' tapers,eigen = dpss(length,half_bandwidth_parameter) return tapers.T,eigen
def test_pmtm(): data = data_cosine(N=64, A=0.1, sampling=1024, freq=200) res = pmtm(data, 2.5, 4, show=False) res = pmtm(data, 2.5, show=False) res = pmtm(data, 2.5, show=False, method="eigen") res = pmtm(data, 2.5, show=False, method="unity") res = pmtm(data, 2.5, method="eigen", show=True) res = pmtm(data, 2.5, method="adapt", show=True) #res = pmtm(data, 2.5, show=False, method="eigen", show=True) # e and v must be provided together try: res = pmtm(data, 2.5, show=False, e=1, v=None) assert False except: assert True # provide v and e v,e = dpss(64,4,2) pmtm(marple_data, NW=4, k=2, v=v, e=e); try: pmtm(marple_data, NW=None, k=2); assert False except: assert True
def fftppc_biased_multitaper(snippits,Fs=1000,k=4): # some precision trouble # use quad precition # PPC doesn't care about scale so also rescale? #nippits = array(snippits,dtype=__PPC_FP_TYPE__) #snippits = snippits/std(snippits) M,window = shape(snippits) print(M,window) if M<=window: warn('WARNING SAMPLES SEEM TRANSPOSED?') #print('BROKE FOR MATLAB CHECK REMOVE +1 on K KEEP ALL TAPERS') #tapers = dpss(window,NW=0.499*(k+1),k=(k+1))[0][:,:-1] tapers = dpss(window,NW=0.499*k,k=k)[0] results = [] unit = lambda x:x/abs(x) average = [mean(unit(fft(snippits*taper)),0) for taper in tapers.T] raw = mean([abs(x)**2 for x in average],0) phases = angle(mean([exp(2j*pi*angle(x)) for x in average],0)) freqs = fftfreq(window,1./Fs) return freqs[:(window+1)/2], raw[:(window+1)/2], phases[:(window+1)/2]
def test_dpss(): dpss(64, 2.5, 4)
def slepian(n_samp, num_tapers): return dpss(N = n_samp, NW=int((num_tapers+1)/2), k=None)[0]