Skip to content

Commit

Permalink
Merge pull request #1 from ThomasLecocq/master
Browse files Browse the repository at this point in the history
changed np.fft to scipy.fftpack for improved performances
  • Loading branch information
ThomasLecocq committed Aug 25, 2013
2 parents dc7c8cd + 9914e66 commit fcabc0a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions MWCS.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import numpy as np
# import matplotlib.pyplot as plt
import logging
import scipy.fftpack


def nextpow2(x):
return np.ceil(np.log2(np.abs(x)))
Expand Down Expand Up @@ -67,8 +69,8 @@ def mwcs(ccCurrent,ccReference,fmin,fmax,sampRate,tmin,windL,step):
cri -= np.mean(cri)
cri *= tp

Fcur = np.fft.fft(cci, n=int(padd))[:padd/2]
Fref = np.fft.fft(cri, n=int(padd))[:padd/2]
Fcur = scipy.fftpack.fft(cci, n=int(padd))[:padd/2]
Fref = scipy.fftpack.fft(cri, n=int(padd))[:padd/2]

Fcur2 = np.real(Fcur)**2 + np.imag(Fcur)**2
Fref2 = np.real(Fref)**2 + np.imag(Fref)**2
Expand All @@ -84,7 +86,7 @@ def mwcs(ccCurrent,ccReference,fmin,fmax,sampRate,tmin,windL,step):
dcs = np.abs(X)

#Find the values the frequency range of interest
freqVec = np.fft.fftfreq(len(X)*2,1./sampRate)[:padd/2]
freqVec = scipy.fftpack.fftfreq(len(X)*2,1./sampRate)[:padd/2]
indRange = np.argwhere(np.logical_and(freqVec >= fmin,freqVec <= fmax))

# Get Coherence and its mean value
Expand Down
5 changes: 3 additions & 2 deletions myCorr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack

def nextpow2(x):
return np.ceil(np.log2(np.abs(x)))
Expand All @@ -23,7 +24,7 @@ def myCorr(data, maxlag, plot=False):
Nc = 2* Nt - 1
Nfft = 2**nextpow2(Nc)

corr = np.fft.fft(data,int(Nfft),axis=1)
corr = scipy.fftpack.fft(data,int(Nfft),axis=1)

if plot:
plt.subplot(211)
Expand All @@ -32,7 +33,7 @@ def myCorr(data, maxlag, plot=False):
plt.plot(np.arange(len(corr[1]))*0.05,np.abs(corr[1]))

corr = np.conj(corr[couples[0]]) * corr[couples[1]]
corr = np.real(np.fft.ifft(corr)) / Nt
corr = np.real(scipy.fftpack.ifft(corr)) / Nt
corr = np.concatenate( (corr[-Nt+1:],corr[:Nt+1]) )

if plot:
Expand Down
5 changes: 3 additions & 2 deletions whiten.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack

def nextpow2(x):
return np.ceil(np.log2(np.abs(x)))
Expand Down Expand Up @@ -28,7 +29,7 @@ def whiten(matsign, Npts, tau, frebas, frehaut,plot=False,tmp=False):
high = J[-1] + Napod
if high > len(matsign)/2 : high= len(matsign)/2

FFTRawSign = np.fft.fft(matsign)
FFTRawSign = scipy.fftpack.fft(matsign)

if plot:
plt.subplot(412)
Expand Down Expand Up @@ -77,7 +78,7 @@ def whiten(matsign, Npts, tau, frebas, frehaut,plot=False,tmp=False):
plt.plot(axis,np.abs(FFTRawSign))
plt.xlim(0,max(axis))

wmatsign = np.real(np.fft.ifft(FFTRawSign))
wmatsign = np.real(scipy.fftpack.ifft(FFTRawSign))

del matsign, FFTRawSign
if plot:
Expand Down

0 comments on commit fcabc0a

Please sign in to comment.