Friday, February 26, 2021
  • Setup menu at Appearance » Menus and assign menu to Top Bar Navigation
Advertisement
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News
No Result
View All Result
NikolaNews
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News
No Result
View All Result
NikolaNews
No Result
View All Result
Home Data Science

Fourier Series and Differential Equations with some applications in R and Python (Part 2)

July 10, 2020
in Data Science
Fourier Series and Differential Equations with some applications in R and Python (Part 2)
592
SHARES
3.3k
VIEWS
Share on FacebookShare on Twitter

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:

You might also like

How Machine Learning Discretely Assists Data Scientists

A Plethora of Machine Learning Articles: Part 1

AI Chatbot Platforms: The Best in the Market and Why to Consider

  1. Solve the PDE for Heat / Diffusion using Neumann / Dirichlet boundary conditions
  2. Solve Wave equation (PDE).
  3. Remove noise from an audio file with Fourier transform.

Heat / Diffusion Equation

f17

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).

heat3

Let’s solve the below diffusion PDE with the given Neumann BCs.

f12

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.,

f13

The next animation shows how the different points on the tube arrive at the steady-state solution over time.

 

heat

The next figure shows the time taken for each point inside the tube, to approach within 1% the steady-state solution.

steady

 

f14

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

 

x = seq(0,5,5/19)

dt = 0.06        

tMax = 20        

nu = 0.5         

 

t = seq(0, tMax, dt)

 

n = length(x)

m = length(t)

 

fLeft = function(t) 0                            

fRight = function(t) sin(2*pi*t/5)               

fInitial = function(x) matrix(rep(0,m*n), nrow=m)

 

dx = x[2]-x[1]

r = nu*dt/dx^2

 

The tri-diagonal matrix A is shown in the following figure

tridiag2

 

1

2

3

4

5

6

7

8

9

10

11

u = fInitial(x)

u[1,1] = fLeft(0)

u[1,n] = fRight(0)

 

for (i in 1:(length(t)-1)) {

 

   u[i+1,] = A%*%(u[i,])  

   u[i+1,1] = fLeft(t[i]) 

   u[i+1,n] = fRight(t[i])

}

The following animation shows the solution obtained to the heat equation using the numerical method (in R) described above,

heat2

 

f18f19

The next figure shows how can a numerical method be used to solve the wave PDE

f20

Implementation in R

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

x = seq(0,1,1/99)

dt = 0.5

tMax = 200

c = 0.015

 

fLeft = function(t) 0

fRight = function(t) 0.1*sin(t/10)

fPosInitial = function(x) exp(-200*(x-0.5)^2)

fVelInitial = function(x) 0*x

 

dx = x[2]-x[1]

r = c*dt/dx

 

n = length(x)

t = seq(0,tMax,dt) 

m =length(t) + 1

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

 

u = matrix(rep(0, n*m), nrow=m)

u[1,] = fPosInitial(x)

u[1,1] = fLeft(0)

u[1,n] = fRight(0)

 

for (i in 1:length(t)) {

 

  

  if (i == 1) {

     u[2,] = 1/2*(A%*%u[1,]) + dt*fVelInitial(x)

  } else {

     u[i+1,] = (A%*%u[i,])-u[i-1,]

  }

 

  u[i+1,1] = fLeft(t[i])

  u[i+1,n] = fRight(t[i])

}

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.

wave

 

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

from scipy.io import wavfile

import scipy.fftpack as fp

import numpy as np

import matplotlib.pylab as plt

 

Fs, y = wavfile.read('pather_panchali_noisy.wav')

 

Y = fp.fftshift(fp.fft(y)) 

fshift = np.arange(-n//2, n//2)*(Fs/n)

 

plt.plot(fshift, Y.real)

plt.show()

You will obtain a figure like the following:
f22

1

2

3

4

5

6

7

8

9

10

11

12

13

L = len(fshift)

Yfilt = Y

 

print(np.argsort(Y.real)[::-1][:2])

 

Yfilt[495296] = Yfilt[639296] = 0 

plt.plot(fshift, Yfilt.real)

plt.show()

 

soundFiltered = fp.ifft(fp.ifftshift(Yfilt)).real

wavfile.write('pather_panchali_denoised.wav', Fs, soundNoisy)

f23
The denoised output wave file produced with the filtering can be found here. (use vlc media player to listen to input and output wave files)


Credit:
Data Science Central By: Sandipan Dey

Previous Post

Aspiring Toward Provably Beneficial AI Including The Case Of Autonomous Cars

Next Post

Backdoor accounts discovered in 29 FTTH devices from Chinese vendor C-Data

Related Posts

How Machine Learning Discretely Assists Data Scientists
Data Science

How Machine Learning Discretely Assists Data Scientists

February 24, 2021
A Plethora of Machine Learning Articles: Part 1
Data Science

A Plethora of Machine Learning Articles: Part 1

February 24, 2021
What are Data Pipelines ?
Data Science

AI Chatbot Platforms: The Best in the Market and Why to Consider

February 24, 2021
Modernizing Data Dashboards. – Data Science Central
Data Science

Modernizing Data Dashboards. – Data Science Central

February 24, 2021
4 ways Cryptocurrency is Benefiting the Fintech Industry
Data Science

4 ways Cryptocurrency is Benefiting the Fintech Industry

February 23, 2021
Next Post
Backdoor accounts discovered in 29 FTTH devices from Chinese vendor C-Data

Backdoor accounts discovered in 29 FTTH devices from Chinese vendor C-Data

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Plasticity in Deep Learning: Dynamic Adaptations for AI Self-Driving Cars

Plasticity in Deep Learning: Dynamic Adaptations for AI Self-Driving Cars

January 6, 2019
Microsoft, Google Use Artificial Intelligence to Fight Hackers

Microsoft, Google Use Artificial Intelligence to Fight Hackers

January 6, 2019

Categories

  • Artificial Intelligence
  • Big Data
  • Blockchain
  • Crypto News
  • Data Science
  • Digital Marketing
  • Internet Privacy
  • Internet Security
  • Learn to Code
  • Machine Learning
  • Marketing Technology
  • Neural Networks
  • Technology Companies

Don't miss it

Basic laws of physics spruce up machine learning
Machine Learning

New machine learning tool facilitates analysis of health information, clinical forecasting

February 26, 2021
Creative Destruction and Godlike Technology in the 21st Century | by Madhav Kunal
Neural Networks

Creative Destruction and Godlike Technology in the 21st Century | by Madhav Kunal

February 26, 2021
Spy agency: Artificial intelligence is already a vital part of our missions
Internet Security

Spy agency: Artificial intelligence is already a vital part of our missions

February 26, 2021
Blockchain lags behind other technologies in finance adoption for now, says Broadridge
Blockchain

Blockchain lags behind other technologies in finance adoption for now, says Broadridge

February 26, 2021
Supercomputer-Powered Machine Learning Supports Fusion Energy Reactor Design
Machine Learning

Supercomputer-Powered Machine Learning Supports Fusion Energy Reactor Design

February 26, 2021
How 3D Cuboid Annotation Service is better than free Tool? | by ANOLYTICS
Neural Networks

How 3D Cuboid Annotation Service is better than free Tool? | by ANOLYTICS

February 26, 2021
NikolaNews

NikolaNews.com is an online News Portal which aims to share news about blockchain, AI, Big Data, and Data Privacy and more!

What’s New Here?

  • New machine learning tool facilitates analysis of health information, clinical forecasting February 26, 2021
  • Creative Destruction and Godlike Technology in the 21st Century | by Madhav Kunal February 26, 2021
  • Spy agency: Artificial intelligence is already a vital part of our missions February 26, 2021
  • Blockchain lags behind other technologies in finance adoption for now, says Broadridge February 26, 2021

Subscribe to get more!

© 2019 NikolaNews.com - Global Tech Updates

No Result
View All Result
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News

© 2019 NikolaNews.com - Global Tech Updates