本文整理汇总了Python中scipy.signal.hamming函数的典型用法代码示例。如果您正苦于以下问题:Python hamming函数的具体用法?Python hamming怎么用?Python hamming使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hamming函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: window
def window(f,start,stop,type='blackman'):
"""
runs the data through a hamming window.
@param f: The data matrix
@param start: The start index of the hamming window.
@param stop: The end index of the hamming window.
"""
h=numpy.zeros(f.shape,dtype=float)
if len(h.shape)==1:
if type=='hamming':
h[start:stop]=signal.hamming(stop-start)
elif type=='blackman':
h[start:stop]=signal.blackman(stop-start)
elif type=='hann':
h[start:stop]=signal.hann(stop-start)
elif type=='blackmanharris':
h[start:stop]=signal.blackmanharris(stop-start)
elif type=='rectangular' or type=='rect' or type=='boxcar':
h[start:stop]=signal.boxcar(stop-start)
else:
if type=='hamming':
h[:,start:stop]=signal.hamming(stop-start)
elif type=='blackman':
h[:,start:stop]=signal.blackman(stop-start)
elif type=='hann':
h[:,start:stop]=signal.hann(stop-start)
elif type=='blackmanharris':
h[:,start:stop]=signal.blackmanharris(stop-start)
elif type=='rectangular' or type=='rect' or type=='boxcar':
h[:,start:stop]=signal.boxcar(stop-start)
return numpy.multiply(f,h)
开发者ID:heltPython,项目名称:medicalRadar,代码行数:32,代码来源:processing.py
示例2: test_basic
def test_basic(self):
assert_allclose(signal.hamming(6, False),
[0.08, 0.31, 0.77, 1.0, 0.77, 0.31])
assert_allclose(signal.hamming(6),
[0.08, 0.3978521825875242, 0.9121478174124757,
0.9121478174124757, 0.3978521825875242, 0.08])
assert_allclose(signal.hamming(7, sym=True),
[0.08, 0.31, 0.77, 1.0, 0.77, 0.31, 0.08])
开发者ID:chris-b1,项目名称:scipy,代码行数:8,代码来源:test_windows.py
示例3: __init__
def __init__(self,freq,N_samples):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.createQtConnections()
self.sample_rate = 2.4e5 ###1e6
#self.decim_r1 = 1e6/2e5 # for wideband fm
self.decim_r2 = 2.4e5/48000 # for baseband recovery
self.center_freq = freq #+250e3
self.gain = 38
self.N_samples = N_samples
self.is_sampling = False
self.spectrogram = np.zeros((328,200))
self.chspectrogram = np.zeros((328,200))
self.plspectrogram = np.zeros((164,200))
self.sdr = RtlSdr()
#self.sdr.direct_sampling = 1
self.sdr.sample_rate = self.sample_rate
self.sdr.center_freq = self.center_freq
self.sdr.gain = self.gain
self.pa = pyaudio.PyAudio()
self.stream = self.pa.open( format = pyaudio.paFloat32,
channels = 2,
rate = 48000,
output = True)
adj = 0
hamming = np.kaiser(self.N_samples/4 + adj,1)
lpf = np.append( np.zeros(self.N_samples*3/8),hamming)
self.lpf = np.fft.fftshift(np.append(lpf,np.zeros(self.N_samples*3/8))) #,int(-.25*self.N_samples))
hamming = 10*signal.hamming(self.N_samples/16)
lpf = np.append(np.zeros(self.N_samples*15/32),hamming)
self.lpf_s1 = (np.append(lpf,np.zeros(int(self.N_samples*15/32))))
#self.lpf_s1 = np.roll(temp,int(.5*self.N_samples*67/120))
#self.lpf_s1 += np.roll(temp,int(-.5*self.N_samples*67/120))
self.lpf_s1 = np.fft.fftshift(self.lpf_s1)
#self.lpf_s1 += np.fft.fftshift(self.lpf_s1)
# fig = plt.figure()
# ax = fig.add_subplot(111)
# ax.plot(range(self.lpf_s1.size),self.lpf_s1)
# fig.show()
hamming = 10*signal.hamming(self.N_samples/32)
lpf = np.append(np.zeros(self.N_samples*31/64),hamming)
self.lpf_s2 = (np.append(lpf,np.zeros(int(self.N_samples*31/64))))
#self.lpf_s2 = np.roll(temp,int(.5*self.N_samples*92/120))
#self.lpf_s2 += np.roll(temp,int(-.5*self.N_samples*92/120))
self.lpf_s2 = np.fft.fftshift(self.lpf_s2)
开发者ID:peragwin,项目名称:fmradio-qt,代码行数:58,代码来源:radio-multithread.py
示例4: read_data_thread
def read_data_thread(rf_q,ad_rdy_ev,audio_q):
print("read data thread start")
pre_data=0
#filter design
#FIR_LP = signal.firwin(19,17e3,1e3,window='hamming',True,False,RFRATE/2)
#FIR_LP = signal.firwin(19,400e3/(RFRATE/2))
#FIR_LP = signal.firwin(9,10e3/(AUDIORATE/2))
rfwindow = signal.hamming(RFSIZE)
audiowindow = signal.hamming(AUDIOSIZE)
fftwindow = signal.hamming(512)
ad_rdy_ev.wait(timeout=5000)
np.save("data",rf_q.get())
while 0:
ad_rdy_ev.wait(timeout=1000)
while not rf_q.empty():
#process data here
data=rf_q.get()
#data=signal.decimate(data,DOWN_FACTOR,ftype="fir")
#data = signal.lfilter(FIR_LP,1.0,data)
#demod method 1
angle_data=np.angle(data)
audioda=np.diff(angle_data)
audiodata=np.insert(audioda,0,angle_data[0]-pre_data)
pre_data=angle_data[-1]
audiodata=np.unwrap(audiodata,np.pi)
#demod method 2
#data_delay=np.insert(data,0,pre_data)
#pre_data = data_delay[-1]
#data_delay=np.delete(data_delay,-1)
#diff_data=data*np.conj(data_delay)
#audiodata=np.angle(diff_data)
#audiodata=np.unwrap(audiodata)
#demod method 3
#diff_data=np.diff(data)
#diff_data=np.insert(diff_data,0,data[0]-pre_data)
#pre_data=data[-1]
#audiodata=data.real*diff_data.imag-data.imag*diff_data.real
#audiodata=audiodata/(np.power(data.real,2)+np.power(data.imag,2))
#audiodata=audiodata*10
audiodata=signal.decimate(audiodata,DOWN_FACTOR,ftype="fir")
#audiodata = signal.lfilter(FIR_LP,1.0,audiodata)
audiodata_amp=audiodata*1e4
snd_data = audiodata_amp.astype(np.dtype('<i2')).tostring()
audio_q.put(snd_data)
ad_rdy_ev.clear()
print("read data thread ended")
开发者ID:licheegh,项目名称:dig_sig_py_study,代码行数:56,代码来源:fm_radio_sample_data.py
示例5: test_basic
def test_basic(self):
assert_allclose(signal.hamming(6, False),
[0.08, 0.31, 0.77, 1.0, 0.77, 0.31])
assert_allclose(signal.hamming(7, sym=False),
[0.08, 0.2531946911449826, 0.6423596296199047,
0.9544456792351128, 0.9544456792351128,
0.6423596296199047, 0.2531946911449826])
assert_allclose(signal.hamming(6),
[0.08, 0.3978521825875242, 0.9121478174124757,
0.9121478174124757, 0.3978521825875242, 0.08])
assert_allclose(signal.hamming(7, sym=True),
[0.08, 0.31, 0.77, 1.0, 0.77, 0.31, 0.08])
开发者ID:arichar6,项目名称:scipy,代码行数:12,代码来源:test_windows.py
示例6: __init__
def __init__(self,freq,N_samples):
self.sample_rate = 1e6
self.decim_r1 = 1e6/2e5 # for wideband fm
self.decim_r2 = 2e5/44100 # for baseband recovery
self.center_freq = freq+250e3
self.gain = 36
self.N_samples = N_samples
self.sdr = RtlSdr()
self.sdr.direct_sampling = 1
self.sdr.sample_rate = self.sample_rate
self.sdr.center_freq = self.center_freq
self.sdr.gain = 'auto' #self.gain
self.pa = pyaudio.PyAudio()
self.stream = self.pa.open( format = pyaudio.paFloat32,
channels = 2,
rate = 44100,
output = True)
adj = 0
hamming = 10*signal.hamming(self.N_samples*.10 + adj)
lpf = np.append( np.zeros(self.N_samples*.45),hamming)
self.lpf = np.roll(np.fft.fftshift(np.append(lpf,np.zeros(self.N_samples*.45))),int(-.25*self.N_samples))
开发者ID:peragwin,项目名称:fmradio-qt,代码行数:26,代码来源:radio-slim.py
示例7: fourier_transform_and_reconstruct
def fourier_transform_and_reconstruct(image, detrend=False, window=False,
ffunc=None):
"""
Take fourier transform, alter it, and reconstruct image. For some
reason this is shifting the origin by 1 pixel after reconstruction, which
should not happen.
:param image: data
:type image: :py:class:`numpy.ndarray`
:param ffunc: function that alters FFT matrix
:type ffunc: func
:return: modified image data
:rtype: :py:class:`numpy.ndarray`
"""
if window:
w = signal.hamming(image.shape)
else:
w = np.ones_like(image)
if detrend:
f = fftpack.fft(w * signal.detrend(image))
else:
f = fftpack.fft(w * image)
# alter the fft
if not ffunc is None:
f = ffunc(f)
result = np.fliplr(fftpack.fft(f))
return result > result.mean()
开发者ID:JoshuaSBrown,项目名称:langmuir,代码行数:33,代码来源:modify.py
示例8: hamming
def hamming(self, cutoff):
"""Filter the data using a hamming filter and store the values in filteredseries"""
for i in range(len(self.recarray[0])):
fil = signal.hamming(cutoff)
output = signal.convolve(self.recarray[:,i], fil, mode='same')
self.filteredseries[:,i] = output
return self.filteredseries
开发者ID:MarkTransell,项目名称:masterscode,代码行数:7,代码来源:masterlibrary.py
示例9: unsharp_masking
def unsharp_masking(X):
lp = np.array(X)
for i, ws in zip([0, 1, 2], [50, 50, 25]):
h = hamming(ws)
h /= h.sum()
convolve1d(lp, h, axis=i, output=lp)
return X - lp
开发者ID:cajal,项目名称:cell_detector,代码行数:7,代码来源:utils.py
示例10: filter_csd
def filter_csd(self):
'''Spatial filtering of the CSD estimate, using an N-point filter'''
if not self.f_order > 0 and type(self.f_order) == type(3):
raise Exception, 'Filter order must be int > 0!'
if self.f_type == 'boxcar':
num = ss.boxcar(self.f_order)
denom = pl.array([num.sum()])
elif self.f_type == 'hamming':
num = ss.hamming(self.f_order)
denom = pl.array([num.sum()])
elif self.f_type == 'triangular':
num = ss.triang(self.f_order)
denom = pl.array([num.sum()])
elif self.f_type == 'gaussian':
num = ss.gaussian(self.f_order[0], self.f_order[1])
denom = pl.array([num.sum()])
else:
raise Exception, '%s Wrong filter type!' % self.f_type
num_string = '[ '
for i in num:
num_string = num_string + '%.3f ' % i
num_string = num_string + ']'
denom_string = '[ '
for i in denom:
denom_string = denom_string + '%.3f ' % i
denom_string = denom_string + ']'
print 'discrete filter coefficients: \nb = %s, \na = %s' % \
(num_string, denom_string)
self.csd_filtered = pl.empty(self.csd.shape)
for i in xrange(self.csd.shape[1]):
self.csd_filtered[:, i] = ss.filtfilt(num, denom, self.csd[:, i])
开发者ID:Junji110,项目名称:iCSD,代码行数:34,代码来源:icsd.py
示例11: data_w_hamm
def data_w_hamm(dt,frame=256):
temp = []
_t = sig.hamming(frame)
fx = frame*0.5
#temp = [sum(np.array(dt[x*fx:x*fx+frame]*_t)**2) for x in range(int(len(dt)/fx -1))]
temp = [np.log(sum(np.abs(dt[x*fx:x*fx+frame]*_t))) for x in range(int(len(dt)/fx -1))]
return temp
开发者ID:twkun,项目名称:MEFE_Python,代码行数:7,代码来源:tools.py
示例12: __init__
def __init__(self, clip, window=1024, step=None, n=None):
"""Compute the short-time Fourier transform on a 1-dimensional array
*signal*, with the specified *window* size, *step* size, and
*n*-resolution FFT.
This function returns a 2-dimensional array of complex floats. The
0th dimension is time (window steps) and the 1th dimension is
frequency.
"""
if clip is None:
return
if step is None:
step = window / 2
if n is None:
n = window
signal = clip.signal
self.params = (window, step, n, clip.nyq)
if signal.ndim != 1:
raise ValueError("signal must be a 1-dimensional array")
length = signal.size
num_windows = _num_windows(length, window, step)
out = np.zeros((num_windows, n), dtype=np.complex64)
taper = hamming(window)
for (i, s) in enumerate(window_slice_iterator(length, window, step)):
out[i, :] = np.fft.fft(signal[s] * taper, n)
self.data = out
开发者ID:chairmanK,项目名称:eulerian-audio-magnification,代码行数:29,代码来源:clip.py
示例13: setUp
def setUp(self):
path = join(dirname(__file__), "data")
# setting up sliding window data
data_z = np.loadtxt(join(path, "MBGA_Z.ASC"))
data_e = np.loadtxt(join(path, "MBGA_E.ASC"))
data_n = np.loadtxt(join(path, "MBGA_N.ASC"))
n = 256
fs = 75
inc = int(0.05 * fs)
self.data_win_z, self.nwin, self.no_win = util.enframe(data_z, signal.hamming(n), inc)
self.data_win_e, self.nwin, self.no_win = util.enframe(data_e, signal.hamming(n), inc)
self.data_win_n, self.nwin, self.no_win = util.enframe(data_n, signal.hamming(n), inc)
# global test input
self.fk = [2, 1, 0, -1, -2]
self.norm = pow(np.max(data_z), 2)
self.res = np.loadtxt(join(path, "3cssan.hy.1.MBGA_Z"))
开发者ID:jmfee-usgs,项目名称:obspy,代码行数:16,代码来源:test_polarization.py
示例14: __window_data
def __window_data(data):
# Apply window function to the decoded data & store as new key:value pair in dictionary
# Parameters: data: [{'frame_data': string,
# 'frame_count': int,
# 'frame_time': float,
# 'frame_position': int,
# 'frame_decoded': numpy.ndarray}, ...]
# cache window function
if 'hann' == config_analysis.frame_window:
window = signal.hann(config_audio.frames_per_buffer)
elif 'hamming' == config_analysis.frame_window:
window = signal.hamming(config_audio.frames_per_buffer)
elif 'blackman' == config_analysis.frame_window:
window = signal.blackman(config_audio.frames_per_buffer)
elif 'bartlett' == config_analysis.frame_window:
window = signal.bartlett(config_audio.frames_per_buffer)
elif 'barthann' == config_analysis.frame_window:
window = signal.barthann(config_audio.frames_per_buffer)
else:
# window function unavailable
return
# apply specified window function in config
for i in range(len(data)):
data[i]['frame_windowed'] = data[i]['frame_decoded'][:] * window
开发者ID:MaxLikelihood,项目名称:PyDSP,代码行数:26,代码来源:analysis.py
示例15: mfcc
def mfcc(samples, winlen, winshift, nfft, nceps, samplingrate):
"""Computes Mel Frequency Cepstrum Coefficients.
Args:
samples: array of speech samples with shape (N,)
winlen: lenght of the analysis window
winshift: number of samples to shift the analysis window at every time step
nfft: length of the Fast Fourier Transform (power of 2, grater than winlen)
nceps: number of cepstrum coefficients to compute
samplingrate: sampling rate of the original signal
Note: for convenienve, you can define defaults for the input arguments that fit the exercise
Returns:
ceps: N x nceps array with one MFCC feature vector per row
mspec: N x M array of outputs of the Mel filterbank (of size M)
spec: N x nfft array with squared absolute fast Fourier transform
"""
enframes = enframe(samples, winlen, winshift)
# preemp_signal = map(lambda x: preemp(x, 0.97), enframes)
preemp_signal = preemp(enframes, p=0.97)
hamWindow = hamming(winlen, False)
ham_signal = helper.combineHam(preemp_signal, hamWindow)
if not nfft:
nfft = 512
spec, logspec_fft = fft(ham_signal, nfft);
bank1 = tools.trfbank(samplingrate, nfft);
mspec = helper.melSpec(spec, bank1)
spec_dct = helper.cosineTransform(mspec)
ceps = spec_dct[:, :nceps]
return (spec, mspec, ceps)
开发者ID:adhaka,项目名称:kthasrdnn,代码行数:33,代码来源:prepare_mfcc.py
示例16: mteo
def mteo (x, k_values):
"""
Multi resolution Teagre Energy Operator
Parameters
----------
x : ndarray
The raw signal
k_values : ndarray
The values of k to use for estimating MTEO
Returns
-------
tem : ndarray
The operated signal
"""
from scipy.signal import hamming
from scipy.signal import lfilter
teo_k_wise = np.zeros((len(k_values), len(x)))
for i in range(len(k_values)):
teo_k_wise[i, :] = teo(x, k_values[i])
variance = np.var(teo_k_wise[i, :])
window = hamming(4*k_values[i] + 1)
teo_k_wise[i, :] = lfilter(window, 1, teo_k_wise[i, :]) / variance
tem = np.max(teo_k_wise, axis=0)
return tem
开发者ID:anupam-mitra,项目名称:PySpikeSort,代码行数:29,代码来源:diff.py
示例17: mfcc
def mfcc(self, x, Fs, win, hop, nfft, CC):
'''Mel-Frequency cepstral coefficients of a signal
x := signal
Fs := sampling rate
win := window size
hop := hop size
nfft := fft size
CC := number of coefficients'''
#filterbank parameters
lowestFrequency = 133.3333
linearFilters = 13
linearSpacing = 200./3
logFilters = 27
logSpacing = 1.0711703
totalFilters = linearFilters + logFilters
w = sig.hamming(win)
seg = np.zeros((np.ceil(len(x)/float(hop)), win))
i = 0
pin = 0
pend = len(x) - win
while pin < pend:
seg[i, 0:win] = x[pin:pin+win] * w
i += 1
pin += hop
preEmp = sig.lfilter(np.array([1, -.97]), 1, seg)
fbank = self.trfbank(Fs, nfft, lowestFrequency, linearSpacing, logSpacing, linearFilters, logFilters)[0]
fftMag = np.abs(fftpack.fft(preEmp, nfft, axis=-1))
earMag = np.log10(np.inner(fftMag, fbank) + 0.0000000001)
ceps = fftpack.realtransforms.dct(earMag, type=2, norm='ortho', axis=-1)[:, 0:CC]
return ceps, earMag
开发者ID:gboyes,项目名称:pydbm,代码行数:35,代码来源:utils.py
示例18: enframe
def enframe(self, datas, fs, frame_len, frame_inc, win):
'''
' datas: 语音数据
' fs: 采样频率
' frame_len: 帧长,单位秒
' frame_inc: 帧移,单位秒
' win: 窗函数
'''
datas_len = len(datas) # 数据总长度
frame_len = int(round(frame_len * fs)) # 帧长,数据个数
nstep = frame_len - int(round(frame_inc * fs)) # 帧移动步长,数据个数
if datas_len < frame_len: # 若信号长度小于帧长,则帧数定义为1
nf = 1
else:
nf = int(np.ceil((1.0*datas_len-frame_len)/nstep)) + 1
pad_len = int((nf-1)*nstep + frame_len) # 所有帧总数据长度
# 多余的数据使用0填充
new_datas = np.concatenate((datas, np.zeros(pad_len - datas_len)))
indices = np.tile(np.arange(0,frame_len),(nf,1))+np.tile(np.arange(0,nf*nstep,nstep),(frame_len,1)).T
indices = np.array(indices, dtype = np.int32) # 否则会报类型错误
frames = new_datas[indices] #得到帧信号
# 加窗
if win == 'hamming':
win = signal.hamming(frame_len)
elif win == 'hanning':
win = signal.hanning(frame_len)
else:
win = signal.boxcar(frame_len)
return frames * np.tile(win, (nf, 1))
开发者ID:Bfat-boy,项目名称:jobcode,代码行数:35,代码来源:SilenceDetector_with_plot.py
示例19: plot_specgram
def plot_specgram(ax, data, fs, nfft=256, noverlap=128, window='hann',
cmap='jet', interpolation='bilinear', rasterized=True):
if window not in SPECGRAM_WINDOWS:
raise ValueError("Window not supported")
elif window == "boxcar":
mwindow = signal.boxcar(nfft)
elif window == "hamming":
mwindow = signal.hamming(nfft)
elif window == "hann":
mwindow = signal.hann(nfft)
elif window == "bartlett":
mwindow = signal.bartlett(nfft)
elif window == "blackman":
mwindow = signal.blackman(nfft)
elif window == "blackmanharris":
mwindow = signal.blackmanharris(nfft)
specgram, freqs, time = mlab.specgram(data, NFFT=nfft, Fs=fs,
window=mwindow,
noverlap=noverlap)
specgram = 10 * np.log10(specgram[1:, :])
specgram = np.flipud(specgram)
freqs = freqs[1:]
halfbin_time = (time[1] - time[0]) / 2.0
halfbin_freq = (freqs[1] - freqs[0]) / 2.0
extent = (time[0] - halfbin_time, time[-1] + halfbin_time,
freqs[0] - halfbin_freq, freqs[-1] + halfbin_freq)
ax.imshow(specgram, cmap=cmap, interpolation=interpolation,
extent=extent, rasterized=rasterized)
ax.axis('tight')
开发者ID:zhangwise,项目名称:apasvo,代码行数:34,代码来源:plotting.py
示例20: dip
def dip(peak, smooth=True):
""" Run a dip test.
The diptest can be used to test if a distribution is unimodal. In order to
get it to work, I have to turn the peak signal into a distribution by
simulating, and then run the test on the simulated data. This is a little
hackish, there is probably a better/faster way.
"""
# Smooth distribution using hamming
if smooth:
smooth = signal.convolve(peak, signal.hamming(10))
else:
smooth = peak
# Set up x's
x_grid = np.arange(0, smooth.shape[0])
# Normalize the peak section to sum to 1
norm = smooth / smooth.sum()
# Simulate data from the peak distribution
sim = choice(x_grid, size=3000, replace=True, p=norm)
# Run diptest
test, pval = diptest(sim)
return test, pval
开发者ID:jfear,项目名称:tapeAnalyst,代码行数:29,代码来源:analysis.py
注:本文中的scipy.signal.hamming函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论