# $n\textrm{ Hz}$ waveform sampled at $m\textrm{ Hz}$ per second

Here is an example of plotting a square wave given in SciPy Documentation

A $5\textrm{ Hz}$ waveform sampled at $500\textrm{ Hz}$ for 1 second:

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)**strong text**


The documentation page states that

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].

1. Why in the example 5*t is multipled by 2*np.pi? Doesn't the signal.sqrt() function take care of multiplying the frequency 5*t by 2*np.pi?
2. What is the meaning of sampled at $500\textrm{ Hz}$ for second? I understand it is a $5\textrm{ Hz}$ waveform since 2*np.pi*5*t takes care of creating $5\textrm{ Hz}$ wave. But I do not understand

sampled at 500 Hz for 1 second

• " Doesn't the signal.sqrt() function take care of multiplying the frequency 5*t by 2*np.pi?" you mean signal.square(), not signal.sqrt() ? – arpit jain Apr 5 '17 at 12:48
• @arpitjain: No, he means actual square wave. – jojek Apr 6 '17 at 11:21

1. The basic square wave function signal.square() has a period of 2*pi. Multiplying each time by 2*pi*f is a way of stretching the wave along the time axis to get a wave with a period of 1/f.
t=np.linspace(0,1,500,endpoint=False)

If you look at the numpy documentation for this function, you'll see this creates a list of 500 evenly spaced numbers between 0 and 1. This is an array of times. When you then call the signal.square() function with this array, it returns an array of points on the square wave for each of those times. Thus you have sampled the square wave at 500Hz for 1 second.