A web app demonstrating how the Fourier series can be used to approximate user-inputted line drawing

Overview

Fourier Series Animation

An interactive React web app that demonstrates how an arbitrary user-inputted line drawing can be approximated using the Fourier series. The concept is modelled through the visualisation of rotating vectors put end-to-end, with the Fourier series being used to determine the magnitude and initial position of each vector.

Inspired by 3Blue1Brown's video explaining and demonstrating the topic

Usage

Try it out directly here: https://jasonfyw.com/fourier-series/

Or clone it onto your own machine

$ git clone https://github.com/jasonfyw/fourier-series

Install the dependencies

$ cd fourier-series
$ npm install

And then start the development server

$ npm start

About the Fourier series

The Fourier series is a branch of Fourier analysis that aims to decompose a periodic function into a sum of exponentials (or trigonometric functions) with different frequencies and magnitudes. This is where the concept of rotating vectors placed end-to-end tracing out a function is derived.

Being able to do this allows for an arbitrary periodic function to be broken up into discrete terms that can then be easily manipulate. As a result, it has a lot of applications in physics such as with signal/image processing, quantum physics, electrical engineering and more.

In this particular demonstration, we are defining $f(t)$ to be a periodic complex function with $t\in[0, 1]$ . The exact data points in the codomain are given by a user-drawn input which are then mapped to the domain.

The essential idea is to represent $f(t)$ as a sum of exponential functions rotating at frequencies of $0, 1, -1, 2, -2, ...$ rotations per $t$ . Each of these exponential functions will be multiplied by a complex coefficient, $c_n$ (where $n$ is the frequency), to determine its initial position and magnitude:

$$ f(t) = \dots + c_{-2}e^{-2\cdot 2\pi it} + c_{-1}e^{-1\cdot 2\pi it} + c_{0}e^{0\cdot 2\pi it} + c_{1}e^{1\cdot 2\pi it} + c_{2}e^{2\cdot 2\pi it} + \dots $$

The term for the vector that doesn't rotate at all is $c_0$ . This can be though of as the 'centre' of the whole function – or the average of all the points in the function. This can be computed by taking the integral of the function across its domain:

$$ \int_0^1 f(t) dt $$

By expanding $f(t)$ in terms of its Fourier series:

$$ \int_0^1 f(t) dt = \int_0^1 (\dots + c_{-1}e^{-1\cdot 2\pi it} + c_{0}e^{0\cdot 2\pi it} + c_{1}e^{1\cdot 2\pi it} + \dots)dt $$

and then distributing the definite integral:

$$ \int_0^1 f(t) dt = \dots + \int_0^1c_{-1}e^{-1\cdot 2\pi it}dt + \int_0^1c_{0}e^{0\cdot 2\pi it}dt + \int_0^1c_{1}e^{1\cdot 2\pi it}dt + \dots $$

Every term except for the one with $c_0$ represents the average of a vector that makes a whole number of rotations, which cancel to zero. Hence,

$$ \int_0^1 f(t) dt = \dots + 0 + c_0 + 0 + \dots = c_0 $$

This yields the value for $c_0$ .

For an arbitrary coefficient $c_n$ , the integral above can be modified by multiplying $f(t)$ by the term $e^{-n2\pi it}$ :

$$ \int_0^1 f(t)e^{-n2\pi it} dt $$

Upon expanding $f(t)$ and distributing the exponential term,

$$ \int_0^1 f(t)e^{-n2\pi it} dt = \int_0^1 (\dots + c_{0}e^{-2\cdot 2\pi it} + c_{1}e^{-1\cdot 2\pi it} + \dots + c_{n}e^{0\cdot 2\pi it} + \dots)dt $$

Now, every term apart from that with $c_n$ is an average over vectors that rotate a whole number of turns, which cancels out to zero. This leaves just the $c_n$ term remianing, resulting in the following generalised expression to find any arbitrary $c_n$ :

$$ c_n = \int_0^1 f(t)e^{-n2\pi it} dt $$

In this implementation, the program performs the computation numerically to find the Fourier series of an inputted function to a certain number of terms. For an exact representation of the original function, there would have to be infinitely many terms.

Using the computed coefficients, the program plots the resulting approximation of the function.

You might also like...

This project is an educational asset demonstrating the use of AWS amplify, Graphql API, Appsync, Material UI and amazon cognito. T

This project is an educational asset demonstrating the use of AWS amplify, Graphql API, Appsync, Material UI and amazon cognito. T

This project is an educational asset demonstrating the use of AWS amplify, Graphql API, Appsync, Material UI and amazon cognito. This project belongs to Black bird and this repo will remain dormant until final decision.

Oct 12, 2022

Open Horizon service container demonstrating Node-RED Object Detection

Open Horizon service container demonstrating Node-RED Object Detection

service-node-red-object-detection Open Horizon service container demonstrating Node-RED Object Detection. This is an Open Horizon configuration to dep

Dec 25, 2022

Movies and series web app developed using NextJS.

Movies and series web app developed using NextJS.

Disney+ Clone Movies and series web app developed using NextJS. Deployed Link : https://disney-clone-ndmiypj8n-suchitd11.vercel.app/ Preview Login Hom

Dec 9, 2022

Movies and series web app developed using NextJS.

Movies and series web app developed using NextJS.

Disney+ Movies and series web app developed using NextJS. Deployed Link : https://disney-clone-ndmiypj8n-suchitd11.vercel.app/ Preview Login Homescree

Jun 28, 2022

AweSome Book App displays the book details entered by user and saves the information in Local storage. User can add and remove a book title/author to the library and from the library.

Awesome Book App with ES6 Used npm init -y command to create package.json file. Created the entry point for the JavaScript code called index.js Create

Aug 15, 2022

JavaScript library to make drawing animation on SVG

JavaScript library to make drawing animation on SVG

vivus.js Demo available on http://maxwellito.github.io/vivus Play with it on Vivus Instant Vivus is a lightweight JavaScript class (with no dependenci

Jan 3, 2023

Drawing Newton's fractal using pure js, rust-wasm, SIMDs, threads and GPU

Drawing Newton's fractal using pure js, rust-wasm, SIMDs, threads and GPU

Newton's fractal Runtime Newton's fractal renderer. Click to open in your browser Inspired by 3blue1brown's video about Newton's fractal. Drawing

Nov 17, 2022

Cross provider map drawing library, supporting Mapbox, Google Maps and Leaflet out the box

Terra Draw Frictionless map drawing across mapping providers. TerraDraw centralises map drawing logic and provides a host of out the box drawing modes

Dec 31, 2022
Comments
  • Add image upload and tracing feature

    Add image upload and tracing feature

    Users can upload an image. Edge detection is then applied to extract edges detected within the image, which is then fed to the Fourier series to approximate

    opened by jasonfyw 0
Releases(v1.1.0)
  • v1.1.0(Sep 13, 2022)

  • v1.0.0(Jun 19, 2022)

    Features:

    • Drawing. The user can input a function using their cursor/finger
    • Animating. The Fourier series is calculated (to a finite number of terms) and animated using the notion of rotating vectors placed end-to-end
    • Resetting. The canvas can be cleared either when drawing or animating
    • Customisability. A number of parameters can be adjusted on the fly, such as the number of terms of the Fourier series being used, as well as allowing the toggling of the rendering of different elements
    • UI elements. A drawer hides the settings and other details about the app.
    • Dark/light mode. Allows for the app to look according to the user's preference
    Source code(tar.gz)
    Source code(zip)
Owner
Jason Wang
CS @ UofT '25 – Python + web dev with React
Jason Wang
no-comma is a javascript library for dealing with inputted numbers that include commas

no-comma no-comma is a javascript library for dealing with inputted numbers that include commas. Nocomma will allow you to check if the number contain

Fatty 3 Jan 27, 2022
Kyrillos Hany 14 Aug 10, 2022
this is a single-page web application. we built a book website where the user can add , remove and display books. we used modules to implement these functionalities. also, we used the Date class to display the date and time.

Awsome Books In this Project, we have built A Books websites. Built With ?? HTML CSS javascript Git & Github Live Demo Here you can find the live Demo

Nedjwa Bouraiou 10 Aug 3, 2022
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
A Minimalist to do list website where user can add, remove and edit multiple tasks and All the changes user makes in his to do list is saved in browser local storage so that it can be accessed later.

Testing for Add Remove function in To Do List App Jest framework is used for testing. Created (addremove.test.js) for a file containing the add item a

Krishna Prasad Acharya 8 Aug 15, 2022
A repository demonstrating functional techniques with C# 10 and the similarities between JavaScript, TypeScript, and C#.

Building up from JavaScript to TypeScript to C# 10 and .NET 6 This repository is meant to highlight some of the various functional techniques availabl

Charles Chen 67 Dec 30, 2022
Node.js TypeScript project demonstrating a Prisma integration with PostgreSQL

Prisma with PostgreSQL, TypeScript, Serverless and Parameter Store This project is the outcome of following the Prisma Getting Started guide. In addit

Christian Rich 10 Aug 28, 2022
Demonstrating the Dashboard++ method of organizing a vault in Obsidian

Information This repository is an Obsidian vault that demonstrates using the Dashboard++ method for organizing and navigating notes. For further detai

null 194 Jan 3, 2023