• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python scipy.hamming函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.hamming函数的典型用法代码示例。如果您正苦于以下问题:Python hamming函数的具体用法?Python hamming怎么用?Python hamming使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了hamming函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:RichardYang40148,项目名称:SourceSeparation,代码行数:7,代码来源:stft.py


示例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
开发者ID:nashj,项目名称:Automatic-Music-Transcription,代码行数:7,代码来源:main.py


示例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
开发者ID:naegawa,项目名称:SimMch,代码行数:27,代码来源:sim_tf.py


示例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
开发者ID:peace098beat,项目名称:fisig2,代码行数:32,代码来源:signaldata.py


示例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
开发者ID:c-base,项目名称:apidictor,代码行数:8,代码来源:fft.py


示例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))
开发者ID:stevetjoa,项目名称:musicsearch,代码行数:8,代码来源:main.py


示例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)
开发者ID:extsui,项目名称:AeroMixer,代码行数:8,代码来源:STFTAudio.py


示例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)
开发者ID:jgbos,项目名称:phased-array-radar,代码行数:8,代码来源:plots.py


示例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
开发者ID:lesniak2,项目名称:signal-processing,代码行数:9,代码来源:FrequencyAnalyzer.py


示例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]	
开发者ID:jgbos,项目名称:phased-array-radar,代码行数:9,代码来源:phased_array.py


示例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,)
开发者ID:epiasini,项目名称:OpenElectrophy,代码行数:57,代码来源:mteo.py


示例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)]
开发者ID:gmaslov,项目名称:apnea,代码行数:10,代码来源:unc_sdl.py


示例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
开发者ID:computational-science-of-art,项目名称:suikin,代码行数:55,代码来源:constant_q_trans.py


示例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))}
开发者ID:pnikrat,项目名称:spyker_inzynierka,代码行数:11,代码来源:charts.py


示例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
开发者ID:peace098beat,项目名称:SignalProcessingApp,代码行数:11,代码来源:GraphBoxWidget.py


示例16: apply_tf

def apply_tf(data,fftLen, step,tf_config,src_index,noise_amp=0):
	win = hamming(fftLen) # ハミング窓
	mch_data=apply_tf_spec(data,fftLen, step,tf_config,src_index,noise_amp)
	out_wavdata=[]
	for mic_index in xrange(mch_data.shape[0]):
		spec=mch_data[mic_index]
		### iSTFT
		resyn_data = simmch.istft(spec, win, step)
		out_wavdata.append(resyn_data)
	# concat waves
	mch_wavdata=np.vstack(out_wavdata)
	return mch_wavdata
开发者ID:naegawa,项目名称:SimMch,代码行数:12,代码来源:sim_tf.py


示例17: tdft

def tdft(audio, srate, windowsize, windowshift,fftsize):

    """Calculate the real valued fast Fourier transform of a segment of audio multiplied by a 
    a Hamming window.  Then, convert to decibels by multiplying by 20*log10.  Repeat for all
    segments of the audio."""
    
    windowsamp = int(windowsize*srate)
    shift = int(windowshift*srate)
    window = scipy.hamming(windowsamp)
    spectrogram = scipy.array([20*scipy.log10(abs(np.fft.rfft(window*audio[i:i+windowsamp],fftsize))) 
                     for i in range(0, len(audio)-windowsamp, shift)])
    return spectrogram
开发者ID:TheTradingWarrior,项目名称:Shazam,代码行数:12,代码来源:tdft.py


示例18: stft

def stft(x, fs, framesz, hop):
    """
     x - signal
     fs - sample rate
     framesz - frame size
     hop - hop size (frame size = overlap + hop size)
    """
    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
开发者ID:ktho22,项目名称:speech_synthesis,代码行数:12,代码来源:Learnweight.py


示例19: compute_music_power

def compute_music_power(wav_filename,tf_config,
		normalize_factor,
		fftLen,stft_step,
		min_freq,max_freq,src_num,
		music_win_size,music_step):
	setting={}
	# read wav
	print "... reading", wav_filename
	wav_data=simmch.read_mch_wave(wav_filename)
	wav=wav_data["wav"]/normalize_factor
	fs=wav_data["framerate"]
	# print info
	print "# #channels : ", wav_data["nchannels"]
	setting["nchannels"]=wav_data["nchannels"]
	print "# sample size : ", wav.shape[1]
	setting["nsamples"]=wav.shape[1]
	print "# sampling rate : ", fs,"Hz"
	setting["framerate"]=fs
	print "# duration : ", wav_data["duration"],"sec"
	setting["duration"]=wav_data["duration"]

	# reading data
	df=fs*1.0/fftLen
	# cutoff bin
	min_freq_bin=int(np.ceil(min_freq/df))
	max_freq_bin=int(np.floor(max_freq/df))
	print "# min freq. :",min_freq_bin*df , "Hz"
	setting["min_freq"]=min_freq_bin*df
	print "# max freq. :",max_freq_bin*df , "Hz"
	setting["max_freq"]=max_freq_bin*df
	print "# freq. step:",df, "Hz"
	setting["freq_step"]=df
	print "# min freq. bin index:",min_freq_bin
	print "# max freq. bin index:",max_freq_bin

	# apply STFT
	win = hamming(fftLen) # ハミング窓
	spec=simmch.stft_mch(wav,win,stft_step)
	spec_m=spec[:,:,min_freq_bin:max_freq_bin]
	# apply MUSIC method
	## power[frame, freq, direction_id]
	print "# src_num:",src_num
	setting["src_num"]=src_num
	setting["step_ms"]=1000.0/fs*stft_step
	setting["music_step_ms"]=1000.0/fs*stft_step*music_step
	power=compute_music_spec(spec_m,src_num,tf_config,df,min_freq_bin,
			win_size=music_win_size,
			step=music_step)
	p=np.sum(np.real(power),axis=1)
	m_power=10*np.log10(p+1.0)
	m_full_power=10*np.log10(np.real(power)+1.0)
	return spec,m_power,m_full_power,setting
开发者ID:naegawa,项目名称:SimMch,代码行数:52,代码来源:music.py


示例20: stft

def stft(x, fs, framesz, hop):
    """x is the time-domain signal
    fs is the sampling frequency
    framesz is the frame size, in seconds
    hop is the the time between the start of consecutive frames, in seconds

    """
    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
开发者ID:sthenc,项目名称:pyKAM,代码行数:13,代码来源:stft.py



注:本文中的scipy.hamming函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python scipy.hanning函数代码示例发布时间:2022-05-27
下一篇:
Python scipy.genfromtxt函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap