Assume that the coefficients required to implement the summa
Assume that the coefficients required to implement the summation are known. Coefficients of Cn and On are stored in vectors of length N+1. Variable t=0:Tsample:Tmax, tmax is some multiple of the period of the signal. Write a MATLAB function called harmonic to generate the signal r(t). The inputs to this function should be the scalar w0, containing the fundamental frequency, the vectors Cn, thetan, the maximum time tmax, and the sampling interval Tsample. The output of the function should be the vector r containing the signal r(t) sampled at the specified values of time t. Your function may use either a for loop or a matrix multiply to implement the summation. If you use a for loop, only one such loop should be necessary.
n cos nwo n=0Solution
function r=harmonic(w0,Cn,thetan,Tmax, Tsample)
t=0:Tsample:Tmax;
r=zeros(size(t));
for n=1:length(Cn)
r=r+Cn(n).*cos((n-1).*w0.t+thetan(n-1));
end
end
