Open In App

Create a gauss pulse using scipy.signal.gausspulse

Last Updated : 03 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisites: Scipy

The impulse response of a Gaussian Filter is written as a Gaussian Function as follows: 

g(t) = \frac{1}{\sqrt{2 \pi } \sigma} e^{- \frac{t^2}{2 \sigma^2}}

Its result is also Gaussian. In this article, we will plot the gauss pulse at 3Hz using scipy and matplotlib Python library. Gauss pulse is used in digital filters for motion analysis.  To create a gauss pulse scipy’s gausspulse() method is used. gausspulse() returns a unit-amplitude Gaussian-modulated sinusoidal pulse at the times indicated in array t, with a center frequency ‘fc’ in hertz(Hz).

Syntax: scipy.signal.gausspulse(t, fc retquad, retenv)

Parameter:

  • t: Input array.
  • fc: Center frequency.
  • retquad: If True, return the imaginary as well as the real part of the signal. Default is False.
  • retenv: If True, return the envelope of the signal. Default is False.

Returns

  • yI: The real part of the signal. Always returned.
  • yQ:  Imaginary part of signal. Only returned if retquad is True.
  • yenv:  The envelope of the signal. Only returned if retenv is True.

Approach:

  • Import required module.
  • Create an array of data using np.linespace.
  • Create a gauss pulse at 3 Hz.
  • Label the Graph.
  • Show the resultant Graph.

Implementation using the above approach is depicted below:

Python3

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
  
t = np.linspace(-1, 1, 200)
  
i, q, e = signal.gausspulse(t, fc=3, retquad=True, retenv=True)
  
plt.plot(i, color='green')
plt.plot(q, color='black')
plt.plot(e, '--', color='red')
  
plt.title('Gauss pulse for a 3 Hz - Geeksforgeeks')
plt.ylabel("Normalized magnitude [dB]")
plt.xlabel("Normalized frequency [cycles per sample]")
plt.margins(0, 0.1)
plt.grid(which='both', axis='both')
plt.legend(['Inphase', 'Quadrature', 'Envelope'])
  
plt.show()

                    

Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads