MathLab Computational Tools Problem Set 3 Solution PDF
MathLab Computational Tools Problem Set 3 Solution PDF
Solutions
Mathematics Club IITM
Navin, KK, Achintya
June 2024
• The solutions to the problems in Problem Set 3 can be found in this solution sheet.
• Feel free to reach out to us for doubts! Contact information of the problem-set creators:
– Achintya Raghavan - +91 96068 52240
– Karthik Kashyap - +91 80739 78167
– Navin Kumar - +91 90287 70420
1. ex and a constant were walking down the street one day. While ex continued walking, oh dear
had the constant run away. What operator in the path would cause the constant much dismay?
Find the solutions y(x) to the following differential equations given the boundary conditions:
d2 y dy
a) 2 +5 − 3y = 0
dx2 dx
[ y(2) = e−2 + e12 and y(16) = e−30 + e5 ]
Solution:
d2 esx desx
2 2
+5 − 3esx = 0
dx dx
=⇒ (2s2 + 5s − 3)esx = 0
=⇒ (2s − 1)(s + 3) = 0
1
=⇒ s = , −3
2
1
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
=⇒ y = Ae 2 x + Be−3x
1
A = e−3 , B = e18
=⇒ y = e 2 x−3 + e−3x+18
1
∴ y(6) = 2
d2 y dy √ ix
b) 2 + 5 − 3y = 15 2e
dx2 dx
[ Assume only the forced part of the solution as discussed in the presentation i.e. system
is at rest in the beginning ]
Final Expected Answer: The magnitude of the solution (Since the solution will be
complex)
Solution:
√
Since we already have an exponential driving force f (x) = 15 2eix , we assume the
solution is of the form Aeix .
d2 Aeix dAeix √
=⇒ 2 2
+ 5 − 3Aeix = 15 2eix
dx dx
√
=⇒ Aeix (2(i)2 + 5i − 3) = 15 2eix
√
=⇒ A(−5 + 5i) = 15 2
√
15 2
=⇒ A =
−5 + 5i
√
3 2
=⇒ A =
i−1
√
3 2
∴ |A| = √ = 3
2
∞
d2 y dy √
c)
kix
X
2
− 2 − 5y = 25 13k 2 e 2
dx dx
k=−∞
[ Assume only the forced part of the solution as discussed in the presentation i.e. system
is at rest in the beginning ]
Final Expected Answer: The magnitude of the coefficient of the k = 2 term in the
solution series.
Solution:
Applying the usual method of solving a LCCDE with the driving force f (x) being a
2
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
∞
Fourier series, we assume the solution is of the form .
kix
X
Ak e 2
k=−∞
∞ ∞ ∞ ∞
d2 X d X √
=⇒
kix kix kix kix
X X
2
A k e 2 − 2 A k e 2 − 5 A k e 2 = 25 13k 2 e 2
dx dx
k=−∞ k=−∞ k=−∞ k=−∞
∞ ∞
kix kix
!
d2 e 2 de 2 √
=⇒
kix kix
X X
Ak 2
−2 − 5e 2 = 25 13k 2 e 2
dx dx
k=−∞ k=−∞
∞ ∞
2 !
√
ki ki
=⇒
kix kix
X X
Ak +2 +5 e 2 = 25 13k 2 e 2
2 2
k=−∞ k=−∞
∞ ∞
k2 √
ki
=⇒
kix kix
X X
−Ak +5+2 e 2 = 25 13k 2 e 2
4 2
k=−∞ k=−∞
Using the fact that exponentials of different frequencies are linearly independent,
we equate coefficients to get:
k2 √
ki
− Ak +5+2 = 25 13k 2
4 2
√
−25 13 k 2
=⇒ Ak = k2 ki
4 +5+2 2
√
−100 13
∴ A2 =
6 + 2i
√
50 13
=⇒ |A2 | = √
10
2. Why did the function f go see a Fourier therapist? Because it wanted to break down its complex
personality into a series of sines and cosines!
Consider the function:
f (x) = x, −π ≤ x < π
Here f has a period of 2π, that is f (x + 2π) = f (x). Find the Fourier series corresponding to
f (x).
Final Expected Answer: If the coefficients of the series are an , bn , then find the value of
a2 + b2 .
3
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Solution:
We make an observation that the function f (x) = x is an odd function. Thus, by applying
the properties of Fourier series, we find that the Fourier Series corresponding to this
function is a sine series and conclude that:
an = 0 ∀ n
Z π
1
To find bn , we can use: bn = f (x) sin(nx) dx
π −π
Z π
1
=⇒ bn = x sin(nx) dx
π −π
x cos(nx)
π !
Z π
1 1
=⇒ bn = − + cos(nx) dx
π n −π n −π
2
bn = − cos(nπ)
n
∴ a2 = 0 & b2 = −1
4
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Achintya remembers learning about an interesting function called the ramp function r(t) in his
signal processing class. He remembers his teacher defining it as:
t t≥0
r(t) =
0 otherwise
On his class quiz, he comes across this differential equation when he attempts to model an old,
rusty and stiff spring that is being slowly but steadily pulled by an insanely strong ant. However
since he missed half of his math classes, he has no idea how to solve it. Can you help him?
d3 x d2 x dx
5 + 3 +6 + 2x = rp (t)
dt3 dt2 dt
Assume rp (t) = r(t) when −π < t ≤ π and is periodic with time period 2π. Also solve for only the
particular solution (this is what we discussed in the session).
Final Expected Answer: The solution to the differential equation given above using Fourier
series methods.
Solution:
We begin by decomposing the given periodic ramp function into a trigonometric Fourier series.
2π 2π
ω= = =1
t 2π
Thus,
Zπ Zπ
1 1 π
a0 = rp (t)dt = tdt =
π π 2
−π 0
5
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Zπ Zπ k
!
1 1 1 (−1) − 1
ak = rp (t) cos(kt)dt = t cos(kt)dt =
π π π k2
−π 0
Zπ Zπ k+1
1 1 (−1)
bk = rp (t) sin(kt)dt = t sin(kt)dt =
π π k
−π 0
∞ ∞
a0 X
ak cos(kt) + bk sin(kt)
X
∴ rp (t) = +
2
k=1 k=1
∞ ∞
!
k k+1
π 1 (−1) − 1 (−1)
=⇒ rp (t) = cos(kt) + sin(kt)
X X
+
4 π k2 k
k=1 k=1
∞
X
∴ rp (t) = A0 + Ak eikt
k=−∞
k6=0
∞
!
k k
π 1 iπ (−1) (−1) − 1
=⇒ rp (t) = +
X
+ eikt
4 2π k k2
k=−∞
k6=0
The differential equation now reduces to the standard LCCDE with an driving force in the
form of a Fourier Series.
∞
d3 x d2 x dx X
+ 3 + 6 + 2x = Ak eikt
dt3 dt2 dt
k=−∞
∞
As usual, we assume the solution is some series Bk eikt . Substituting in the above
X
k=−∞
differential equation and solving, we get:
∞
X ∞
X
3 2
5 (ik) + 3 (ik) + 6ik + 2 Bk eikt = Ak eikt
k=−∞ k=−∞
6
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Ak
=⇒ Bk =
−5ik 3 − 3k 2 + 6ik + 2
!
k k
1 jπ (−1) (−1) − 1
k 6= 0
∞
Ak
+
Ak = 2π k k2
X
∴ x(t) = eikt
−5ik 3 − 3k 2 + 6ik + 2
π
k=−∞
k=0
4
Consider the function f (t) = |t| when −π < t ≤ π with the same period as the above question
(T = 2π). Can you relate it somehow to the ramp function? Now use that knowledge to solve the
above question but with the driving force replaced by f (t) (with the same period) instead of the
ramp function.
NOTE: For those who have already met the attendance criteria, there is absolutely NO need to
submit this bonus question. But I still ask you to try this out. Including it in your solution will
make my day.
Solution:
Thus,
f (t) = rp (t) + rp (−t)
∞ ∞
! !
k k k k
π X 1 iπ (−1) (−1) − 1 π X 1 iπ (−1) (−1) − 1
= + + e ikt
+ + + e−ikt
4 2π k k2 4 2π k k2
k=−∞ k=−∞
k6=0 k6=0
∞
! ! !
k k (−k) (−k)
π X 1 iπ (−1) (−1) − 1 1 iπ (−1) (−1) −1
= + + eikt + + eikt
2 2π k k2 2π −k (−k)2
k=−∞
k6=0
∞
! ! !
k k k k
π X 1 iπ (−1) (−1) − 1 1 iπ (−1) (−1) − 1
= + + eikt + + eikt
2 2π k k2 2π −k k2
k=−∞
k6=0
∞
! !
k k k k
π X 1 iπ (−1) (−1) − 1 iπ (−1) (−1) − 1 ikt
= + + + + e
2 2π k k2 −k k2
k=−∞
k6=0
∞
!
k k
π X 1 (−1) − 1 (−1) − 1
= + + eikt
2 2π k2 k2
k=−∞
k6=0
7
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
∞
!
k
π X 1 (−1) − 1
= + eikt
2 π k2
k=−∞
k6=0
!
k
1 (−1) − 1
k 6= 0
∴ Ak = π k2
π
k=0
2
The differential equation now reduces to the standard LCCDE with an driving force in the
form of a Fourier Series.
∞
d3 x d2 x dx X
+ 3 + 6 + 2x = Ak eikt
dt3 dt2 dt
k=−∞
∞
As usual, we assume the solution is some series Bk eikt . Substituting in the above
X
k=−∞
differential equation and solving, we get:
∞
X ∞
X
3 2
5 (ik) + 3 (ik) + 6ik + 2 Bk eikt = Ak eikt
k=−∞ k=−∞
Ak
=⇒ Bk =
−5ik 3 − 3k 2 + 6ik + 2
!
k
1 (−1) − 1
k 6= 0
∞
Ak
k2
Ak = π
X
∴ x(t) = eikt
−5ik 3 − 3k 2 + 6ik + 2
π
k=−∞
k=0
2
8
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
If I were to simplify things a bit, and ask you to find the value of the definite integral
Z ∞
1
dx
−∞ (1 + x2 )2
what would your approach be? There is a really elegant way to compute this integral using the
concepts that were taught in the third session. Try to recall them and compute the value of this
definite integral.
Final Expected Answer: The value of the definite integral computed using
R∞ 1
−∞ (1+x2 )2
dx
the concepts taught in the third session.
Solution:
Z ∞ Z ∞ Z ∞
4
=⇒ dω = 2π × e−2|t| dt = 4π × e−2t dt
−∞ (1 + ω 2 )2 −∞ 0
Z ∞ Z ∞
1 1 π
=⇒ dω = π × e−2t dt = π × =
−∞ (1 + ω 2 )2 0 2 2
Z ∞
1 π
Thus, we have computed the value of the required integral; 2 2
dx =
−∞ (1 + x ) 2
9
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
This morning Navin was assigned the work of recording an orchestral performance that was being
performed by the coordinators of the Mathematics Club. He was asked to record each instrument
in a different channel, so that the audio can be equalized easily later on by our Music Directors -
KK and Achintya. Unfortunately, Navin being the clumsy person that he is accidentally ended up
recording all of the instruments as a single audio file.
The Music directors want to tone down (decrease the volume of) the snare drums by 25%. The
snare drums used by the Mathematics Club produce sounds in the frequency range of 150Hz
to 250Hz. Assume that no other musical instruments produce sounds in this audio range.
Luckily, he has you to help him! Navin hoping that you listened to his presentation attentively is
asking you to write a program in MATLAB or GNU Octave which fulfills the directors’ request and
saves his job!
Final Expected Submission: A script written in MATLAB or GNU Octave that performs the
following:
• Uses Fourier Transform methods to perform the request of reducing the volume of the drums
by 25% in the audio data
• Writes the newly generated audio data using the function audiowrite to an audio file named
"thankyou_for_saving_my_job.wav"
Note:
2. If you are submitting your code via a Google Drive / GitHub link make sure to enable access
for all, so that we will be able to access your submission.
10
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Solution:
The GNU Octave / MATLAB code is given below. This code also accounts for multiple channels
being present in the audio file.
clc;
clear;
% Parameters for our filter, you can play around with them
f1 = 150;
f2 = 250;
atten = 0.75;
% Run through each channel in the audio file and perform Fourier
,→ Transform
for i = 1:numChannels
audioFT(:, i) = fft(inputAudio(:, i));
end
11
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
If you have not accounted for multiple channels, your code might look like this:
clc;
clear;
% Parameters for our filter, you can play around with them
f1 = 150;
f2 = 250;
atten = 0.75;
An alternative approach would be to use for loops instead of using the smart indexing features
provided in GNU Octave / MATLAB to filter the frequencies from 150Hz to 250Hz. You can also
use fftshift to reorder the frequencies if you wish to.
Your code doesn’t need to be exactly the same as the solution given here. As long
as your code has the same functionality as what is demanded by this problem you
will get a good grade.
12
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Bonus Question 2: Thinking in the Time Domain [For those with 7/10 attendance]:
NOTE: For those who have already met the attendance criteria, you DO NOT need to
submit this! You will be eligible for the certificate even if you don’t attempt this question. This is
just a bonus question. I will be very happy if you attempt this question, and that is a good thing!
Can you think of a way to perform the same task of changing the contribution of some
frequencies in a given function of time f (t) without analysing the function in the frequency-domain
using a Fourier Transform, instead working entirely in the time-domain. You can use the same
example as the above question or use any example that you like.
Solution:
Let X(ω) be the Fourier Transform of your time-domain signal x(t) and the filter H (attenuation
of certain frequencies) that you wish apply be represented in the frequency-domain by H(ω).
Let h(t) be the inverse Fourier Transform of H(ω), that is the h(t) is the time-domain
representation of the filter.
You might have noticed that when you are applying the filter H to x(t), what you are doing is:
computing X(ω), multiplying it with H(ω) and then computing the inverse Fourier Transform
of X(ω)H(ω) to obtain xnew (t). Let’s try to perform this for a general x(t).
Z +∞
1
xnew (t) = eiωt X(ω)H(ω)dω
2π −∞
Writing X(ω) in terms of x(t) using the expression for Fourier Transform, we get
Z +∞ Z +∞ Z +∞ Z +∞
iωt −iωτ
2πxnew (t) = e e x(τ )dτ H(ω)dω = eiω(t−τ ) x(τ )H(ω)dτ dω
−∞ −∞ −∞ −∞
Now we change the order of the integration using Fubini’s theorem from dτ dω to dωdτ . Note
that we are assuming here that the order of the integration can be reversed. This can be done
as long as the inner integral exists and the functions inside are integrable, which is indeed true
since we have assumed beforehand that X(ω) and every other quantity involved exist.
Z +∞ Z +∞ Z +∞ Z +∞
iω(t−τ ) iωt −iωτ
2πxnew (t) = e x(τ )H(ω)dωdτ = x(τ ) e H(ω)e dω dτ
−∞ −∞ −∞ −∞
Z +∞ Z +∞
1
=⇒ xnew (t) = x(τ ) eiωt H(ω)e−iωτ dω dτ
−∞ 2π −∞
The expression H(ω)e is simply the Fourier Transform of h(t − τ ) and the expression
−iωτ
In the expression obtained above, we have shown the can result of the filtering process be
obtained directly by convolving the original signal x(t) with the time-domain representation of
the required filter h(t). The process of working in the frequency domain has been completely
eliminated.
13
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Bonus Question 3: A more sophisticated Filter [For those with 7/10 attendance]:
NOTE: For those who have already met the attendance criteria, you DO NOT need to
submit this! You will be eligible for the certificate even if you don’t attempt this question. This is
just a bonus question. I will be very happy if you attempt this question, and that is a good thing!
Repeat Problem 3 (A Tale of Musical Mismanagement) but instead of toning down the
amplitude of all frequencies in 150Hz to 250Hz by 25%, you have to tone down the frequencies:
Solution:
The modifications to GNU Octave / MATLAB code in Problem 3 in order to make the filtering
more sophisticated is given here. The variations in the code mentioned in the solution to
Problem 3 apply here as well. You can work with mono or stereo audio files, use fftshift
or not, and so on. The code snippet here shows only the modifications to the filtering
process.
...
% Parameters for our filter, you can play around with them
filterFreqs = [150, 175, 225, 250]
filterAttens = [0.80, 0.75, 0.85]
...
14
Mathematics Club IITM MathLab: Problem Set 3
Navin, KK, Achintya — June 2024 Solutions
Appendix
∞
Let the exponential series be of the form Ak eikω0 t and the trigonometric series be of the form
X
k=−∞
∞ ∞
a0 X
bk sin(ω0 t). Then, it can be shown that:
X
+ ak cos(ω0 t) +
2
k=1 k=1
• ak = Ak + A−k
• bk = i(Ak − A−k )
15