Skip to Content
Elegant SciPy
book

Elegant SciPy

by Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
August 2017
Intermediate to advanced
280 pages
6h 19m
English
O'Reilly Media, Inc.
Content preview from Elegant SciPy

Chapter 4. Frequency and the Fast Fourier Transform

If you want to find the secrets of the universe, think in terms of energy, frequency and vibration.

Nikola Tesla

This chapter was written in collaboration with SW’s father, PW van der Walt.

This chapter will depart slightly from the format of the rest of the book. In particular, you may find the code in the chapter quite modest. Instead, we want to illustrate an elegant algorithm, the Fast Fourier Transform (FFT), that is endlessly useful, is implemented in SciPy, and works, of course, on NumPy arrays.

Introducing Frequency

We’ll start by setting up some plotting styles and importing the usual suspects:

# Make plots appear inline, set custom plotting style
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('style/elegant.mplstyle')
import numpy as np

The discrete1 Fourier transform (DFT) is a mathematical technique used to convert temporal or spatial data into frequency domain data. Frequency is a familiar concept, due to its colloquial occurrence in the English language: the lowest notes your headphones can rumble out are around 20 Hz, whereas middle C on a piano lies around 261.6 Hz; Hertz, or oscillations per second, in this case literally refers to the number of times per second at which the membrane inside the headphone moves to-and-fro. That, in turn, creates compressed pulses of air which, upon arrival at your eardrum, induces a vibration at the same frequency. So, if you take a simple periodic function, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SciPy Recipes

SciPy Recipes

Luiz Felipe Martins, Ke Wu, Ruben Oliva Ramos, V Kishore Ayyadevara
Scientific Computing with Python 3

Scientific Computing with Python 3

Claus Führer, Claus Fuhrer, Jan Erik Solem, Olivier Verdier
Mastering SciPy

Mastering SciPy

Francisco Javier Blanco-Silva, Francisco Javier B Silva

Publisher Resources

ISBN: 9781491922927Errata PageSupplemental Content