How to use the scipy.signal function in scipy

To help you get started, we’ve selected a few scipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ni / nimi-python / src / nifgen / examples / nifgen_script.py View on Github external
def calculate_square():
    time = np.linspace(start=0, stop=10, num=number_of_points)    # np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
    square_build = signal.square(t=time, duty=0.5)              # signal.square(t, duty=0.5)
    square = square_build.tolist()                              # List of Float
    return square
github eegsynth / eegsynth / module / generatesignal / generatesignal.py View on Github external
monitor.update("frequency", frequency)
    monitor.update("amplitude", amplitude)
    monitor.update("offset   ", offset)
    monitor.update("noise    ", noise)
    monitor.update("dutycycle", dutycycle)

    # compute the phase of each sample in this block
    phasevec = 2 * np.pi * frequency * timevec + phasevec[-1]
    if shape == 'sin':
        signal = np.sin(phasevec) * amplitude + offset
    elif shape == 'square':
        signal = sp.square(phasevec, dutycycle) * amplitude + offset
    elif shape == 'triangle':
        signal = sp.sawtooth(phasevec, 0.5) * amplitude + offset
    elif shape == 'sawtooth':
        signal = sp.sawtooth(phasevec, 1) * amplitude + offset
    elif shape == 'dc':
        signal = phasevec * 0. + offset

    dat_output = np.random.randn(blocksize, nchannels) * noise
    for chan in range(nchannels):
        dat_output[:, chan] += signal

    # write the data to the output buffer
    if datatype == 'uint8':
        ft_output.putData(dat_output.astype(np.uint8))
    elif datatype == 'int8':
        ft_output.putData(dat_output.astype(np.int8))
    elif datatype == 'uint16':
        ft_output.putData(dat_output.astype(np.uint16))
    elif datatype == 'int16':
        ft_output.putData(dat_output.astype(np.int16))
github nion-software / nionswift / nion / swift / model / Processing.py View on Github external
def process(self, *, src: DataItem.DataSource, **kwargs) -> typing.Union[DataAndMetadata.DataAndMetadata, DataAndMetadata.ScalarAndMetadata]:
        sigma = kwargs.get("sigma", 1.0)
        if src.xdata.datum_dimension_count == 1:
            w = src.xdata.datum_dimension_shape[0]
            return src.xdata * scipy.signal.gaussian(src.xdata.datum_dimension_shape[0], std=w/2)
        elif src.xdata.datum_dimension_count == 2:
            # uses circularly rotated approach of generating 2D filter from 1D
            h, w = src.xdata.datum_dimension_shape
            y, x = numpy.meshgrid(numpy.linspace(-h / 2, h / 2, h), numpy.linspace(-w / 2, w / 2, w))
            s = 1 / (min(w, h) * sigma)
            r = numpy.sqrt(y * y + x * x) * s
            return src.xdata * numpy.exp(-0.5 * r * r)
        return None
github jianing-sun / Interpolated-Policy-Gradient-with-PPO-for-Robotics-Control- / IPG_for_PPO / log-files / FetchReach-v0 / Apr-22_14:37:52 / main.py View on Github external
def discount(x, gamma):

    """ Calculate discounted forward sum of a sequence at each point """

    return scipy.signal.lfilter([1.0], [1.0, -gamma], x[::-1])[::-1]
github diegoeck / px4tuning / dist / px4tuning-0.1.1 / px4tuning / exemplo_vrft2.py View on Github external
import sysid
from scipy import signal
import matplotlib.pyplot as plt

N=10000

u=np.zeros(N)
u[2]=1
u[202]=1
u[402]=1
u[602]=1
u[802]=1

a0=np.array([1, -1])
b0=np.array([0, 1])
y = signal.lfilter(b0, a0, u) 

# Td
a=0.9
a0=np.array([1, -4*a+2, (2*a-1)*(2*a-1)])
b0=np.array([0, 4*(1-a), -4*(1-a)*a])


r=np.ones(100)
yd = signal.lfilter(b0, a0, r) 

rho=vrft.vrft_pid_mf(u, y, a0,b0,'loco',250)


plt.plot(yd)
github kyochujoho / us-beamform-linarray / linear_array_beamforming.py View on Github external
(2) Demodulation + Low-pass filtering
        - implementable with analog electronics
        - requires knowledge of the carrier frequency, which gets smaller with
          propagation
        - more computational steps involved.

    'demod' and 'demod2' do exactly the same thing here. The former is merely
    the simplest/most intuitive way to look at the operation (multiplying by
    complex exponential yields a frequency shift in the fourier domain).
    Whereas with the latter, the I and Q components are defined, as is typical.
    """
    n = 201
    fs = 1/(t[1]-t[0])
    lc = 0.75e6
    b = signal.firwin(n, lc/(fs/2))  # low-pass filter

    if method == 'hilbert':
        envelope = np.abs(signal.hilbert(scan_line))
    elif method == 'demod':
        demodulated = scan_line*np.exp(-1j*2*np.pi*transmit_freq*t)
        demod_filt = np.sqrt(2)*signal.filtfilt(b, 1, demodulated)
        envelope = np.abs(demod_filt)
    elif method == 'demod2':
        I = scan_line*np.cos(2*np.pi*transmit_freq*t)
        If = np.sqrt(2)*signal.filtfilt(b, 1, I)
        Q = scan_line*np.sin(2*np.pi*transmit_freq*t)
        Qf = np.sqrt(2)*signal.filtfilt(b, 1, Q)
        envelope = np.sqrt(If**2+Qf**2)
    return envelope
github wblgers / py_speech_seg / BIC / voice_activity_detect.py View on Github external
maxsilence = 8
    minlen     = 15
    status     = 0
    count      = 0
    silence    = 0

    x = x/np.absolute(x).max()

    tmp1 = enframe(x[0:(len(x)-1)], framelen, frameshift)
    tmp2 = enframe(x[1:(len(x)-1)], framelen, frameshift)
    signs = (tmp1* tmp2) < 0
    diffs = (tmp1 - tmp2) > 0.05
    zcr = np.sum(signs* diffs, axis=1)

    filter_coeff = np.array([1, -0.9375])
    pre_emphasis = signal.convolve(x,filter_coeff)[0:len(x)]
    amp = np.sum(np.absolute(enframe(pre_emphasis, framelen, frameshift)), axis=1)

    amp_th1 = min(amp_th1, amp.max()/ 3)
    amp_th2 = min(amp_th2, amp.max() / 8)

    x1 = []
    x2 = []
    t = 0

    for n in range(len(zcr)):
        if status == 0 or status == 1:
            if amp[n] > amp_th1:
                x1.append(max(n - count - 1, 1))
                status = 2
                silence = 0
                count = count + 1
github interactiveaudiolab / nussl / nussl / spectral_utils.py View on Github external
Args:
        window_type (basestring): Type of window to create, string can be
        length (int): length of window

    Returns:
        window (np.array): np array with a window of type window_type
    """

    # Generate samples of a normalized window
    if window_type == constants.WINDOW_RECTANGULAR:
        return np.ones(length)
    elif window_type == constants.WINDOW_HANN:
        return scipy.signal.hann(length, False)
    elif window_type == constants.WINDOW_BLACKMAN:
        return scipy.signal.blackman(length, False)
    elif window_type == constants.WINDOW_HAMMING:
        return scipy.signal.hamming(length, False)
    else:
        return None
github mdbartos / pysheds / tools / swmm.py View on Github external
def generate_timeseries(self, **kwargs):
        timeseries = {}
        timelen = 5
        timeseries['name'] = pd.Series(np.repeat('STEP_INPUT', timelen))
        timeseries['date'] = ''
        timeseries['time'] = pd.Series(pd.date_range('20140705', periods=timelen,
                                                     freq='5min').strftime('%H:%M'))
        timeseries['value'] = pd.Series(1.5*scipy.signal.unit_impulse(timelen))
        timeseries = pd.DataFrame.from_dict(timeseries)
        # Manual overrides
        for key, value in kwargs.items():
            timeseries[key] = value
        self.timeseries = timeseries[['name', 'date', 'time', 'value']]
github interactiveaudiolab / nussl / nussl / spectral_utils.py View on Github external
def make_window(window_type, length):
    """Returns an np array of type window_type

    Args:
        window_type (basestring): Type of window to create, string can be
        length (int): length of window

    Returns:
        window (np.array): np array with a window of type window_type
    """

    # Generate samples of a normalized window
    if window_type == constants.WINDOW_RECTANGULAR:
        return np.ones(length)
    elif window_type == constants.WINDOW_HANN:
        return scipy.signal.hann(length, False)
    elif window_type == constants.WINDOW_BLACKMAN:
        return scipy.signal.blackman(length, False)
    elif window_type == constants.WINDOW_HAMMING:
        return scipy.signal.hamming(length, False)
    else:
        return None