Python numpy.kaiser() Examples
The following are 13 code examples for showing how to use numpy.kaiser(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: deep-learning-note Author: wdxtub File: util.py License: MIT License | 5 votes |
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]
Example 2
Project: deep-learning-from-scratch Author: oreilly-japan File: util.py License: MIT License | 5 votes |
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]
Example 3
Project: cupy Author: cupy File: window.py License: MIT License | 5 votes |
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)
Example 4
Project: spectrum Author: cokelaer File: window.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example 5
Project: spectrum Author: cokelaer File: window.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example 6
Project: sound_field_analysis-py Author: AppliedAcousticsChalmers File: process.py License: MIT License | 5 votes |
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
Example 7
Project: deep-learning-from-scratch Author: hguomin File: util.py License: MIT License | 5 votes |
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]
Example 8
Project: pystoi Author: mpariente File: utils.py License: MIT License | 5 votes |
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
Example 9
Project: R-CNN_LIGHT Author: YeongHyeon File: util.py License: MIT License | 5 votes |
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]
Example 10
Project: sfs-python Author: sfstoolbox File: tapering.py License: MIT License | 5 votes |
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
Example 11
Project: MLPrimitives Author: HDI-Project File: dsp.py License: MIT License | 5 votes |
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
Example 12
Project: spectrum Author: cokelaer File: window.py License: BSD 3-Clause "New" or "Revised" License | 4 votes |
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
Example 13
Project: sarpy Author: ngageoint File: Grid.py License: MIT License | 4 votes |
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)