Part One - A point on a rotating wheel | Fourier Transform use cases in AI
· 6 min read
Maths, Spectral Analysis
What do sound, light, and images have in common? They can all be studied using the language of frequencies. A sound recording, an image, or even a signal from a sensor can look complicated at first glance.
It turns out that we can understand these signals as a combination of much simpler waves, each with its own frequency, amplitude, and phase.
This is the central idea behind the Fourier Transform — looking at a signal from the perspective of its frequencies.
But before we can understand how this works, we need to build an intuition for the waves themselves. So, let's start with something surprisingly simple — a point rotating on a wheel. We'll see how its motion gives rise to sine and cosine waves, and how we can describe its journey through time using mathematics.
The goal of this guide is to picturize how a point on a rotating wheel moves through time, and write its evolution in a mathematical form.
Before we do so, let us make sure we agree on what is meant by three things:
- frequency $f$
- how do we measure angles.
- What is meant by $cos(\theta)$ and $sin(\theta)$ for us.
The frequency $f$ is a measure to count how often something repeats. For e.g. —
- A clock's second hand returns to 12 after every 1 minute.
- Your heart repeats once a second.
Now let's see how do we measure angles. We will measure angles in radians. A radian is defined as the length of the circumference travelled on a unit circle. Thus an angle of 360 degrees means the circumference ($2\pi r$) is $2\pi$ ($r = 1$ for a unit circle). Likewise the angle of 180 degrees means $\pi$ radians and so on.
$$ 2\pi \text{ radians} = 360 \text{ degrees} $$ We can represent any such angle in radians using the above relationship.
And finally once we know the angle of the point on a unit circle, we can query about its x-coordinate and the y-coordinate values. For unit circle these values are $cos(\theta)$ and $sin(\theta)$ respectively. (Assuming $\theta$ is considered counterclockwise)
Couple of facts directly follow from the above figure.
- $cos^2(\theta) + sin^2(\theta) = 1$: follows from the pythagoras' principle.
- Both values repeat every $2\pi$: Thus $cos(\theta + 2\pi) = cos(\theta)$ and likewise for $sin$. It means a full turn around the circle lands you on the same spot horizontally and vertically.
- When we measure $\theta$ clockwise, we get the following observations: $cos(-\theta) = cos(\theta)$ and $sin(-\theta) = -sin(\theta)$. Confirm this from the image.
Tracking the journey of a point on the rotating wheel
Let us first look at an easy case. Consider a unit wheel (circle). The wheel's center is currently at $(0,0)$ and our point of interest that we want to track is at $(1,0)$.
Now let's assume the wheel starts rotating counterclockwise. Emphasize the word — "rotate". Keep in the mind it is just fixed at a center ($(0,0)$ in this case) and rotating and not rolling. The wheel is completing $f$ turns in $1$ second. We thus say the wheel has the frequency $f$. After time $t$, the wheel completes $ft$ turns. $$ 1 \text{ sec} \to f \text{ turns} \ t \text{ secs} \to ? $$ Thus after $t$ secs, the wheel completes $ft$ turns. Now our point will be at angle $2\pi ft$ radians. Let's see how: $$ 1\text{ turn}=360^\circ=2\pi\text{ radians} \ \therefore \underbrace{ft}{\text{turns}} \times \underbrace{2\pi}{\text{radians/turn}} =\boxed{2\pi ft\text{ radians}} $$
Thus our point of interest is at $2\pi ft$ radians. We can then calculate its x-coordinate and y-coordinate. Thus: $$ x(t) = cos(2\pi ft) \ y(t) = sin(2\pi ft) $$
Okay if you understood so far, then we can extend to the following generic case: $$ \boxed{ \begin{aligned} x(t) &= A\cos(2\pi ft+\varphi)+c_x\ y(t) &= A\sin(2\pi ft+\varphi)+c_y \end{aligned} } $$
Here we have four knobs that we can control:
| Knob on the wheel | Name | Symbol | Effect/Meaning |
|---|---|---|---|
| Radius of the wheel | Amplitude | $A$ | Tells how high the point goes: (peaks at $+A$ and troughs at $-A$). |
| Turns per second | Frequency | $f$ | Counts how many peaks per second. |
| Where the point(dot) starts | Phase | $\varphi$ | Slides the whole wave left/right |
| Height of the wheel's axle | Offset ("DC") | $c_y$ | Lifts the whole wave up or down (Non oscillating part). $c_x$ has similar role when the axle is shifted left/right. |
Concisely, $x(t)$ and $y(t)$ tells where is the point currently on the wheel. The phase $\varphi$ tells the initial position of the point.
When we apply some initial phase, the wave $x(t)$ will become a shifted version of the zero-phase wave. If we measure the phase counterclockwise ($+ ve$ phase), then the whole wave is shifted left.
Thus starting with a point with a phase $\varphi$, shifts the whole wave left by $\varphi$. i.e. — whatever value(amplitude) of the wave was going to happen in the normal case, occurred $\varphi$ radians back.
$c_x$ and $c_y$ represents the wheel's fixed center. If the wheel is physically rolling through time, its center translates too, and then the trajectory of the point on its circumference is generally a cycloid, not a circle. So, that's why I have written "rotating wheel" and not "rolling wheel". We can go on a side quest in some other guide to look for the equations for rolling wheel as well. But currently let's assume rotating wheel.
We will understand one last thing in this guide. And that is $\omega = 2\pi f$ — the angular frequency. The idea is if $f$ tells you about many revolutions are happening per second, then $\omega$ tells you how many radians are swept per second. This is the way I like to imagine it. It gives us the sense of speed or precisely the rate of change of the angle (of the point) w.r.t time.
If we denote the angle of the point $\theta$ as a function of time $\theta(t)$, then $\theta(t) = 2\pi ft$. If we do so, then: $$ \omega=\frac{d\theta}{dt}=2\pi f \text{ rads/s} $$
$\omega$ is the rate of change of angle per second. Thus after each second the angle changes by $2 \pi f$.
In this guide I wanted to give the feel of what the formula $x(t) = \text{A }cos(2\pi ft + \varphi) + c_x$ means in the first place intuitively. Here we understood this formula from the means of a point rotating on a wheel. But the key-takeaway is the formula itself. It is nothing but a sinusoid (cosine waves are just sine waves shifted by a phase of 90 degrees). We will see a lot more of these waves in the coming guides. But before we do so, we need to form a notion of discrete waves — which are sampled from a continuous signal to enable the computer to read them. It will change the above formula a little and we will understand it in the next guide. See you there! :)
Comments (1)
Neil (author) ·
I am planning to write a long series of guides on Fourier Transform and its use cases in AI. This is the first step towards it. I don't know how many guides I will write. But I have definitely planned a lot of them. Hope you like these guides and intuitions.