Fourier Analysis

In Fourier analysis general functions are represented or approximated by sums of simpler trigonometric functions.

These functions are named after Joseph Fourier (1768-1830) who applied them to areas such as:

  • heat flow such as conduction (energy transfer between objects in physical contact) and convection (energy transfer between objects and their environment)

  • dimensional analysis of relationships between physical quantities by identifying their base quantities (e.g., length, mass time) and units of measure

A Fourier transform:

  • finds the trigonometric functions to fit the target function/form

  • converts a signal from time to frequency domain

Use of Fourier analysis and transforms in Machine Learning include:

Python Example

To download the code below, click here.

"""
fourier_transform_using_numpy.py
computes the one-dimensional n-point discrete fourier transform
"""

# Import needed libraries.
import numpy as np
import matplotlib.pyplot as plotlib

# Set parameters.
number_of_interval_values = 32

# Arrange evenly spaced values within a given range.
intervals = np.arange(number_of_interval_values)
print("Intervals:")
print(intervals)

# Use the interval numbers as angles in radians for input to creating sines.
sines = np.sin(intervals)
print("Sines:")
print(sines)

# Compute frequencies in cycles per unit of spacing.
frequencies = np.fft.fftfreq(intervals.shape[-1])
print("Frequencies:")
print(frequencies)

# Compute a one-dimensional n-point discrete Fourier Transform.
transform = np.fft.fft(sines)
print("Transform:")
print(transform)

# Plot the transform.
plotlib.xlabel('frequencies')
plotlib.ylabel('transform values')
plotlib.plot(frequencies, transform.real)
plotlib.show()
The output is shown below:

Intervals:
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 24 25 26 27 28 29 30 31]
Sines:
[ 0.          0.84147098  0.90929743  0.14112001 -0.7568025  -0.95892427
 -0.2794155   0.6569866   0.98935825  0.41211849 -0.54402111 -0.99999021
 -0.53657292  0.42016704  0.99060736  0.65028784 -0.28790332 -0.96139749
 -0.75098725  0.14987721  0.91294525  0.83665564 -0.00885131 -0.8462204
 -0.90557836 -0.13235175  0.76255845  0.95637593  0.27090579 -0.66363388
 -0.98803162 -0.40403765]
Frequencies:
[ 0.       0.03125  0.0625   0.09375  0.125    0.15625  0.1875   0.21875
  0.25     0.28125  0.3125   0.34375  0.375    0.40625  0.4375   0.46875
 -0.5     -0.46875 -0.4375  -0.40625 -0.375   -0.34375 -0.3125  -0.28125
 -0.25    -0.21875 -0.1875  -0.15625 -0.125   -0.09375 -0.0625  -0.03125]
Transform:
[-0.12398729 +0.j         -0.11736871 -0.1221137j
 -0.09387743 -0.27507089j -0.03616682 -0.52608284j
  0.14242961 -1.16878622j  4.29256337-15.01495666j
 -0.71822454 +1.61608763j -0.47775765 +0.78333198j
 -0.40480425 +0.51029458j -0.37055807 +0.36771593j
 -0.35128126 +0.27598033j -0.33935953 +0.20919154j
 -0.33162773 +0.15629097j -0.32655861 +0.11166443j
 -0.32334958 +0.07206136j -0.32156745 +0.0353622j
 -0.32099544 +0.j         -0.32156745 -0.0353622j
 -0.32334958 -0.07206136j -0.32655861 -0.11166443j
 -0.33162773 -0.15629097j -0.33935953 -0.20919154j
 -0.35128126 -0.27598033j -0.37055807 -0.36771593j
 -0.40480425 -0.51029458j -0.47775765 -0.78333198j
 -0.71822454 -1.61608763j  4.29256337+15.01495666j
  0.14242961 +1.16878622j -0.03616682 +0.52608284j
 -0.09387743 +0.27507089j -0.11736871 +0.1221137j ]