← Back
Editing: _czt.cpython-311.pyc
� d�c�K � � � d Z ddlZddlZddlZddlmZmZ ddlmZm Z m Z g d�Zd� Zdd�Z G d � d � � Z G d� de� � Zdd d�d�Zdddd d�d�ZdS )a� Chirp z-transform. We provide two interfaces to the chirp z-transform: an object interface which precalculates part of the transform and can be applied efficiently to many different data sets, and a functional interface which is applied only to the given data set. Transforms ---------- CZT : callable (x, axis=-1) -> array Define a chirp z-transform that can be applied to different signals. ZoomFFT : callable (x, axis=-1) -> array Define a Fourier transform on a range of frequencies. Functions --------- czt : array Compute the chirp z-transform for a signal. zoom_fft : array Compute the Fourier transform on a range of frequencies. � N)�pi�arange)�fft�ifft� next_fast_len)�czt�zoom_fft�CZT�ZoomFFT� czt_pointsc �� � | dk st | t j � � st d| � d�� � �|�| }n3|dk st |t j � � st d|� d�� � �|S )N� z#Invalid number of CZT data points (z1) specified. n must be positive and integer type.z%Invalid number of CZT output points (z1) specified. m must be positive and integer type.)� isinstance�numbers�Integral� ValueError)�n�ms �3/usr/lib/python3/dist-packages/scipy/signal/_czt.py�_validate_sizesr % s� � ��1�u�u�J�q�'�"2�3�3�u�� @�$%�@� @� @� A� A� A� �y� ��� �Q���j��G�$4�5�5��� @�$%�@� @� @� A� A� A� �H� � �? c � � t d| � � } t | � � }d|z }|�%|t j dt z |z | z � � z S d|z }||| z z S )a� Return the points at which the chirp z-transform is computed. Parameters ---------- m : int The number of points desired. w : complex, optional The ratio between points in each step. Defaults to equally spaced points around the entire unit circle. a : complex, optional The starting point in the complex plane. Default is 1+0j. Returns ------- out : ndarray The points in the Z plane at which `CZT` samples the z-transform, when called with arguments `m`, `w`, and `a`, as complex numbers. See Also -------- CZT : Class that creates a callable chirp z-transform function. czt : Convenience function for quickly calculating CZT. Examples -------- Plot the points of a 16-point FFT: >>> import numpy as np >>> from scipy.signal import czt_points >>> points = czt_points(16) >>> import matplotlib.pyplot as plt >>> plt.plot(points.real, points.imag, 'o') >>> plt.gca().add_patch(plt.Circle((0,0), radius=1, fill=False, alpha=.3)) >>> plt.axis('equal') >>> plt.show() and a 91-point logarithmic spiral that crosses the unit circle: >>> m, w, a = 91, 0.995*np.exp(-1j*np.pi*.05), 0.8*np.exp(1j*np.pi/6) >>> points = czt_points(m, w, a) >>> plt.plot(points.real, points.imag, 'o') >>> plt.gca().add_patch(plt.Circle((0,0), radius=1, fill=False, alpha=.3)) >>> plt.axis('equal') >>> plt.show() r � �?N� @)r r �np�expr )r �w�a�ks r r r 5 si � �^ ��1���A��q� � �A��a��A��y��2�6�"�r�'�A�+��/�*�*�*�*� �!�G���1�q�b�5�y�r c �, � e Zd ZdZd d�Zdd�d�Zd� ZdS ) r a Create a callable chirp z-transform function. Transform to compute the frequency response around a spiral. Objects of this class are callables which can compute the chirp z-transform on their inputs. This object precalculates the constant chirps used in the given transform. Parameters ---------- n : int The size of the signal. m : int, optional The number of output points desired. Default is `n`. w : complex, optional The ratio between points in each step. This must be precise or the accumulated error will degrade the tail of the output sequence. Defaults to equally spaced points around the entire unit circle. a : complex, optional The starting point in the complex plane. Default is 1+0j. Returns ------- f : CZT Callable object ``f(x, axis=-1)`` for computing the chirp z-transform on `x`. See Also -------- czt : Convenience function for quickly calculating CZT. ZoomFFT : Class that creates a callable partial FFT function. Notes ----- The defaults are chosen such that ``f(x)`` is equivalent to ``fft.fft(x)`` and, if ``m > len(x)``, that ``f(x, m)`` is equivalent to ``fft.fft(x, m)``. If `w` does not lie on the unit circle, then the transform will be around a spiral with exponentially-increasing radius. Regardless, angle will increase linearly. For transforms that do lie on the unit circle, accuracy is better when using `ZoomFFT`, since any numerical error in `w` is accumulated for long data lengths, drifting away from the unit circle. The chirp z-transform can be faster than an equivalent FFT with zero padding. Try it with your own array sizes to see. However, the chirp z-transform is considerably less precise than the equivalent zero-padded FFT. As this CZT is implemented using the Bluestein algorithm, it can compute large prime-length Fourier transforms in O(N log N) time, rather than the O(N**2) time required by the direct DFT calculation. (`scipy.fft` also uses Bluestein's algorithm'.) (The name "chirp z-transform" comes from the use of a chirp in the Bluestein algorithm. It does not decompose signals into chirps, like other transforms with "chirp" in the name.) References ---------- .. [1] Leo I. Bluestein, "A linear filtering approach to the computation of the discrete Fourier transform," Northeast Electronics Research and Engineering Meeting Record 10, 218-219 (1968). .. [2] Rabiner, Schafer, and Rader, "The chirp z-transform algorithm and its application," Bell Syst. Tech. J. 48, 1249-1292 (1969). Examples -------- Compute multiple prime-length FFTs: >>> from scipy.signal import CZT >>> import numpy as np >>> a = np.random.rand(7) >>> b = np.random.rand(7) >>> c = np.random.rand(7) >>> czt_7 = CZT(n=7) >>> A = czt_7(a) >>> B = czt_7(b) >>> C = czt_7(c) Display the points at which the FFT is calculated: >>> czt_7.points() array([ 1.00000000+0.j , 0.62348980+0.78183148j, -0.22252093+0.97492791j, -0.90096887+0.43388374j, -0.90096887-0.43388374j, -0.22252093-0.97492791j, 0.62348980-0.78183148j]) >>> import matplotlib.pyplot as plt >>> plt.plot(czt_7.points().real, czt_7.points().imag, 'o') >>> plt.gca().add_patch(plt.Circle((0,0), radius=1, fill=False, alpha=.3)) >>> plt.axis('equal') >>> plt.show() Nr c �� � t ||� � }t t ||� � t j t ||� � dz � � �� � }|�Lt j dt z |z � � }t j dt z |dz d|z z z |z � � }n||dz dz z }d|z }||c| _ | _ ||c| _ | _ t ||z dz � � }||d |� z |d |� z | _ || _ t dt j ||dz dd � |d |� f� � z |� � | _ |d |� | _ t'