當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.blackman方法代碼示例

本文整理匯總了Python中numpy.blackman方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.blackman方法的具體用法?Python numpy.blackman怎麽用?Python numpy.blackman使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.blackman方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_mgc_example

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def run_mgc_example():
    import matplotlib.pyplot as plt
    fs, x = wavfile.read("test16k.wav")
    pos = 3000
    fftlen = 1024
    win = np.blackman(fftlen) / np.sqrt(np.sum(np.blackman(fftlen) ** 2))
    xw = x[pos:pos + fftlen] * win
    sp = 20 * np.log10(np.abs(np.fft.rfft(xw)))
    mgc_order = 20
    mgc_alpha = 0.41
    mgc_gamma = -0.35
    mgc_arr = win2mgc(xw, order=mgc_order, alpha=mgc_alpha, gamma=mgc_gamma, verbose=True)
    xwsp = 20 * np.log10(np.abs(np.fft.rfft(xw)))
    sp = mgc2sp(mgc_arr, mgc_alpha, mgc_gamma, fftlen)
    plt.plot(xwsp)
    plt.plot(20. / np.log(10) * np.real(sp), "r")
    plt.xlim(1, len(xwsp))
    plt.show() 
開發者ID:kastnerkyle,項目名稱:tools,代碼行數:20,代碼來源:audio_tools.py

示例2: transform

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def transform(self, X_indices, y_indices):
        X_indices, y_indices = super(IndexBatchIterator, self).transform(X_indices, y_indices)
        [count] = X_indices.shape
        # Use preallocated space
        X = self.Xbuf[:count]
        Y = self.Ybuf[:count]
        window = np.blackman(SAMPLE_SIZE//DOWNSAMPLE)[None,:]
        for i, ndx in enumerate(X_indices):
            if ndx == -1:
                ndx = np.random.randint(len(self.source.events))
            augmented = self.augmented[:,ndx:ndx+SAMPLE_SIZE]
            X[i] = augmented[:,::-1][:,::DOWNSAMPLE]
            if y_indices is not None:
                Y[i] = self.source.events[ndx]
        Y = None if (y_indices is None) else Y
        return X, Y 
開發者ID:bitsofbits,項目名稱:kaggle_grasp_and_lift_eeg_detection,代碼行數:18,代碼來源:net34.py

示例3: spectrum

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def spectrum(signal, fs, taper=True):
        if taper:
            windowed = signal * np.blackman(len(signal))
        else:
            windowed = signal
        a = abs(np.fft.rfft(windowed))
        f = np.fft.rfftfreq(len(signal), 1/fs)

        db = 20 * np.log10(a)
        sig = db - np.amax(db) + 20
        indices = ((sig[1:] >= 0) & (sig[:-1] < 0)).nonzero()
        crossings = [z - sig[z] / (sig[z+1] - sig[z]) for z in indices]
        mi, ma = np.amin(crossings), np.amax(crossings)
        x = np.arange(0, len(f))  # for back-interpolation
        f_min = np.interp(mi, x, f)
        f_max = np.interp(ma, x, f)

        return f, a, f_min, f_max 
開發者ID:agile-geoscience,項目名稱:seisplot,代碼行數:20,代碼來源:seismic.py

示例4: impulse_response

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def impulse_response(self, sampling_frequency):
        dt = 1 / sampling_frequency
        if self.impulse_window in ['hanning', 'blackman']:
            t_start = 0
            t_stop = int(self.impulse_cycles / self.center_frequency * sampling_frequency) * dt  # int() applies floor
            t_num = int(self.impulse_cycles / self.center_frequency * sampling_frequency) + 1  # int() applies floor
            t = np.linspace(t_start, t_stop, t_num)
            impulse = np.sin(2 * np.pi * self.center_frequency * t)
            if self.impulse_window == 'hanning':
                win = np.hanning(impulse.shape[0])
            elif self.impulse_window == 'blackman':
                win = np.blackman(impulse.shape[0])
            else:
                raise NotImplementedError('Window type {} not implemented'.format(self.impulse_window))
            return impulse * win
        elif self.impulse_window == 'gauss':
            # Compute cutoff time for when the pulse amplitude falls below `tpr` (in dB) which is set at -100dB
            tpr = -60
            t_cutoff = scipy.signal.gausspulse('cutoff', fc=int(self.center_frequency), bw=self.bandwidth, tpr=tpr)
            t = np.arange(-t_cutoff, t_cutoff, dt)
            return scipy.signal.gausspulse(t, fc=self.center_frequency, bw=self.bandwidth, tpr=tpr)
        else:
            raise NotImplementedError('Window type {} not implemented'.format(self.impulse_window)) 
開發者ID:dperdios,項目名稱:us-rawdata-sda,代碼行數:25,代碼來源:probe1d.py

示例5: find_peak

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def find_peak(fname):
    """Find the signal frequency and maximum value"""
    #print("find_peak",fname)
    Fs, x = wavfile.read(fname)
    f,s = periodogram(x, Fs,'blackman',8192,'linear', False, scaling='spectrum')
    threshold = max(s)*0.8  # only 0.4 ... 1.0 of max value freq peaks included
    maxtab, mintab = peakdet(abs(s[0:int(len(s)/2-1)]), threshold,f[0:int(len(f)/2-1)] )
    try:
        val = maxtab[0,0]
    except:
        print("Error: {}".format(maxtab))
        val = 600.
    return val

# Fs should be 8000 Hz 
# with decimation down to 125 Hz we get 8 msec / sample
# with WPM equals to 20 => Tdit = 1200/WPM = 60 msec   (time of 'dit')
# 4 seconds equals 256 samples ~ 66.67 Tdits 
# word 'PARIS' is 50 Tdits 
開發者ID:ag1le,項目名稱:LSTM_morse,代碼行數:21,代碼來源:MorseDecoder.py

示例6: design_windowed_sinc_lpf

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def design_windowed_sinc_lpf(fc, bw):
        N = Filter.get_filter_length_from_bandwidth(bw)

        # Compute sinc filter impulse response
        h = np.sinc(2 * fc * (np.arange(N) - (N - 1) / 2.))

        # We use blackman window function
        w = np.blackman(N)

        # Multiply sinc filter with window function
        h = h * w

        # Normalize to get unity gain
        h_unity = h / np.sum(h)

        return h_unity 
開發者ID:jopohl,項目名稱:urh,代碼行數:18,代碼來源:Filter.py

示例7: smooth

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def smooth(y, box_pts, window='flat'):
  # https://scipy-cookbook.readthedocs.io/items/SignalSmooth.html
  if window is 'flat':
    box = np.ones(box_pts)
  elif window is 'blackman':
    box =  np.blackman(box_pts)
  else:
    raise ValueError('unknown window')
  box /= np.sum(box)
  y_smooth = astroconv.convolve(y, box, boundary='extend') # also: None, fill, wrap, extend
  return y_smooth 
開發者ID:calico,項目名稱:basenji,代碼行數:13,代碼來源:basenji_data_hic_read.py

示例8: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def __init__(self, sf=16000, fl=400, fs=80, fftl=1024, mfbsize=80):
        self.sf = sf
        self.fl = fl
        self.fs = fs
        self.fftl = fftl
        self.mfbsize = mfbsize
        winpower = np.sqrt(np.sum(np.square(np.blackman(self.fl).astype(np.float32))))
        self.window = np.blackman(self.fl).astype(np.float32) / winpower
        self.melfb = self._melfbank() 
開發者ID:nii-yamagishilab,項目名稱:project-CURRENNT-scripts,代碼行數:11,代碼來源:speechprocessing.py

示例9: test_fft_peaks

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def test_fft_peaks():
    fig, ax = plt.subplots()
    t = np.arange(65536)
    p1 = ax.plot(abs(np.fft.fft(np.sin(2*np.pi*.01*t)*np.blackman(len(t)))))

    path = p1[0].get_path()
    transform = p1[0].get_transform()
    path = transform.transform_path(path)
    simplified = path.cleaned(simplify=True)

    assert simplified.vertices.size == 36 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_simplification.py

示例10: blackman

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def blackman(M):
    """Returns the Blackman window.

    The Blackman window is defined as

    .. math::
        w(n) = 0.42 - 0.5 \\cos\\left(\\frac{2\\pi{n}}{M-1}\\right)
        + 0.08 \\cos\\left(\\frac{4\\pi{n}}{M-1}\\right)
        \\qquad 0 \\leq n \\leq M-1

    Args:
        M (:class:`~int`):
            Number of points in the output window. If zero or less, an empty
            array is returned.

    Returns:
        ~cupy.ndarray: Output ndarray.

    .. seealso:: :func:`numpy.blackman`
    """
    if M == 1:
        return cupy.ones(1, dtype=cupy.float64)
    if M <= 0:
        return cupy.array([])
    alpha = numpy.pi * 2 / (M - 1)
    out = cupy.empty(M, dtype=cupy.float64)
    return _blackman_kernel(alpha, out) 
開發者ID:cupy,項目名稱:cupy,代碼行數:29,代碼來源:window.py

示例11: plotPSD

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def plotPSD(data,fftWindow, Fs):

    assert fftWindow in ['rectangular', 'bartlett', 'blackman', 
                         'hamming', 'hanning']
    
    N = len(data)
    
    #Generate the selected window
    if fftWindow == "rectangular":
        window = np.ones(N)
    elif fftWindow == "bartlett":
        window = np.bartlett(N)
    elif args.fftWindow == "blackman":
        window = np.blackman(N)
    elif fftWindow == "hamming":
        window = np.hamming(N)
    elif fftWindow == "hanning":
         window = np.hanning(N)         
         
    dft = np.fft.fft(data*window)    
    
    if Fs == None:
        #If the sample rate is known then plot PSD as
        #Power/Freq in (dB/Hz)
        plt.psd(data*window, NFFT=N)
        
    else:
        #If sample rate is not known then plot PSD as
        #Power/Freq as (dB/rad/sample)
        plt.psd(data*window, NFFT=N, Fs=Fs)

    plt.show() 
開發者ID:jgibbard,項目名稱:iqtool,代碼行數:34,代碼來源:iqplot.py

示例12: plotSpectrogram

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def plotSpectrogram(data, fftWindow, fftSize, Fs):

    if fftSize == None:
        N = len(data)
    else:
        N = fftSize    
    
    if Fs == None:
        Fs = 2
    
    if fftWindow == "rectangular":
        plt.specgram(data, NFFT=N, Fs=Fs, 
        window=lambda data: data*np.ones(len(data)),  noverlap=int(N/10))
    elif fftWindow == "bartlett":
        plt.specgram(data, NFFT=N, Fs=Fs, 
        window=lambda data: data*np.bartlett(len(data)),  noverlap=int(N/10))
    elif args.fftWindow == "blackman":
        plt.specgram(data, NFFT=N, Fs=Fs, 
        window=lambda data: data*np.blackman(len(data)),  noverlap=int(N/10))
    elif fftWindow == "hamming":
        plt.specgram(data, NFFT=N, Fs=Fs, 
        window=lambda data: data*np.hamming(len(data)),  noverlap=int(N/10))
    elif fftWindow == "hanning":
         plt.specgram(data, NFFT=N, Fs=Fs, 
         window=lambda data: data*np.hanning(len(data)),  noverlap=int(N/10))

    plt.show() 
開發者ID:jgibbard,項目名稱:iqtool,代碼行數:29,代碼來源:iqplot.py

示例13: init

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def init(self, lo=0, hi=125, bins=256, yrange=750, ratio=False):
        self.widget = pg.PlotWidget()
        self.widget.setLabel('bottom', 'Frequency', units='Hz')

        self.bars = pg.BarGraphItem()

        self.win = np.hanning(bins)
        self.win = np.blackman(bins)
        #self.win = np.ones(bins)
        self.lo, self.hi = lo, hi
        self.ratio = ratio
        
        FS = self.input.sample_rate

        self.gr_block.set_history(bins)

        #num_bars = int(round((self.bins - 1) * (self.hi - self.lo) / FS))
        # This is total bullshit:
        num_bars = len(np.zeros(bins)[lo: hi])

        x = np.linspace(self.lo, self.hi, num_bars)

        self.bars = pg.BarGraphItem(x=x, height=range(num_bars), width=1.0)
        
        self.bars.setOpts(brushes=[pg.hsvColor(float(x) / num_bars) for x in range(num_bars)])
        self.widget.addItem(self.bars)

        # TODO: Better autoranging features
        #self.plot.enableAutoRange('xy', False)
        
        self.widget.setYRange(0, yrange)
        self.widget.enableAutoRange('y', 0.95)

        self.buffer = np.zeros(bins)

        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.updateGUI)
        self.timer.start(10) 
開發者ID:strfry,項目名稱:OpenNFB,代碼行數:40,代碼來源:gnuradio_protocol.py

示例14: init

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def init(self, lo=0, hi=125, bins=256, yrange=750, ratio=False):
        self.widget = pg.PlotWidget()
        self.widget.setLabel('bottom', 'Frequency', units='Hz')

        self.bars = pg.BarGraphItem()

        self.win = np.hanning(bins)
        self.win = np.blackman(bins)
        #self.win = np.ones(bins)
        self.lo, self.hi = lo, hi
        self.ratio = ratio
        
        FS = self.input.sample_rate

        self.gr_block.set_history(bins)

        #num_bars = int(round((self.bins - 1) * (self.hi - self.lo) / FS))
        # This is total bullshit:
        num_bars = len(np.zeros(bins)[lo: hi])

        x = np.linspace(self.lo, self.hi, num_bars)

        self.bars = pg.BarGraphItem(x=x, height=range(num_bars), width=1.0)
        
        self.bars.setOpts(brushes=[pg.hsvColor(float(x) / num_bars) for x in range(num_bars)])
        self.widget.addItem(self.bars)

        # TODO: Better autoranging features
        #self.plot.enableAutoRange('xy', False)
        
        self.widget.setYRange(0, yrange)
        self.widget.enableAutoRange('y', 0.95)

        self.buffer = np.zeros(bins)

        self.timer = pg.QtCore.QTimer()
        self.timer.timeout.connect(self.updateGUI)
        self.timer.start(10) 
開發者ID:strfry,項目名稱:OpenNFB,代碼行數:40,代碼來源:display.py

示例15: init

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import blackman [as 別名]
def init(self):
        self.canvas = Canvas()
        self.widget = self.canvas.native

        self.gr_block.set_history(bins)
        self.win = np.blackman(bins) 
開發者ID:strfry,項目名稱:OpenNFB,代碼行數:8,代碼來源:waterfall.py


注:本文中的numpy.blackman方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。