Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

At this assignment, we want to implement the trigonometric Fourier series in MAT

ID: 3754858 • Letter: A

Question

At this assignment, we want to implement the trigonometric Fourier series in MATLAB. The goal is to write a function which calculates the trigonometric Fourier series coefficients of a given periodic function. a. Write a MATLAB function, [ao a, bl- FSLTN), which gets the input function x(t) as a vector x, the vector of time positions (t in sec), the period (T in sec), and N (number of coefficients) as the input arguments so as to calculate and return the trigonometric Fourier series coefficients (aoanabn) @m = Sto+7 f(t)cos (na,t)dt 2 cto+T Here, ao is a scalar and a and b are two vectors of length N. For integration purposes, use trapz in MATLAB

Explanation / Answer

function [a0,a,b]=FS(x,t,T,N)
n=1:N;
a=zeros(1,N);
b=a;
w=2*pi/T;
a0=trapz(x)/T;
for i=1:N
    a(i)=(2/T)*trapz(x.*cos(n(i)*w*t));
    b(i)=(2/T)*trapz(x.*sin(n(i)*w*t));
end