本文整理汇总了Python中numpy.hanning函数的典型用法代码示例。如果您正苦于以下问题:Python hanning函数的具体用法?Python hanning怎么用?Python hanning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hanning函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hanning_taper
def hanning_taper(self, side='both', channels=None, offset=0):
"""Hanning taper
Parameters
----------
side : {'left', 'right', 'both'}
channels : {None, int}
The number of channels to taper. If None 5% of the total
number of channels are tapered.
offset : int
Returns
-------
channels
"""
if channels is None:
channels = int(round(len(self()) * 0.02))
if channels < 20:
channels = 20
dc = self.data
if side == 'left' or side == 'both':
dc[..., offset:channels+offset] *= (
np.hanning(2*channels)[:channels])
dc[...,:offset] *= 0.
if side== 'right' or side == 'both':
if offset == 0:
rl = None
else:
rl = -offset
dc[..., -channels-offset:rl] *= (
np.hanning(2*channels)[-channels:])
if offset != 0:
dc[..., -offset:] *= 0.
return channels
示例2: compute_window
def compute_window(x, crop1, crop2, MARGIN=0, Pow=1):
#
# __margin__
# / \
# c1 c2
# 1D Function
# -----------
w = np.ones(x)
c1 = crop1 + MARGIN
c2 = crop2+MARGIN
w[:c1] = np.hanning(2*c1)[:c1]**Pow
w[-c2:] = np.hanning(2*c2)[-c2:]**Pow
#~ import matplotlib.pyplot as plt
#~ plt.figure()
#~ plt.plot(w)
#~ plt.plot(1-w)
#~ plt.show()
# Turn into 2D : distance to the center
# -------------------------------------
R, C = generate_coords((x, x))
rmax = int(R.max()-0.5)
M = np.int32(rmax-np.sqrt((R+0.5)**2+(C+0.5)**2));
M[M<0] = 0
return w[M]
示例3: ripoc
def ripoc(f, g, M = 50, fitting_shape = (9, 9)):
hy = numpy.hanning(f.shape[0])
hx = numpy.hanning(f.shape[1])
hw = hy.reshape(hy.shape[0], 1) * hx
ff = f * hw
gg = g * hw
F = scipy.fftpack.fft2(ff)
G = scipy.fftpack.fft2(gg)
F = scipy.fftpack.fftshift(numpy.log(numpy.abs(F)))
G = scipy.fftpack.fftshift(numpy.log(numpy.abs(G)))
FLP = logpolar(F, (F.shape[0] / 2, F.shape[1] / 2), M)
GLP = logpolar(G, (G.shape[0] / 2, G.shape[1] / 2), M)
R = poc(FLP, GLP)
angle = -R[1] / F.shape[0] * 360
scale = 1.0 - R[2] / 100
center = tuple(numpy.array(g.shape) / 2)
rot = cv2.getRotationMatrix2D(center, -angle, 1.0 + (1.0 - scale))
g_dash = cv2.warpAffine(g, rot, (g.shape[1], g.shape[0]), flags=cv2.INTER_LANCZOS4)
t = poc(f, g_dash)
return (t[1], t[2], angle, scale)
示例4: gen_spec
def gen_spec(self,x,m):
itsreal = np.isreal(x[0])
lx = x.size
nt = (lx +m -1) // m
xb = np.append(x,np.zeros(-lx+nt*m))
xc = np.append(np.roll(x,int(m/2)),np.zeros(nt*m - lx))
xr = np.reshape(xb, (m,nt), order='F') * np.outer(np.hanning(m),np.ones(nt))
xs = np.reshape(xc, (m,nt), order='F') * np.outer(np.hanning(m),np.ones(nt))
xm = np.zeros((m,2*nt),dtype='complex')
xm[:,::2] = xr
xm[:,1::2] = xs
#xm=xr
if itsreal:
spec = np.fft.fft(xm,m,axis=0)[int(m/2):]
else:
spec = np.fft.fftshift(np.fft.fft(xm,m,axis=0))
mx = np.max(spec)
pwr = 64*(20* np.log(np.abs(spec)/mx + 1e-6) + 60 )/60
return np.real(pwr)
示例5: hanningWindow
def hanningWindow(nx, ny, nPixX, nPixY):
"""
Return a Hanning window in 2D
Args:
nx (TYPE): number of pixels in x-direction of mask
ny (TYPE): number of pixels in y-direction of mask
nPixX (TYPE): number of pixels in x-direction of the transition
nPixY (TYPE): number of pixels in y-direction of the transition
Returns:
real: 2D apodization mask
"""
winX = np.hanning(nPixX)
winY = np.hanning(nPixY)
winOutX = np.ones(nx)
winOutX[0:nPixX/2] = winX[0:nPixX/2]
winOutX[-nPixX/2:] = winX[-nPixX/2:]
winOutY = np.ones(ny)
winOutY[0:nPixY/2] = winY[0:nPixY/2]
winOutY[-nPixY/2:] = winY[-nPixY/2:]
return np.outer(winOutX, winOutY)
示例6: test_calculate_lanczos_kernel
def test_calculate_lanczos_kernel(self):
"""
Tests the kernels implemented in C against their numpy counterpart.
"""
x = np.linspace(-5, 5, 11)
values = calculate_lanczos_kernel(x, 5, "hanning")
np.testing.assert_allclose(
values["only_sinc"], np.sinc(x), atol=1E-9)
np.testing.assert_allclose(
values["only_taper"], np.hanning(len(x)), atol=1E-9)
np.testing.assert_allclose(
values["full_kernel"], np.sinc(x) * np.hanning(len(x)),
atol=1E-9)
values = calculate_lanczos_kernel(x, 5, "blackman")
np.testing.assert_allclose(
values["only_sinc"], np.sinc(x), atol=1E-9)
np.testing.assert_allclose(
values["only_taper"], np.blackman(len(x)), atol=1E-9)
np.testing.assert_allclose(
values["full_kernel"], np.sinc(x) * np.blackman(len(x)),
atol=1E-9)
values = calculate_lanczos_kernel(x, 5, "lanczos")
np.testing.assert_allclose(
values["only_sinc"], np.sinc(x), atol=1E-9)
np.testing.assert_allclose(
values["only_taper"], np.sinc(x / 5.0), atol=1E-9)
np.testing.assert_allclose(
values["full_kernel"], np.sinc(x) * np.sinc(x / 5.0),
atol=1E-9)
示例7: bell
def bell(size, ratio):
n = size / ratio
first_half = numpy.hanning(n * 2)[:n] * 65535
r = size - n
second_half = numpy.hanning(r * 2)[r:] * 65535
bell = list(first_half) + list(second_half) + [0]
return bell
示例8: applyWindow
def applyWindow(self, window="hanning", ww=0, cf=0):
'''
Apply window function to frequency domain data
cf: the frequency the window is centered over [Hz]
ww: the window width [Hz], if ww equals 0 the window covers the full range
'''
self.info("Applying %s window ..." % window)
if window == "hanning":
if ww == 0:
w = np.hanning(self.numfreq)
else:
pos = int((cf - self.lowF) / self.deltaF)
halfwidth = int(ww / (2.0 * self.deltaF))
w = np.zeros(self.numfreq)
w[pos - halfwidth:pos + halfwidth] = np.hanning(2 * halfwidth)
elif window == "hamming":
if ww == 0:
w = np.hamming(self.numfreq)
else:
pos = int((cf - self.lowF) / self.deltaF)
halfwidth = int(ww / (2.0 * self.deltaF))
w = np.zeros(self.numfreq)
w[pos - halfwidth:pos + halfwidth] = np.hamming(2 * halfwidth)
elif window == "blackman":
if ww == 0:
w = np.blackman(self.numfreq)
else:
pos = int((cf - self.lowF) / self.deltaF)
halfwidth = int(ww / (2.0 * self.deltaF))
w = np.zeros(self.numfreq)
w[pos - halfwidth:pos + halfwidth] = np.blackman(2 * halfwidth)
self.data = self.data * w
self.done()
示例9: lcn_octaves
def lcn_octaves(X, kernel):
"""Apply octave-varying contrast normalization to an input with a given
kernel.
Notes:
* This is the variant introduced in the LVCE Section of Chapter 5.
* This approach is painfully heuristic, and tuned for the dimensions used
in this work (36 bpo, 7 octaves).
Parameters
----------
X : np.ndarray, ndim=2, shape[1]==252.
CQT representation, with 36 bins per octave and 252 filters.
kernel : np.ndarray
Convolution kernel (should be roughly low-pass).
Returns
-------
Z : np.ndarray
The processed output.
"""
if X.shape[-1] != 252:
raise ValueError(
"Apologies, but this method is currently designed for input "
"representations with a last dimension of 252.")
x_hp = highpass(X, kernel)
x_73 = local_l2norm(x_hp, np.hanning(73).reshape(1, -1))
x_37 = local_l2norm(x_hp, np.hanning(37).reshape(1, -1))
x_19 = local_l2norm(x_hp, np.hanning(19).reshape(1, -1))
x_multi = np.array([x_73, x_37, x_19]).transpose(1, 2, 0)
w = _create_triband_mask()**2.0
return (x_multi * w).sum(axis=-1)
示例10: load_signature
def load_signature(guids,sample_rate,nbits):
amp,ampS, t= .49,.49,.05 #Variable handels for Bits
tBit = np.arange(0,t*sample_rate+1)/float(sample_rate) #time Vector for Bits
F0,F1,Fsync = 19600, 19300, 19900 #Bits Carrier Frequency
y0=amp*np.cos(2*np.pi*F0*tBit) #Bit0
winB=np.hanning(len(y0)) #Applying Windows
y0=y0*winB
y1=amp*np.cos(2*np.pi*F1*tBit) #Bit1
y1=y1*winB #Applying Windows
ysync=ampS*np.cos(2*np.pi*Fsync*tBit) #Bit for Synchronization
winS=np.hanning(len(ysync)) #Applying Windows
ysync=ysync*winS
ySilence=amp*np.sin(2*np.pi*0*tBit) #Adding Silence in between all bits
y0=np.concatenate([ySilence,y0,ySilence,ysync]) #Bit0 coupled with silence and Sync
y1=np.concatenate([ySilence,y1,ySilence,ysync]) #Bit1 coupled with silence and Sync
guids1=guids[0] #First available guid
signature=ysync #Declare and place Sync
for g in guids1: #Complete Concatenated Signature
if g=='0': # concatenate Bit0
signature=np.concatenate([signature,y0])
else: # concatenate Bit1
signature=np.concatenate([signature,y1])
return signature
示例11: fft_data
def fft_data(arr, ft='lag'):
"""
Returns the windowed fft of a time/freq array along the time axis, freq axis, or both.
Parameters
==========
arr: complex array
(nfreq x ntimes) array of complex visibilities
ft: str
transform to return, either lag, m, or mlag
Returns
=======
Returns the fft array that was asked for in ft argument.
"""
freq_window = np.hanning(arr.shape[0])[:, np.newaxis]
time_window = np.hanning(arr.shape[-1])[np.newaxis, :]
if ft=='lag':
return np.fft.fftshift(np.fft.fft(freq_window * arr, axis=0), axes=0)
elif ft=='m':
return np.fft.fftshift(np.fft.fft(time_window * arr, axis=-1), axes=-1)
elif ft=='mlag':
return np.fft.fftshift(np.fft.fft2(freq_window * time_window * arr))
else:
raise Exception('only lag, m, or mlag allowed')
示例12: de_disperse
def de_disperse(Data, DM, del_t):
""" De-disperses pulsar data. First fourier transforms data along time axis then get
the fourier frequencies with length "ntimes". The FT is then multiplied by the delay
phase factor, correcting for dispersion, and data is transformed back.
Parameters
----------
Data : float or array of floats
Pulsar data array. Assumes (freq, corr_prod, time)
DM :
Pulsar dispersion measure in pc/cm**3
del_t:
Total observation time in seconds
Returns
-------
De-dispersed data
"""
n_times = Data.shape[-1]
FT_Data = np.fft.fft(np.hanning(n_times)[np.newaxis, :] * Data, axis=-1)
ft_freq = np.fft.fftfreq(n_times)
delay_nu = time_delay(DM, Data.shape[0])[0]
FT_Data = FT_Data * np.exp(2j * np.pi * ft_freq[np.newaxis, :] * delay_nu[:, np.newaxis] * n_times / del_t)
return np.fft.fft(np.hanning(n_times)[np.newaxis, :] * FT_Data, axis=-1)
示例13: spec_est2
def spec_est2(A,d1,d2,win=True):
""" computes 2D spectral estimate of A
obs: the returned array is fftshifted
and consistent with the f1,f2 arrays
d1,d2 are the sampling rates in rows,columns """
import numpy as np
l1,l2,l3 = A.shape
df1 = 1./(l1*d1)
df2 = 1./(l2*d2)
f1Ny = 1./(2*d1)
f2Ny = 1./(2*d2)
f1 = np.arange(-f1Ny,f1Ny,df1)
f2 = np.arange(-f2Ny,f2Ny,df2)
if win == True:
wx = np.matrix(np.hanning(l1))
wy = np.matrix(np.hanning(l2))
window_s = np.repeat(np.array(wx.T*wy),l3).reshape(l1,l2,l3)
else:
window_s = np.ones((l1,l2,l3))
an = np.fft.fft2(A*window_s,axes=(0,1))
E = (an*an.conjugate()) / (df1*df2) / ((l1*l2)**2)
E = np.fft.fftshift(E)
E = E.mean(axis=2)
return np.real(E),f1,f2,df1,df2,f1Ny,f2Ny
示例14: new_resize_data_fft
def new_resize_data_fft(data,factor=3,window=14):
xwidth, ywidth = data.shape
max_size = max(data.shape)
print window
#create hanning window and apply
#hx = kaiser(xwidth,window)
#hy = kaiser(ywidth,window)
hx = hanning(xwidth)
hy = hanning(ywidth)
ham2d = sqrt(outer(hx,hy))
if window is not None:
data = data*ham2d
#just create an array odd number as big
#to avoid overuns etc - It needs to be padded anyhow
max_size = max_size*factor
if not max_size % 2:
print "Not correct"
return -1
new_array = zeros([max_size, max_size], dtype="complex")
x_start = (max_size - 1)/2 - (xwidth-1)/2
x_end = x_start + xwidth
y_start = (max_size - 1)/2 - (xwidth-1)/2
y_end = y_start + ywidth
print x_start,x_end,y_start,y_end
new_array[x_start:x_end,y_start:y_end] = data
return new_array,ham2d
示例15: __init__
def __init__(self):
""" """
# self.in_filename = 'WURB-1_20160612T230008+0200_N57.6629E12.6390_FS-384_Enil_UTAN_KON_TESTFIL-INDATA-FDX.wav'
self.in_filename = 'TEST_FS384.wav'
self.out_filename = 'TEST_FDX.wav'
self.sample_rate_in = 384000
self.sample_rate_out = 38400 ###### 44100
self.channels = 1
self.sample_width = 2 # 16 bits.
# self.buffer_size_in = 1024 * 16
self.buffer_size_in = 1024 * 4
# self.buffer_size_in = 1024 * 2
# self.buffer_size_out = 1878
# self.buffer_size_out = 648
# self.buffer_size_out = 204
self.buffer_size_out = 408
# self.buffer_size_out = 202
self.divide_factor = 10
self.overlap_in = self.buffer_size_in / 2
self.overlap_out = self.buffer_size_out / 2
# Create Hann window
# self.window_in=0.5-np.cos(np.arange(self.buffer_size_in,dtype='float')*2.0*np.pi/(self.buffer_size_in-1))*0.5
# self.window_out=0.5-np.cos(np.arange(self.buffer_size_out,dtype='float')*2.0*np.pi/(self.buffer_size_out-1))*0.5
self.window_in=np.hanning(self.buffer_size_in)
self.window_out=np.hanning(self.buffer_size_out)
#
self.extra_freq_bins = None
# Perform translation.
self.from_fs384_to_fdx()