本文整理匯總了Python中numpy.kaiser方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.kaiser方法的具體用法?Python numpy.kaiser怎麽用?Python numpy.kaiser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.kaiser方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: smooth_curve
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def smooth_curve(x):
"""用於使損失函數的圖形變圓滑
參考:http://glowingpython.blogspot.jp/2012/02/convolution-with-numpy.html
"""
window_len = 11
s = np.r_[x[window_len-1:0:-1], x, x[-1:-window_len:-1]]
w = np.kaiser(window_len, 2)
y = np.convolve(w/w.sum(), s, mode='valid')
return y[5:len(y)-5]
示例2: window_visu
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def window_visu(N=51, name='hamming', **kargs):
"""A Window visualisation tool
:param N: length of the window
:param name: name of the window
:param NFFT: padding used by the FFT
:param mindB: the minimum frequency power in dB
:param maxdB: the maximum frequency power in dB
:param kargs: optional arguments passed to :func:`create_window`
This function plot the window shape and its equivalent in the Fourier domain.
.. plot::
:width: 80%
:include-source:
from spectrum import window_visu
window_visu(64, 'kaiser', beta=8.)
"""
# get the default parameters
mindB = kargs.pop('mindB', -100)
maxdB = kargs.pop('maxdB', None)
norm = kargs.pop('norm', True)
# create a window object
w = Window(N, name, **kargs)
# plot the time and frequency windows
w.plot_time_freq(mindB=mindB, maxdB=maxdB, norm=norm)
示例3: smooth_curve
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def smooth_curve(x):
"""損失関數のグラフを滑らかにするために用いる
參考:http://glowingpython.blogspot.jp/2012/02/convolution-with-numpy.html
"""
window_len = 11
s = np.r_[x[window_len-1:0:-1], x, x[-1:-window_len:-1]]
w = np.kaiser(window_len, 2)
y = np.convolve(w/w.sum(), s, mode='valid')
return y[5:len(y)-5]
示例4: kaiser
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def kaiser(M, beta):
"""Return the Kaiser window.
The Kaiser window is a taper formed by using a Bessel function.
.. math:: w(n) = I_0\\left( \\beta \\sqrt{1-\\frac{4n^2}{(M-1)^2}}
\\right)/I_0(\\beta)
with
.. math:: \\quad -\\frac{M-1}{2} \\leq n \\leq \\frac{M-1}{2}
where :math:`I_0` is the modified zeroth-order Bessel function.
Args:
M (int):
Number of points in the output window. If zero or less, an empty
array is returned.
beta (float):
Shape parameter for window
Returns:
~cupy.ndarray: The window, with the maximum value normalized to one
(the value one appears only if the number of samples is odd).
.. seealso:: :func:`numpy.kaiser`
"""
if M == 1:
return cupy.array([1.])
if M <= 0:
return cupy.array([])
alpha = (M - 1) / 2.0
out = cupy.empty(M, dtype=cupy.float64)
return _kaiser_kernel(beta, alpha, out)
示例5: _kaiser
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def _kaiser(n, beta):
"""Independant Kaiser window
For the definition of the Kaiser window, see A. V. Oppenheim & R. W. Schafer, "Discrete-Time Signal Processing".
The continuous version of width n centered about x=0 is:
.. note:: 2 times slower than scipy.kaiser
"""
from scipy.special import iv as besselI
m = n - 1
k = arange(0, m)
k = 2. * beta / m * sqrt (k * (m - k))
w = besselI (0, k) / besselI (0, beta)
return w
示例6: iFFT
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def iFFT(Y, output_length=None, window=False):
""" Inverse real-valued Fourier Transform
Parameters
----------
Y : array_like
Frequency domain data [Nsignals x Nbins]
output_length : int, optional
Length of returned time-domain signal (Default: 2 x len(Y) + 1)
window : boolean, optional
Window applied to the resulting time-domain signal
Returns
-------
y : array_like
Reconstructed time-domain signal
"""
Y = _np.atleast_2d(Y)
y = _np.fft.irfft(Y, n=output_length)
if window:
no_of_samples = y.shape[-1]
if window == 'hann':
window_array = _np.hanning(no_of_samples)
elif window == 'hamming':
window_array = _np.hamming(no_of_samples)
elif window == 'blackman':
window_array = _np.blackman(no_of_samples)
elif window == 'kaiser':
window_array = _np.kaiser(no_of_samples, 3)
else:
raise ValueError('Selected window must be one of hann, hamming, blackman or kaiser')
y *= window_array
return y
# noinspection PyUnusedLocal
示例7: smooth_curve
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def smooth_curve(x):
"""用於使損失函數的圖形變圓滑
參考:http://glowingpython.blogspot.jp/2012/02/convolution-with-numpy.html
"""
window_len = 11
s = np.r_[x[window_len-1:0:-1], x, x[-1:-window_len:-1]]
w = np.kaiser(window_len, 2)
y = np.convolve(w/w.sum(), s, mode='valid')
return y[5:len(y)-5]
示例8: _resample_window_oct
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def _resample_window_oct(p, q):
"""Port of Octave code to Python"""
gcd = np.gcd(p, q)
if gcd > 1:
p /= gcd
q /= gcd
# Properties of the antialiasing filter
log10_rejection = -3.0
stopband_cutoff_f = 1. / (2 * max(p, q))
roll_off_width = stopband_cutoff_f / 10
# Determine filter length
rejection_dB = -20 * log10_rejection
L = np.ceil((rejection_dB - 8) / (28.714 * roll_off_width))
# Ideal sinc filter
t = np.arange(-L, L + 1)
ideal_filter = 2 * p * stopband_cutoff_f \
* np.sinc(2 * stopband_cutoff_f * t)
# Determine parameter of Kaiser window
if (rejection_dB >= 21) and (rejection_dB <= 50):
beta = 0.5842 * (rejection_dB - 21)**0.4 \
+ 0.07886 * (rejection_dB - 21)
elif rejection_dB > 50:
beta = 0.1102 * (rejection_dB - 8.7)
else:
beta = 0.0
# Apodize ideal filter response
h = np.kaiser(2 * L + 1, beta) * ideal_filter
return h
示例9: smooth_curve
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def smooth_curve(x):
""" Used to smooth the graph of the loss function
reference:http://glowingpython.blogspot.jp/2012/02/convolution-with-numpy.html
"""
window_len = 11
s = np.r_[x[window_len-1:0:-1], x, x[-1:-window_len:-1]]
w = np.kaiser(window_len, 2)
y = np.convolve(w/w.sum(), s, mode='valid')
return y[5:len(y)-5]
示例10: kaiser
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def kaiser(active, *, beta):
"""Kaiser tapering window.
This uses :func:`numpy.kaiser`.
Parameters
----------
active : array_like, dtype=bool
A boolean array containing ``True`` for active loudspeakers.
alpha : float
Shape parameter of the Kaiser window, see :func:`numpy.kaiser`.
Returns
-------
(len(active),) `numpy.ndarray`
Tapering weights.
Examples
--------
.. plot::
:context: close-figs
plt.plot(sfs.tapering.kaiser(active1, beta=0), label='beta = 0')
plt.plot(sfs.tapering.kaiser(active1, beta=2), label='beta = 2')
plt.plot(sfs.tapering.kaiser(active1, beta=6), label='beta = 6')
plt.plot(sfs.tapering.kaiser(active1, beta=8.6), label='beta = 8.6')
plt.plot(sfs.tapering.kaiser(active1, beta=14), label='beta = 14')
plt.axis([-3, 103, -0.1, 1.1])
plt.legend(loc='lower center')
.. plot::
:context: close-figs
plt.plot(sfs.tapering.kaiser(active2, beta=7))
plt.axis([-3, 103, -0.1, 1.1])
"""
idx = _windowidx(active)
window = _np.zeros(len(active))
window[idx] = _np.kaiser(len(idx), beta)
return window
示例11: window_design
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def window_design(self, window_length, beta):
"""Kaiser window design
Args:
window_length: Length of the window in number of samples
beta: Beta value for Kaiser window design
Returns:
window: Window designed using the beta and length provided as inputs
"""
self.window = np.kaiser(window_length, beta)
return self.window
示例12: enbw
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def enbw(data):
r"""Computes the equivalent noise bandwidth
.. math:: ENBW = N \frac{\sum_{n=1}^{N} w_n^2}{\left(\sum_{n=1}^{N} w_n \right)^2}
.. doctest::
>>> from spectrum import create_window, enbw
>>> w = create_window(64, 'rectangular')
>>> enbw(w)
1.0
The following table contains the ENBW values for some of the
implemented windows in this module (with N=16384). They have been
double checked against litterature (Source: [Harris]_, [Marple]_).
If not present, it means that it has not been checked.
=================== ============ =============
name ENBW litterature
=================== ============ =============
rectangular 1. 1.
triangle 1.3334 1.33
Hann 1.5001 1.5
Hamming 1.3629 1.36
blackman 1.7268 1.73
kaiser 1.7
blackmanharris,4 2.004 2.
riesz 1.2000 1.2
riemann 1.32 1.3
parzen 1.917 1.92
tukey 0.25 1.102 1.1
bohman 1.7858 1.79
poisson 2 1.3130 1.3
hanningpoisson 0.5 1.609 1.61
cauchy 1.489 1.48
lanczos 1.3
=================== ============ =============
"""
N = len(data)
return N * np.sum(data**2) / np.sum(data)**2
示例13: define_weight_function
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import kaiser [as 別名]
def define_weight_function(self, weight_size=DEFAULT_WEIGHT_SIZE):
"""
Try to derive WgtFunct from WgtType, if necessary. This should likely be called from the `GridType` parent.
Parameters
----------
weight_size : int
the size of the `WgtFunct` to generate.
Returns
-------
None
"""
if self.WgtType is None or self.WgtType.WindowName is None:
return # nothing to be done
window_name = self.WgtType.WindowName.upper()
if window_name == 'HAMMING':
# A Hamming window is defined in many places as a raised cosine of weight .54, so this is the default.
# Some data use a generalized raised cosine and call it HAMMING, so we allow for both uses.
try:
# noinspection PyTypeChecker
coef = float(self.WgtType.get_parameter_value(None, 0.54)) # just get first parameter - name?
except ValueError:
coef = 0.54
self.WgtFunct = _raised_cos(weight_size, coef)
elif window_name == 'HANNING':
self.WgtFunct = _raised_cos(weight_size, 0.5)
elif window_name == 'KAISER':
try:
# noinspection PyTypeChecker
beta = float(self.WgtType.get_parameter_value(None, 14)) # just get first parameter - name?
except ValueError:
beta = 14.0 # default suggested in numpy.kaiser
self.WgtFunct = numpy.kaiser(weight_size, beta)
elif window_name == 'TAYLOR':
# noinspection PyTypeChecker
sidelobes = int(self.WgtType.get_parameter_value('NBAR', 4)) # apparently the matlab argument name
# noinspection PyTypeChecker
max_sidelobe_level = float(self.WgtType.get_parameter_value('SLL', -30)) # same
if max_sidelobe_level > 0:
max_sidelobe_level *= -1
self.WgtFunct = _taylor_win(weight_size,
sidelobes=sidelobes,
max_sidelobe_level=max_sidelobe_level,
normalize=True)