def test_minvar(): from spectrum import tools res = minvar(marple_data, 15, 1.) psd = res[0] newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq return newpsd
def test_arburg_functional(): ar, P, k = arburg(marple_data, order=15) PSD = arma2psd(ar) newpsd = cshift(PSD, len(PSD)//2) # switch positive and negative freq return newpsd
def create_all_psd(): f = pylab.linspace(0, 1, 4096) pylab.clf() pylab.figure(figsize=(12,8)) #MA 15 order b, rho = spectrum.ma(data, 15, 30) psd = spectrum.arma2psd(B=b, rho=rho) newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='MA 15') #ARMA 15 order a, b, rho = spectrum.arma_estimate(data, 15,15, 30) psd = spectrum.arma2psd(A=a,B=b, rho=rho) newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='ARMA 15,15') #yulewalker ar, P,c = spectrum.aryule(data, 15, norm='biased') psd = spectrum.arma2psd(A=ar, rho=P) newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='YuleWalker 15') #burg method ar, P,k = spectrum.arburg(data, order=15) psd = spectrum.arma2psd(A=ar, rho=P) newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='Burg 15') #covar method af, pf, ab, pb, pv = spectrum.arcovar_marple(data, 15) psd = spectrum.arma2psd(A=af, B=ab, rho=pf) newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='covar 15') #modcovar method a, p, pv = spectrum.modcovar_marple(data, 15) psd = spectrum.arma2psd(A=a) newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='modcovar 15') #correlogram psd = spectrum.CORRELOGRAMPSD(data, data, lag=15) newpsd = tools.cshift(psd, len(psd)/2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='correlogram 15') #minvar psd = spectrum.minvar(data, 15) #newpsd = tools.cshift(psd, len(psd)/2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd/max(newpsd)), label='MINVAR 15') #music psd,db = spectrum.music(data, 15, 11) pylab.plot(f, 10 * pylab.log10(psd/max(psd)), '--',label='MUSIC 15') #ev music psd,db = spectrum.ev(data, 15, 11) pylab.plot(f, 10 * pylab.log10(psd/max(psd)), '--',label='EV 15') pylab.legend(loc='upper left', prop={'size':10}, ncol=2) pylab.ylim([-80,10]) pylab.savefig('psd_all.png')
def test_minvar(): from spectrum import tools res = minvar(marple_data, 15, 1.) psd = res[0] newpsd = tools.cshift(psd, len(psd)//2) # switch positive and negative freq return newpsd
def create_all_psd(): f = pylab.linspace(0, 1, 4096) pylab.clf() pylab.figure(figsize=(12, 8)) #MA 15 order b, rho = spectrum.ma(data, 15, 30) psd = spectrum.arma2psd(B=b, rho=rho) newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='MA 15') #ARMA 15 order a, b, rho = spectrum.arma_estimate(data, 15, 15, 30) psd = spectrum.arma2psd(A=a, B=b, rho=rho) newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='ARMA 15,15') #yulewalker ar, P, c = spectrum.aryule(data, 15, norm='biased') psd = spectrum.arma2psd(A=ar, rho=P) newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='YuleWalker 15') #burg method ar, P, k = spectrum.arburg(data, order=15) psd = spectrum.arma2psd(A=ar, rho=P) newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='Burg 15') #covar method af, pf, ab, pb, pv = spectrum.arcovar_marple(data, 15) psd = spectrum.arma2psd(A=af, B=ab, rho=pf) newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='covar 15') #modcovar method a, p, pv = spectrum.modcovar_marple(data, 15) psd = spectrum.arma2psd(A=a) newpsd = tools.cshift(psd, len(psd) // 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='modcovar 15') #correlogram psd = spectrum.CORRELOGRAMPSD(data, data, lag=15) newpsd = tools.cshift(psd, len(psd) / 2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='correlogram 15') #minvar psd = spectrum.minvar(data, 15) #newpsd = tools.cshift(psd, len(psd)/2) # switch positive and negative freq pylab.plot(f, 10 * pylab.log10(newpsd / max(newpsd)), label='MINVAR 15') #music psd, db = spectrum.music(data, 15, 11) pylab.plot(f, 10 * pylab.log10(psd / max(psd)), '--', label='MUSIC 15') #ev music psd, db = spectrum.ev(data, 15, 11) pylab.plot(f, 10 * pylab.log10(psd / max(psd)), '--', label='EV 15') pylab.legend(loc='upper left', prop={'size': 10}, ncol=2) pylab.ylim([-80, 10]) pylab.savefig('psd_all.png')
sigma_2 = 2 dbDiff = 3 # Ruido 3dB por debajo del pico de la seƱal dbSignal = 20 * np.log10(a0) an = 10**((dbSignal - dbDiff) / 20) n = an * np.transpose( np.vstack([np.random.normal(u, np.sqrt(sigma_2), N) for ff in f0])) x = s + n freqX, Xw = sig.welch(x, axis=0) estimador = np.zeros(Xw.shape[0]) for r in range(0, Xw.shape[0]): estimador[r] = freqX[np.argmax(Xw[:, r])] varWelch10 = np.var(estimador) meanWelch10 = np.mean(estimador) meanWelch10 = meanWelch10 * fs estimadorCorr = np.zeros(k) for r in range(0, k): correlogram = CORRELOGRAMPSD(x[:, r], x[:, r], lag=100) correlogram = cshift(correlogram, len(correlogram) / 2) correlogram = correlogram[int(correlogram.size / 2):int(correlogram.size)] f = np.linspace(0, 0.5, int(len(correlogram))) estimadorCorr[r] = f[np.argmax(correlogram)] varCorr10 = np.var(estimadorCorr) meanCorr10 = np.mean(estimadorCorr) meanCorr10 = meanCorr10 * fs
def test_arburg_functional(): ar, P, k = arburg(marple_data, order=15) PSD = arma2psd(ar) newpsd = cshift(PSD, len(PSD) // 2) # switch positive and negative freq return newpsd