In this section, we are going to use NumPy functions to simulate several signal functions and translate them to Fourier transforms. We will focus on using numpy.fft
and its related functions. We hope after this section that you will get some sense of using a Fourier transformation in NumPy. The theory part will be covered in the next section.
The first example we are going to use is our heartbeat signal, which is a series of sine waves. The frequency is 60 beats per minutes (1 Hz), and our sampling period is 5 seconds long, with a sampling interval of 0.005 seconds. Let's create the sine wave first:
In [1]: time = np.arange(0, 5, .005) In [2]: x = np.sin(2 * np.pi * 1 * time) In [3]: y = np.fft.fft(x) In [4]: show(x, y)
In this example, we first created the sampling time interval and saved it to anndarray
called time
. And we passed the time
array times 2π and its frequency 1 Hz to the numpy.sin()
method to create the sine wave (x
). Then applied the...