本文整理汇总了Python中scipy.hamming函数的典型用法代码示例。如果您正苦于以下问题:Python hamming函数的具体用法?Python hamming怎么用?Python hamming使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hamming函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stft
def stft(x, fs, framesz, hop):
framesamp = int(framesz*fs)
hopsamp = int(hop*fs)
w = scipy.hamming(framesamp)
X = scipy.array([scipy.fft(w*x[i:i+framesamp])
for i in range(0, len(x)-framesamp, hopsamp)])
return X
示例2: stft
def stft(x, fs, frame_time, hop_time):
frame_samples = int(frame_time*fs)
hop_samples = int(hop_time*fs)
w = scipy.hamming(frame_samples)
X = scipy.array([ scipy.fft(w*x[i:i+frame_samples])
for i in range(0, len(x)-frame_samples, hop_samples)])
return X
示例3: apply_tf_spec
def apply_tf_spec(data,fftLen, step,tf_config,src_index,noise_amp=0):
win = hamming(fftLen) # ハミング窓
### STFT
spectrogram = simmch.stft(data, win, step)
spec=spectrogram[:, : fftLen / 2 + 1]
#spec = [4,3,2,1,2*,3*]
### Apply TF
tf=tf_config["tf"][src_index]
#print "# position:",tf["position"]
pos=tf["position"]
th=math.atan2(pos[1],pos[0])# -pi ~ pi
#print "# theta(deg):",th/math.pi*180
out_data=[]
for mic_index in xrange(tf["mat"].shape[0]):
tf_mono=tf["mat"][mic_index]
#print "# src spectrogram:",spec.shape
#print "# tf spectrogram:",tf_mono.shape
tf_spec=spec*tf_mono
spec_c=np.conjugate(tf_spec[:,:0:-1])
out_spec=np.c_[tf_spec,spec_c[:,1:]]
noise_spec=np.zeros_like(out_spec)
v_make_noise = np.vectorize(make_noise)
noise_spec=v_make_noise(noise_spec)
out_spec=out_spec+noise_amp*noise_spec
out_data.append(out_spec)
mch_data=np.array(out_data)
return mch_data
示例4: fft
def fft(self, window="hanning", nfft=None):
from numpy.fft.fftpack import fft as npfft
from numpy.fft import fftfreq as npfftfreq
from scipy import hamming, hanning
sig = self.get_data()
n = sig.shape[0]
if window == "hamming":
win = hamming(n)
elif window == "hanning":
win = hanning(n)
elif window == "square":
win = 1
else:
raise StandardError("Windows is not %s" % (window,))
#: FFT, 折り返しこみ
if nfft is None:
nfft = n
spec = npfft(sig * win, n=nfft)
#: Freq, 折り返しこみ
freq = npfftfreq(nfft, d=1. / self.get_fs())
# : 折り返しを削除して返却
se = round(nfft / 2)
spectrum = SpectrumData(data=spec[:se], xdata=freq[:se], name=self.name)
spectrum.set_fs(self.get_fs())
return spectrum
示例5: stft
def stft(x, fs, framesz, hop):
"short-term frequency transform"
framesamp = int(framesz*fs)
hopsamp = int(hop*fs)
w = scipy.hamming(framesamp)
X = scipy.array([scipy.fft(w*x[i:i+framesamp]) for i in range(0, len(x)-framesamp, hopsamp)])
#freqs = fftfreq(framesamp, hop)
return X#,freqs
示例6: add
def add(self, x, fs, label):
x = self.preprocess(x, fs)
X = scipy.array([self.feature(x[i:i+self.fftsz])
for i in range(0, x.size-self.fftsz, self.hop)])
h = scipy.hamming(7)[:,None]
X = scipy.signal.convolve(X, h, mode='valid')
for i in range(len(X)-self.segsz):
self.db.add(X[i:i+self.segsz].reshape(-1), (label, i))
示例7: __init__
def __init__(self):
self.wavefile = None
self.wavedata = None
self.hamming_win = sp.hamming(self.STFT_SIZE)
self.freq_probe_index_list = self.__fftprobe(self.STFT_SIZE,
self.FREQ_PROBE_NUM,
self.LOWER_HERTZ,
self.UPPER_HERTZ)
示例8: get_angle
def get_angle(rci, nfft=128):
"""
Provides the Range-Angle image
"""
win = hamming(rci.shape[0])
win.shape = (len(win),1)
win = win.repeat(rci.shape[1],axis=1)
return fftpack.fft(win*rci,nfft,axis=0)
示例9: stft
def stft(x, fs, framesz, hop):
"""
Short-time fourier transform an input
"""
framesamp = int(framesz*fs)
hopsamp = int(hop*fs)
w = scipy.hamming(framesamp)
X = scipy.array([scipy.fft(w*x[i:i+framesamp]) for i in range(0, len(x)-framesamp, hopsamp)])
return X
示例10: toiq
def toiq(frame,nfft=2048):
"""
Converts ADC output to range in-phase (I) and quadrature (Q) data, i.e., complex range profile
"""
win = hamming(frame.shape[1])
win.shape = (1,len(win))
win = win.repeat(frame.shape[0],axis=0)
data = fftpack.ifft(win*frame,nfft,axis=1)
return data[:,0:nfft/2]
示例11: run
def run(self, spikesorter,
k_max=1,
k_inc=1,
from_fullband=False,
median_thresh=5.,
consistent_across_channels = False,
consistent_across_segments = True,
merge_method = 'fast',
sweep_clean_size = 0.8*pq.ms,
):
sps = spikesorter
# What is the source signal?
if (from_fullband or (sps.filtered_sigs is None)):
MTEO_sigs = np.empty( sps.full_band_sigs.shape, dtype = object)
sigs=sps.full_band_sigs
else:
MTEO_sigs = np.empty( sps.filtered_sigs.shape, dtype = object)
sigs=sps.filtered_sigs
# Compute MTEO signals
for c,s in np.ndindex(sigs.shape) :
sig = sigs[c, s]
kTEO_sig=np.zeros(sig.size)
#compute all k-TEO, including k_max if possible
for k in range(1,k_max+1,k_inc):
s1 = sig[0:-2*k]
s2 = sig[k:-k]
s3 = sig[2*k:]
# standard kTEO signal
kTEO_sig[k:-k]=ne.evaluate("s2**2-s1*s3")
hamm = hamming(4*(k+1)+1)#smoothing window
norm=np.sqrt(3*(hamm**2.)+(hamm.sum())**2.)
hamm = hamm/norm # normalization of the window
#proposed by Choi et al. to prevent excess of false detections at small k
kTEO_sig=np.convolve(kTEO_sig,hamm,'same')
if k==1:
MTEO_sig=kTEO_sig.copy()
else:
#take the max over all kTEO iteratively
MTEO_sig=ne.evaluate("where(MTEO_sig<kTEO_sig,kTEO_sig,MTEO_sig)")
MTEO_sigs[c,s]=MTEO_sig
# Threshold estimation
thresholds = np.zeros(MTEO_sigs.shape, dtype = float)
for c, s in np.ndindex(MTEO_sigs.shape):
sig = MTEO_sigs[c, s]
thresholds[c, s] = abs(median_thresh) * np.median(abs(sig)) / .6745
# Detect
sweep_size = int((sps.sig_sampling_rate*sweep_clean_size).simplified)
sps.spike_index_array = threshold_detection_multi_channel_multi_segment(
MTEO_sigs, thresholds, '+',
consistent_across_channels,consistent_across_segments,
sweep_size, merge_method = merge_method,)
示例12: stft
def stft(x, fs, framesz, hop):
"""
stft(samples, sample_rate, width, stride)
width and stride are in seconds.
returns iterator of fft-coefficient arrays.
"""
framesamp = int(framesz*fs)
hopsamp = int(hop*fs)
w = scipy.hamming(framesamp)
return [numpy.absolute(numpy.fft.rfft(w*x[i:i+framesamp])) for i in xrange(0, len(x)-framesamp, hopsamp)]
示例13: cq_fft
def cq_fft(sig, fs, q_rate = q_rate_def, fmin = fmin_default, fmax = fmax_default,
fratio = fratio_default, win = hamming, spThresh = 0.0054):
# 100 frames per 1 second
nhop = int(round(0.01 * fs))
# Calculate Constant-Q Properties
nfreq = get_num_freq(fmin, fmax, fratio) # number of freq bins
freqs = get_freqs(fmin, nfreq, fratio) # freqs [Hz]
Q = int((1. / ((2 ** fratio) - 1)) * q_rate) # Q value
# Preparation
L = len(sig)
nframe = L / nhop # number of time frames
# N > max(N_k)
fftLen = int(2 ** (ceil(log2(int(float(fs * Q) / freqs[0])))))
h_fftLen = fftLen / 2
# ===================
# カーネル行列の計算
# ===================
sparseKernel = zeros([nfreq, fftLen], dtype = complex128)
for k in xrange(nfreq):
tmpKernel = zeros(fftLen, dtype = complex128)
freq = freqs[k]
# N_k
N_k = int(float(fs * Q) / freq)
# FFT窓の中心を解析部分に合わせる.
startWin = (fftLen - N_k) / 2
tmpKernel[startWin : startWin + N_k] = (hamming(N_k) / N_k) * exp(two_pi_j * Q * arange(N_k, dtype = float64) / N_k)
# FFT (kernel matrix)
sparseKernel[k] = fft(tmpKernel)
### 十分小さい値を0にする
sparseKernel[abs(sparseKernel) <= spThresh] = 0
### スパース行列に変換する
sparseKernel = csr_matrix(sparseKernel)
### 複素共役にする
sparseKernel = sparseKernel.conjugate() / fftLen
### New signal (for Calculation)
new_sig = zeros(len(sig) + fftLen, dtype = float64)
new_sig[h_fftLen : -h_fftLen] = sig
ret = zeros([nframe, nfreq], dtype = complex128)
for iiter in xrange(nframe):
#print iiter + 1, "/", nframe
istart = iiter * nhop
iend = istart + fftLen
# FFT (input signal)
sig_fft = fft(new_sig[istart : iend])
# 行列積
ret[iiter] = sig_fft * sparseKernel.T
return ret, freqs
示例14: stft
def stft(fs, data, frame_size=0.05, hop=0.025):
frame_samp = int(frame_size * fs)
hop_samp = int(hop * fs)
w = scipy.hamming(frame_samp)
ans = scipy.array([np.fft.rfft(w * data[i:i + frame_samp])
for i in range(0, len(data) - frame_samp, hop_samp)])
ans = scipy.log10(scipy.absolute(ans.T))
labels = {'xlabel': 'Czas [s]', 'ylabel': u'Częstotliwość [Hz]', 'zlabel': 'Amplituda'}
return {'y_vector': ans, 'x_vector': None, 'labels': labels, 'yticks': get_freqs_ticks(fs, len(data), len(ans)),
'xticks': get_time_ticks(fs, len(data), len(ans.T))}
示例15: stft
def stft(self, x, fs, framesz, hop):
# framesamp = int(framesz * fs)
# hopsamp = int(hop * fs)
framesamp = framesz
hopsamp = hop
w = scipy.hamming(framesamp)
X = scipy.array([scipy.fft(w * x[i:i + framesamp])for i in range(0, len(x) - framesamp, hopsamp)])
print X.shape
X = X[:, :int(framesz / 2)]
print "== fin stft =="
return X