Unity Fourier Series Visualization

Contra
2019-11-03
Unity Fourier Series Visualization

The [Coding Druid] series is my cross-platform programming practice notes. Each episode focuses on a theme (math, physics, electronics, graphics, sound...), implemented in several programming languages. Leveling up warrior, mage, healer, and rogue simultaneously — tanking, DPSing, healing, and escaping all at once.


Coding Druid - Math Chapter - Fourier Series Visualization: Unity Implementation

fs-unity


The previous chapter covered trigonometric function visualization, implemented in MaxMSP, JavaScript (React), Python, and Unity:

sine-unity-croped

This chapter revisits the terror once dominated by Fourier. When discussing Fourier transform/Fourier analysis, it's usually divided into two parts: Fourier Series and Continuous Fourier Transform. This chapter focuses on Fourier Series.

Math Basics

In mathematics, a Fourier series can be seen as a periodic function composed of a set of sinusoidal curves, combined through weighted summation. (Wikipedia)

For example, a periodic square wave can be decomposed into multiple sine waves. The more sine waves, the closer the composite curve approximates a square wave:

Fourier_series_and_transform

For more detailed explanations and formula derivations, see the previous section: JavaScript (React) Fourier Series Visualization.

Previous section's result:

fs-js-5


This section uses Unity.

I previously wrote a Unity Trigonometric Function Visualization. Building on that code, just change the drawing formula from trigonometric functions to the Fourier series formula:

code

Full code available below.

Final result:

fs-unity


References


Talk is cheap. Show me the code!

The code for this and most of the [Coding Druid] series is open-sourced here: https://github.com/avantcontra/coding-druid


Follow us on social media: code2art

Community resources & courses: https://ghc.h5.xeknow.com/s/hzkMX

code2art Intelligence Center (membership): https://ghc.h5.xeknow.com/s/2BCFuJ

Cheers🍻

Contra