本文整理汇总了Python中numpy.fft函数的典型用法代码示例。如果您正苦于以下问题:Python fft函数的具体用法?Python fft怎么用?Python fft使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fft函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: phi
def phi(entry):
# Likelihood fonction
A = MesFonctions.matrice_A(entry[0:size].reshape((NbLigne, NbColonne)), methode="3")
x_ = (
floue.reshape(size) - MesFonctions.conv_matrices(A, entry[size:2 * size].reshape((NbLigne, NbColonne)),
"vecteur",
"coin"))
likelihood = np.dot(np.dot(x_, C_noise_inv), x_.transpose())
# Regularization term
image_ = entry[0:size] # /sum(sum(im))
PSF_ = entry[size:2 * size] # /sum(sum(PSF))
if regularization == "spectral":
fy_ = np.fft(image_)
y_ = 0
for i in range(0, size):
y_ = y_ + i * i * abs(fy_[i]) * abs(fy_[i])
regularization_im = y_
fz_ = np.fft(PSF_)
z_ = 0
for i in range(0, size):
z_ = z_ + i * i * abs(fz_[i]) * abs(fz_[i])
regularization_PSF = z_
elif regularization == "Tikhonov":
y_ = sum(image_ * image_)
regularization_im = math.sqrt(y_)
z_ = sum(PSF_ * PSF_)
regularization_PSF = math.sqrt(z_)
t_ = likelihood + regularization_im + regularization_PSF
return t_
示例2: process2ch
def process2ch(self,inputbuffers,timestamp):
if not self.update() : return None
fftsize = self.m_blockSize
audioSamples0 = inputbuffers[0]
audioSamples1 = inputbuffers[1]
complexSpectrum0 = fft(self.window*audioSamples0,fftsize)
complexSpectrum1 = fft(self.window*audioSamples1,fftsize)
magnitudeSpectrum0 = abs(complexSpectrum0)[0:fftsize/2] / (fftsize/2)
magnitudeSpectrum1 = abs(complexSpectrum1)[0:fftsize/2] / (fftsize/2)
# do the computation
melSpectrum0 = self.warpSpectrum(magnitudeSpectrum0)
melCepstrum0 = self.getMFCCs(melSpectrum0,cn=True)
melSpectrum1 = self.warpSpectrum(magnitudeSpectrum1)
melCepstrum1 = self.getMFCCs(melSpectrum1,cn=True)
outputs = FeatureSet()
outputs[0] = Feature(hstack((melCepstrum1[self.cnull:],melCepstrum0[self.cnull:])))
outputs[1] = Feature(hstack((melSpectrum1,melSpectrum0)))
return outputs
示例3: calculate_FROG
def calculate_FROG(self):
self.FROGxmin = self.t[0]
self.FROGxmax = self.t[-1]
self.FROGdeltax = (self.t[-1]-self.t[0])/self.NT
self.FROGymin = self.frequencies[0]
self.FROGymax = self.frequencies[-1]
self.FROGdeltay = (self.frequencies[-1]-self.frequencies[0])/self.NT
return
#negative delay
for i in xrange(self.NT/2):
self.field = zeros((self.NT))
self.field[i:] = (self.ElectricField[:self.NT-i]*self.ElectricField[i:])**2
self.field_fft = fft(self.field)
self.field_fft[:self.NT/2] = zeros((self.NT/2)) #no negative freq
self.FROG[:,self.NT/2-i] = abs(self.field_fft[self.NT/2:])**2#fftshift(abs(self.field_fft[self.NT/2:])**2)
#positive delay
for i in xrange(self.NT/2):
self.field = zeros((self.NT))
self.field[i:] = (self.ElectricField[i:]*self.ElectricField[:self.NT-i])**2
self.field_fft = fft(self.field)
self.field_fft[:self.NT/2] = zeros((self.NT/2)) #no negative freq
self.FROG[:,self.NT/2+i] = abs(self.field_fft[self.NT/2:])**2#fftshift(abs(self.field_fft[self.NT/2:])**2)
self.FROG /= ma.max(abs(self.FROG))
示例4: calculate_FROG
def calculate_FROG(self):
self.FROGxmin = self.t[0]
self.FROGxmax = self.t[-1]
self.FROGymin = self.get_frequencies()[0]
self.FROGymax = self.get_frequencies()[-1]
ElectricField = real(self.ElectricField)
# complex field
#negative delay
for i in xrange(self.NT/2):
self.field = zeros((self.NT))
self.field[i:] = (ElectricField[:self.NT-i]*ElectricField[i:])**2
self.field_fft = fft(self.field)
self.FROG[:,self.NT/2-i] = fftshift(abs(self.field_fft)**2)
#positive delay
for i in xrange(self.NT/2):
self.field = zeros((self.NT))
self.field[i:] = (ElectricField[i:]*ElectricField[:self.NT-i])**2
self.field_fft = fft(self.field)
self.FROG[:,self.NT/2+i] = fftshift(abs(self.field_fft)**2)
self.FROG /= ma.max(abs(self.FROG))
示例5: myFFT
def myFFT(self,x):
tt,xx,uu = self.Traj(x,U=1,fast=0)
n,gn=len(tt),len(uu)
grsU = [TGraph(n,tt,uu[i]) for i in range(5)]
ffts = [fft(uu[i]).real for i in range(5)]
ffts2= [fft(uu[i]).imag for i in range(5)]
fftUt = [array('d') for i in range(5)]
fftUt2 = [array('d') for i in range(5)]
for i in range(5):
for j in range(n):
fftUt[i].append(ffts[i][j]**2+ffts2[i][j]**2)
fftUt2[i].append(ffts[i][j])
fftUr = [TGraph(n,tt,fftUt[i]) for i in range(5)]
fftUi = [TGraph(n,tt,fftUt2[i]) for i in range(5)]
c1 = TCanvas()
c1.Divide(3,2)
for i in range(5):
c1.cd(i+1)
fftUi[i].Draw("APE")
fftsx1 = [fft(xx[i]).real for i in range(3)]
fftsx2= [fft(xx[i]).imag for i in range(3)]
fftsxA = [array('d') for i in range(3)]
for i in range(3):
for j in range(n):
fftsxA[i].append(fftsx1[i][j])
fftxr = [TGraph(n,tt,fftsxA[i]) for i in range(3)]
c2 = TCanvas()
c2.Divide(3)
for i in range(3):
c2.cd(i+1)
fftxr[i].Draw("APE")
zwom = input("numbers continue")
示例6: length_shift
def length_shift(signalin, tscale):
L = len(signalin)
# signal blocks for processing and output
phi = zeros(N)
out = zeros(N, dtype=complex)
sigout = zeros(L/tscale+N)
# max input amp, window
amp = max(signalin)
win = hanning(N)
p = 0
pp = 0
while p < L-(N+H):
print p, ',', (L-N-H)
# take the spectra of two consecutive windows
p1 = int(p)
spec1 = fft(win*signalin[p1:p1+N])
spec2 = fft(win*signalin[p1+H:p1+N+H])
# take their phase difference and integrate
phi += (angle(spec2) - angle(spec1))
# bring the phase back to between pi and -pi
for i in phi:
while i < -pi: i += 2*pi
while i >= pi: i -= 2*pi
out.real, out.imag = cos(phi), sin(phi)
# inverse FFT and overlap-add
sigout[pp:pp+N] += (win*ifft(abs(spec2)*out)).real
pp += H
p += H*tscale
return array(amp * sigout / max(sigout))
示例7: fft_sheet
def fft_sheet(f, t):
# Transform along y
fk = fft(f, axis=0)
# Phase shift (to make periodic in x)
fk *= exp(1j * S * t * ky * x)
# Transform along x
return fft(fk, axis=1)
示例8: fft_covariance
def fft_covariance(sample):
'''
returns the covariance matrix and index of each item for a dimension-list of sample-lists
[d0, d1, ...,dd] where d0 is the first dimension containing n samples.
n.b. numpy 1.7rc1 has numpy.pad to pad array. currently running 1.6.2 (released version)
so imported rc1 version.
'''
A = numpy.array(sample)
d, n = A.shape
Q = numpy.ones(1) if(d==2) else numpy.ones((d, d))
idx = [[1]] if(d==2) else [list([1.] * d) for i in range(d)]
nm1 = float(n - 1)
#prep for fft
A = (A.transpose() - numpy.mean(A, axis=1)).transpose()
A = npp.pad(A,(0,len(pad(n))), 'constant', constant_values=(0,0))[:d, : ]
#2x2return
if (d == 2):
corr = ifft(fft(A[0, :]) * np.conjugate(fft(A[1, :])))
maxcorr = getmax(corr)
Q[0] = maxcorr[0] / nm1
idx[0] = maxcorr[1]
else:
for i in range(d):
for j in range(i, d):
corr = ifft(fft(A[i, :]) * np.conjugate(fft(A[j, : ])))
maxcorr = getmax(corr)
Q[i][j] = maxcorr[0] / nm1
idx[i][j] = maxcorr[1]
if i != j:
Q[j][i] = Q[i][j]
return Q, idx
示例9: FFT_Correlation
def FFT_Correlation(x,y):
"""
FFT-based correlation, much faster than numpy autocorr.
x and y are row-based vectors of arbitrary lengths.
This is a vectorized implementation of O(N*log(N)) flops.
"""
lengthx = x.shape[0]
lengthy = y.shape[0]
x = np.reshape(x,(1,lengthx))
y = np.reshape(y,(1,lengthy))
length = np.array([lengthx, lengthy]).min()
x = x[:length]
y = y[:length]
fftx = fft(x, 2 * length - 1, axis=1) #pad with zeros
ffty = fft(y, 2 * length - 1, axis=1)
corr_xy = fft.ifft(fftx * np.conjugate(ffty), axis=1)
corr_xy = np.real(fft.fftshift(corr_xy, axes=1)) #should be no imaginary part
corr_yx = fft.ifft(ffty * np.conjugate(fftx), axis=1)
corr_yx = np.real(fft.fftshift(corr_yx, axes=1))
corr = 0.5 * (corr_xy[:,length:] + corr_yx[:,length:]) / range(1,length)[::-1]
return np.reshape(corr,corr.shape[1])
示例10: diff_spectrum
def diff_spectrum(self, ref_mic):
ref_signal = self.microphones[ref_mic[0]][ref_mic[1]].signal
min_sig_len = min(ref_signal.shape[0], self.signal.shape[0])
wnd = 0.54 - 0.46*numpy.cos(2*pi*numpy.arange(min_sig_len)/min_sig_len)
fft_sum = fftshift(fft(self.signal[0:min_sig_len]*wnd))/min_sig_len
fft_ref = fftshift(fft(ref_signal[0:min_sig_len]*wnd))/min_sig_len
fft_rel = (fft_sum / fft_ref).real
fft_freq = numpy.linspace(-self.samplerate/2, self.samplerate/2, min_sig_len);
return {"x":fft_freq, "y":fft_rel}
示例11: fftconv
def fftconv(x, y):
""" Convolution of x and y using the FFT convolution theorem. """
N = len(x)
n = int(2 ** np.ceil(np.log2(N))) + 1
X, Y, x_y = fft(x, n), fft(y, n), []
for i in range(n):
x_y.append(X[i] * Y[i])
# Returns the inverse Fourier transform with padding correction
return fft.ifft(x_y)[4:N+4]
示例12: conv
def conv(x,y):
x1=np.zeros(x.size)
x1[0:x.size]=x #added zeros
y1=np.zeros(y.size)
y1[0:y.size]=y #added zeros
x1ft=np.fft(x1)
y1ft=np.fft(y1)
vect1=np.real(np.ifft(x1ft*y1ft))
return vect1[0:x.size]
示例13: my_fft
def my_fft(sample, inverse=False):
n = len(sample)
if n == 1:
return sample
else:
Feven = fft([sample[i] for i in xrange(0, n, 2)])
Fodd = fft([sample[i] for i in xrange(1, n, 2)])
combined = [0] * n
for m in xrange(n/2):
combined[m] = Feven[m] + omega(n, -m, inverse) * Fodd[m]
combined[m + n/2] = Feven[m] - omega(n, -m, inverse) * Fodd[m]
return combined
示例14: solve
def solve(self, x, rho):
Nx, = rho.shape
k = fftfreq(Nx) * 2*np.pi*Nx
k[0] = 1.0
rhohat = fft(rho)
rhobar = rhohat[0] / rho.size
phihat = rhohat / -k**2 + fft(0.5 * rhobar * x**2)
gphhat = 1.j * k * phihat
phi = ifft(phihat).real
gph = ifft(1.j * k * phihat).real
soln = np.zeros(rho.shape + (4,))
soln[:,0] = phi
soln[:,1] = gph
return soln
示例15: showResponse
def showResponse(x, f, a, w0, Q):
fmax = 200.0
# smooth it out with averaging:
df = 1.0
fatf = arange(0,fmax,df)
n = len(fatf)
fatX = zeros(n)
print '\nfft\'ing to find the frequency response...'
X = fft(x)
for i in range(n):
fslice = where(abs(f-fatf[i])<df/2)[0]
fatX[i] = mean(abs(X[fslice]))
norm = mean(fatX[0:10])
fatX = fatX/norm
# plot the response with the theoretical curve overlaid:
plot(fatf, fatX, 'k.', label = 'simulated data')
title('response of damping system')
xlabel('frequency (Hz)')
ylabel('abs(fft(x)) normalized to low f')
Omega = 2*pi*fatf/w0
zeta = 1.0/2.0/Q
theory = 1/sqrt( (1-Omega**2)**2 + (2*zeta*Omega)**2 )
semilogy(fatf, theory, label = 'theory')
legend()
show()