100% Guaranteed Results


EE2703 – Assignment 4: Fourier Approximations Solved
$ 24.99
Category:

Description

5/5 – (1 vote)

JINEETH N [EE20B051]
Abstract
• Fit two functions ex and cos(cos(x)) using the Fourier series coefficients calculated by least squares fitting method.
• To plot graphs for better understanding
1 Introduction
The fourier function of a function f(x) with period 2π can be calculated as follows
) (1)
where
(2)
(3)
(4)
2 Asssignment Tasks
2.1 Defining functions and plotting them
def expo(x): return exp(x)
def coscos(x):
pass return cos(cos(x)) x = np.linspace(-2 * pi, 4 * pi, 1200)
plt.semilogy(x, y_exp, label=”True”) plt.plot(xl[::5], yl_coscos[::5], “og”, label=”Predicted”)

Figure 1: Plotting exp(x) in semilog scale

Figure 2: Plotting cos(cos(x)) in semilog scale
The plots for cos(cos(x)) and exp(x) are shown above
2.2 Computing fourier coefficients using integration
The first 51 coefficients are generated using the scipy.integrate.quad and the equations mentioned in
a0
a1
 
b1 
the introduction function.They are saved in the following form  … 

 
a25 b25
for k in range(26):
if k != 0:
c_coscos[p] = integrate.quad(a_coscos, 0, 2 * pi, args=(k))[0] / pi c_coscos[p + 1] = integrate.quad(b_coscos, 0, 2 * pi, args=(k))[0] / pi
c_exp[p] = integrate.quad(a_exp, 0, 2 * pi, args=(k))[0] / pi c_exp[p + 1] = integrate.quad(b_exp, 0, 2 * pi, args=(k))[0] / pi
p = p + 2
else:
c_coscos[p] = (integrate.quad(a_coscos, 0, 2 * pi, args=(k))[0] / pi) / 2 c_exp[p] = (integrate.quad(a_exp, 0, 2 * pi, args=(k))[0] / pi) / 2
p = p + 1
• Fourier coefficients of an even function should be zero. As expected bn is close to zero for cos(cos(x)) as it is an even function. • The coefficients in a fourier series represent what are the frequencies happen to be in the output. The function cos(cos(x)) doesn’t contain many different frequencies, so the values decay out quickly whereas the the exponential function is combination of different frequencies
• The loglog plot is linear for et because Fourier coefficients of et decay with 1/n or 1/n2. The semilog plot is linear in cos(cos(t)) as the Fourier coefficients decay exponentially with n
2.3 Using Least squares approach
Now, we used Least Squares approach to find the Fourier series coefficients. We linearly choose 400 x values in the range [0, 2π) and calculated coefficients using scipy.lstsq function
A = np.zeros((400, 51)) A[:, 0] = 1 for k in range(1, 26):
A[:, 2 * k] = sin(k * xl)
A[:, 2 * k – 1] = cos(k * xl)
cl_exp = lstsq(A, B_exp, rcond=None)[0].reshape((-1, 1)) cl_coscos = lstsq(A, B_coscos, rcond=None)[0].reshape((-1, 1))

Figure 3: semilog scale

Figure 4: loglog scale

Figure 5: semilog scale

Figure 6: loglog scale

Figure 7: semilogy scale

Figure 8: loglogy scale

Figure 9: semilogy scale

Figure 10: loglogy scale The numpy linalg lstsq() solves the equation ax = b by computing a vector x that minimizes the Euclidean 2-norm |b–ax|2
• Maximum deviation for exp(x) is 1.3327
• Maximum deviation for cos(cos(x)) is 2.618e-15
We can observe error in exp(x) >> cos(cos(x))
2.4 Plotting result
The deviation in more in exp(x) fitting beacuse fourier series exists only for periodic functions but ex is a non periodic function

Figure 11: Actual and predicted values of exp(x)

Figure 12: Actual and predicted values of cos(cos(x))
3 Conclusion
We computed Fourier series coefficients using two different methods
• Using integration
• Least Square Fitting method
We found close matching in two methods in case of cos(cos(x)) while, there is a larger discrepancy in exp(x)

Reviews

There are no reviews yet.

Be the first to review “EE2703 – Assignment 4: Fourier Approximations Solved”

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

Related products