← Back
Editing: _waveforms.cpython-311.pyc
� d�c+P � � � d dl Zd dl mZmZmZmZmZmZmZm Z m Z mZmZm Z mZmZ g d�Zdd�Zdd�Z dd�Zdd�Zdd�Zdd�Zd� Zdefd�ZdS )� N)�asarray�zeros�place�nan�mod�pi�extract�log�sqrt�exp�cos�sin�polyval�polyint)�sawtooth�square� gausspulse�chirp� sweep_poly�unit_impulse� c �� � t | � � t |� � }} t || | z z � � }t | ||z z � � } | j j dv r | j j }nd}t | j |� � }|dk |dk z }t ||t � � t | dt z � � }d|z ||dz t z k z }t ||� � }t ||� � } t |||t | z z dz � � d|z d|z z } t | |� � }t | |� � } t || t | dz z |z t d| z z z � � |S )a� Return a periodic sawtooth or triangle waveform. The sawtooth waveform has a period ``2*pi``, rises from -1 to 1 on the interval 0 to ``width*2*pi``, then drops from 1 to -1 on the interval ``width*2*pi`` to ``2*pi``. `width` must be in the interval [0, 1]. Note that this is not band-limited. It produces an infinite number of harmonics, which are aliased back and forth across the frequency spectrum. Parameters ---------- t : array_like Time. width : array_like, optional Width of the rising ramp as a proportion of the total cycle. Default is 1, producing a rising ramp, while 0 produces a falling ramp. `width` = 0.5 produces a triangle wave. If an array, causes wave shape to change over time, and must be the same length as t. Returns ------- y : ndarray Output array containing the sawtooth waveform. Examples -------- A 5 Hz waveform sampled at 500 Hz for 1 second: >>> import numpy as np >>> from scipy import signal >>> import matplotlib.pyplot as plt >>> t = np.linspace(0, 1, 500) >>> plt.plot(t, signal.sawtooth(2 * np.pi * 5 * t)) ��fFdD�dr r � ) r �dtype�charr �shaper r r r r )�t�width�w�ytype�y�mask1�tmod�mask2�tsub�wsub�mask3s �9/usr/lib/python3/dist-packages/scipy/signal/_waveforms.pyr r sk � �N �1�:�:�w�u�~�~�q�A���Q��U����A���Q��U����A��w�|�x���������� �a�g�u���A� ��U�q�1�u��E� �!�U�C���� �q�!�b�&�>�>�D� ��Y�4�!�a�%�"�*�,�-�E��5�$���D��5�!���D� �!�U�D�B��I�&��*�+�+�+� ��Y�1�u�9�%�E��5�$���D��5�!���D� �!�U�R�4�!�8�_�t�+��a�$�h��@�A�A�A��H� � �?c � � t | � � t |� � }} t || | z z � � }t | ||z z � � } | j j dv r | j j }nd}t | j |� � }|dk |dk z }t ||t � � t | dt z � � }d|z ||dz t z k z }t ||d� � d|z d|z z }t ||d� � |S )aB Return a periodic square-wave waveform. The square wave has a period ``2*pi``, has value +1 from 0 to ``2*pi*duty`` and -1 from ``2*pi*duty`` to ``2*pi``. `duty` must be in the interval [0,1]. Note that this is not band-limited. It produces an infinite number of harmonics, which are aliased back and forth across the frequency spectrum. Parameters ---------- t : array_like The input time array. duty : array_like, optional Duty cycle. Default is 0.5 (50% duty cycle). If an array, causes wave shape to change over time, and must be the same length as t. Returns ------- y : ndarray Output array containing the square waveform. Examples -------- A 5 Hz waveform sampled at 500 Hz for 1 second: >>> import numpy as np >>> from scipy import signal >>> import matplotlib.pyplot as plt >>> t = np.linspace(0, 1, 500, endpoint=False) >>> plt.plot(t, signal.square(2 * np.pi * 5 * t)) >>> plt.ylim(-2, 2) A pulse-width modulated sine wave: >>> plt.figure() >>> sig = np.sin(2 * np.pi * t) >>> pwm = signal.square(2 * np.pi * 30 * t, duty=(sig + 1)/2) >>> plt.subplot(2, 1, 1) >>> plt.plot(t, sig) >>> plt.subplot(2, 1, 2) >>> plt.plot(t, pwm) >>> plt.ylim(-1.5, 1.5) r r r r r ���) r r r r r r r r r ) r �dutyr"