本文整理匯總了Python中numpy.bartlett方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.bartlett方法的具體用法?Python numpy.bartlett怎麽用?Python numpy.bartlett使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.bartlett方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: bartlett
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def bartlett(M):
"""
An instance of this class returns the Bartlett spectral window in the
time-domain. The Bartlett window is very similar to a triangular window,
except that the end points are at zero. It is often used in signal
processing for tapering a signal, without generating too much ripple in
the frequency domain.
.. versionadded:: 0.6
Parameters
----------
M : integer scalar
Number of points in the output window. If zero or less,
an empty vector is returned.
Returns
-------
vector of doubles
The triangular window, with the maximum value normalized to one
(the value one appears only if the number of samples is odd), with
the first and last samples equal to zero.
"""
return bartlett_(M)
示例2: window_bartlett
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def window_bartlett(N):
r"""Bartlett window (wrapping of numpy.bartlett) also known as Fejer
:param int N: window length
The Bartlett window is defined as
.. math:: w(n) = \frac{2}{N-1} \left(
\frac{N-1}{2} - \left|n - \frac{N-1}{2}\right|
\right)
.. plot::
:width: 80%
:include-source:
from spectrum import window_visu
window_visu(64, 'bartlett')
.. seealso:: numpy.bartlett, :func:`create_window`, :class:`Window`.
"""
from numpy import bartlett
return bartlett(N)
示例3: window_hann
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def window_hann(N):
r"""Hann window (or Hanning). (wrapping of numpy.bartlett)
:param int N: window length
The Hanning window is also known as the Cosine Bell. Usually, it is called
Hann window, to avoid confusion with the Hamming window.
.. math:: w(n) = 0.5\left(1- \cos\left(\frac{2\pi n}{N-1}\right)\right)
\qquad 0 \leq n \leq M-1
.. plot::
:width: 80%
:include-source:
from spectrum import window_visu
window_visu(64, 'hanning')
.. seealso:: numpy.hanning, :func:`create_window`, :class:`Window`.
"""
from numpy import hanning
return hanning(N)
示例4: perform
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def perform(self, node, inputs, out_):
M = inputs[0]
out, = out_
out[0] = numpy.bartlett(M)
示例5: test_perform
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def test_perform(self):
x = tensor.lscalar()
f = function([x], self.op(x))
M = numpy.random.random_integers(3, 50, size=())
assert numpy.allclose(f(M), numpy.bartlett(M))
assert numpy.allclose(f(0), numpy.bartlett(0))
assert numpy.allclose(f(-1), numpy.bartlett(-1))
b = numpy.array([17], dtype='uint8')
assert numpy.allclose(f(b[0]), numpy.bartlett(b[0]))
示例6: bartlett
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def bartlett(M):
"""Returns the Bartlett window.
The Bartlett window is defined as
.. math::
w(n) = \\frac{2}{M-1} \\left(
\\frac{M-1}{2} - \\left|n - \\frac{M-1}{2}\\right|
\\right)
Args:
M (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.bartlett`
"""
if M == 1:
return cupy.ones(1, dtype=cupy.float64)
if M <= 0:
return cupy.array([])
alpha = (M - 1) / 2.0
out = cupy.empty(M, dtype=cupy.float64)
return _bartlett_kernel(alpha, out)
示例7: voi_noise_window
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def voi_noise_window(length):
return np.bartlett(length)**2.5 # 2.5 optimum # max: 4
#return np.bartlett(length)**4
#==============================================================================
# If win_func == None, no window is applied (i.e., boxcar)
# win_func: None, window function, or list of window functions.
示例8: plotPSD
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [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()
示例9: plotSpectrogram
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [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()
示例10: _get_window
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def _get_window(window, wlen):
if type(window) == str:
# types:
# boxcar, triang, blackman, hamming, hann, bartlett, flattop, parzen,
# bohman, blackmanharris, nuttall, barthann
if window == 'hamming':
fft_window = np.hamming(wlen)
elif window == 'bartlett':
fft_window = np.bartlett(wlen)
elif window == 'hann' or window == 'hanning':
fft_window = np.hanning(wlen)
else:
#try:
# scipy.signal.get_window gives non-symmetric results for hamming with even length :(
#fft_window = scipy.signal.get_window(window, wlen)
#except:
#raise Exception('cannot obtain window type {}'.format(window))
raise Exception('cannot obtain window type {}'.format(window))
# fft_window = scipy.signal.hamming(win_length, sym=False)
elif six.callable(window):
# User supplied a windowing function
fft_window = window(wlen)
else:
# User supplied a window vector.
# Make it into an array
fft_window = np.asarray(window)
assert(len(fft_window) == wlen)
fft_window.flatten()
return fft_window
示例11: smooth
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def smooth(x,window_len=11,window='flat'):
"""smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
(with the window size) in both ends so that transient parts are minimized
in the beginning and end part of the output signal.
:param x: the input signal
:param window_len: the dimension of the smoothing window; should be an odd integer
:param window: the type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'
flat window will produce a moving average smoothing.
:return: the smoothed signal
example::
t=linspace(-2,2,0.1)
x=sin(t)+randn(len(t))*0.1
y=smooth(x)
:see also: numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve,
scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string
"""
if x.ndim != 1:
raise ValueError("smooth only accepts 1 dimension arrays.")
if x.size < window_len:
raise ValueError("Input vector needs to be bigger than window size.")
if window_len < 3:
return x
if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
raise ValueError("Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'")
s=numpy.r_[2*x[0]-x[window_len:1:-1],x,2*x[-1]-x[-1:-window_len:-1]]
#print(len(s))
if window == 'flat': #moving average
w = numpy.ones(window_len,'d')
else:
w = eval('numpy.' + window + '(window_len)')
y = numpy.convolve(w/w.sum(), s, mode='same')
return y[window_len-1:-window_len+1]
示例12: smooth
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def smooth(x,window_len=11,window='flat'):
"""smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
(with the window size) in both ends so that transient parts are minimized
in the beginning and end part of the output signal.
:param x: the input signal
:param window_len: the dimension of the smoothing window; should be an odd integer
:param window: the type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'
flat window will produce a moving average smoothing.
:return: the smoothed signal
example::
t=linspace(-2,2,0.1)
x=sin(t)+randn(len(t))*0.1
y=smooth(x)
:see also: numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve,
scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string
"""
if x.ndim != 1:
raise ValueError, "smooth only accepts 1 dimension arrays."
if x.size < window_len:
raise ValueError, "Input vector needs to be bigger than window size."
if window_len<3:
return x
if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
raise ValueError, "Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"
s=numpy.r_[2*x[0]-x[window_len:1:-1],x,2*x[-1]-x[-1:-window_len:-1]]
#print(len(s))
if window == 'flat': #moving average
w=numpy.ones(window_len,'d')
else:
w=eval('numpy.'+window+'(window_len)')
y=numpy.convolve(w/w.sum(),s,mode='same')
return y[window_len-1:-window_len+1]
示例13: convolve
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def convolve(inspectral, samplingresolution, inwinwidth, outwinwidth, windowtype=np.bartlett):
""" Convolve (non-circular) a spectral variable with a window function,
given the input resolution and input and output window widths.
This function is normally used on wavenumber-domain spectral data. The spectral
data is assumed sampled at samplingresolution wavenumber intervals.
The inwinwidth and outwinwidth window function widths are full width half-max (FWHM)
for the window functions for the inspectral and returned spectral variables, respectively.
The Bartlett function is used as default, but the user can use a different function.
The Bartlett function is a triangular function reaching zero at the ends. Window function
width is correct for Bartlett and only approximate for other window functions.
Spectral convolution is best done in frequency domain ([cm-1] units) because
the filter or emission line shapes have better symmetry in frequency domain than
in wavelength domain.
The input spectral vector must be in spectral density units of cm-1.
Args:
| inspectral (np.array[N,] or [N,1]): spectral variable input vector (e.g., radiance or transmittance).
| samplingresolution (float): wavenumber interval between inspectral samples
| inwinwidth (float): FWHM window width used to obtain the input spectral vector (e.g., spectroradiometer window width)
| outwinwidth (float): FWHM window width of the output spectral vector after convolution
| windowtype (function): name of a numpy/scipy function for the window function
Returns:
| outspectral (np.array[N,]): input vector, filtered to new window width.
| windowfn (np.array[N,]): The window function used.
Raises:
| No exception is raised.
"""
winbins = round(2*(outwinwidth/(inwinwidth*samplingresolution)), 0)
winbins = winbins if winbins%2==1 else winbins+1
windowfn=windowtype(winbins)
#np.convolve is unfriendly towards unicode strings
if sys.version_info[0] > 2:
cmode='same'
else:
cmode='same'.encode('utf-8')
outspectral = np.convolve(windowfn/(samplingresolution*windowfn.sum()),
inspectral.reshape(-1, ),mode=cmode)
return outspectral, windowfn
######################################################################################
示例14: smooth
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bartlett [as 別名]
def smooth(x, window_len=11, window='flat'):
"""smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
(with the window size) in both ends so that transient parts are minimized
in the beginning and end part of the output signal.
:param x: the input signal
:param window_len: the dimension of the smoothing window; should be an odd integer
:param window: the type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'
flat window will produce a moving average smoothing.
:return: the smoothed signal
example::
t=linspace(-2,2,0.1)
x=sin(t)+randn(len(t))*0.1
y=smooth(x)
:see also: numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve,
scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string
"""
if x.ndim != 1:
raise ValueError("smooth only accepts 1 dimension arrays.")
if x.size < window_len:
raise ValueError("Input vector needs to be bigger than window size.")
if window_len < 3:
return x
if window not in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
raise ValueError(
"Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"
)
s = numpy.r_[2 * x[0] - x[window_len:1:-1], x, 2 * x[-1] - x[-1:-window_len:-1]]
# print(len(s))
if window == 'flat': # moving average
w = numpy.ones(window_len, 'd')
else:
w = eval('numpy.' + window + '(window_len)')
y = numpy.convolve(w / w.sum(), s, mode='same')
return y[window_len - 1 : -window_len + 1]