Plotting A Square Wave Using Matplotlib, Numpy And Scipy
A square wave is a non-sinusoidal periodic waveform in which the amplitude alternates at a steady frequency between the fixed minimum and maximum values, with the same duration at minimum and maximum. Graphical representations are always easy to understand and are adopted and preferable before any written or verbal communication. In this article, we will try to understand, How can we plot Square waves using the Scipy python module.
- Import required module.
- Create a sample rate.
- Plot a square wave.
- Label the graph.
- Display Graph.
Step 1: Import module
Step 2: The NumPy linspace function is a tool in Python for creating numeric sequences that return evenly spaced numbers over a specified interval.
Step 3: plot.plot function: This method accepts the following parameters and Plot the square wave signal.
- t: The input time array.
Output array containing the square waveform.
Step 4: Give title name, x-axis label name, y-axis label name.
Step 5: plot.axhline() : The axhline() function in pyplot module of matplotlib library is used to add a horizontal line across the axis.
Below is the full implementation: