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

MATLAB QUESTION 4: The Fourier Series approximation for an even function with a

ID: 3168255 • Letter: M

Question

MATLAB QUESTION 4:

The Fourier Series approximation for an even function with a period of 1 Hz is given by: f(t) = ao +a, cos(2 * 1 * t)+--+a,, cos(2 * N * t) t an + a.cos 2 or, in discrete-time in matrix form: 1 cos(2xt) cos(2tNt f(t2) cos(2t .. cos(2xNt2) a, f() cos(2 . cos(2.xNt)av The ordinary least-squares solution is (l know, it's the long way in MATLAB. You can use the short way if you remember) -1 Note that the elements of the n-th column (where n ranges from 0 to N) of the H matrix are given by: H, = cos(2 nt.) where i ranges from 1 to k. Let a time vector be defined in MATLAB® as: t = [-2:0.0127; % Note: this makes t' a column vector k = length(t); % ,length, returns the number of elements in a vector Assume 'N' has been defined. Note that it can be any positive integer." Assume f is a pre-defined vector of length k and contains the values of an ideal, even, 1 Hz square wave with values that correspond to the time values in t With t, k, f and N defined as above, write the MATLAB® code needed to create the H matrix and then write the MATLAB statement needed to estimate the Fourier Series coefficient vector, aoLS

Explanation / Answer

H = zeros(k, N+1);
for i=1:k
for j=1:N+1
H(i,j) = cos(2*pi*(j-1)*t(i));
end
end
a = (inv(H'*H))*(H')*f;