当前位置: 首页>>代码示例>>Python>>正文


Python signal.hamming函数代码示例

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


在下文中一共展示了hamming函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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