This is the 2nd part of the article on a few applications of Fourier Series in solving differential equations. All the problems are taken from the edx Course: MITx – 18.03Fx: Differential Equations Fourier Series and Partial Differential Equations. The article will be posted in two parts (two separate blongs)
We shall see how to solve the following ODEs / PDEs using Fourier series:
- Solve the PDE for Heat / Diffusion using Neumann / Dirichlet boundary conditions
- Solve Wave equation (PDE).
- Remove noise from an audio file with Fourier transform.
Heat / Diffusion Equation
The following animation shows how the temperature changes on the bar with time (considering only the first 100 terms for the Fourier series for the square wave).
Let’s solve the below diffusion PDE with the given Neumann BCs.
As can be seen from above, the initial condition can be represented as a 2-periodic triangle wave function (using even periodic extension), i.e.,
The next animation shows how the different points on the tube arrive at the steady-state solution over time.
The next figure shows the time taken for each point inside the tube, to approach within 1% the steady-state solution.
with the following
- L=5, the length of the bar is 5 units.
- Dirichlet BCs: u(0, t) =0, u(L,t) = sin(2πt/L), i.e., the left end of the bar is held at a constant temperature 0 degree (at ice bath) and the right end changes temperature in a sinusoidal manner.
- IC: u(x,0) = 0, i.e., the entire bar has temperature 0 degree.
The following R code implements the numerical method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
The tri-diagonal matrix A is shown in the following figure
1 2 3 4 5 6 7 8 9 10 11 |
|
The following animation shows the solution obtained to the heat equation using the numerical method (in R) described above,
The next figure shows how can a numerical method be used to solve the wave PDE
Implementation in R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Now iteratively compute u(x,t) by imposing the following boundary conditions
1. u(0,t) = 0
2. u(L,t) = (1/10).sin(t/10)
along with the following initial conditions
1. u(x,0) = exp(-500.(x-1/2)2)
2. ∂u(x,0)/∂t = 0.x
as defined in the above code snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
The following animation shows the output of the above implementation of the solution of wave PDE using R, it shows how the waves propagate, given a set of BCs and ICs.
Some audio processing: De-noising an audio file with Fourier Transform
Let’s denoise an input noisy audio file (part of the theme music from Satyajit Ray’s famous movie পথের পাঁচালী, Songs of the road) using python scipy.fftpack module’s fft() implementation.
The noisy input file was generated and uploaded here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Fs, y = wavfile.read( 'pather_panchali_noisy.wav' )
|
You will obtain a figure like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|

Credit: Data Science Central By: Sandipan Dey