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

Write a Matlab code for the following question 1) Given a periodic signal with v

ID: 2265953 • Letter: W

Question

Write a Matlab code for the following question

1) Given a periodic signal with values over one period given by: 1, 0St1 -1, x(t) = 1sts?, a) Compute the trigonometric Fourier Series coefficients (ao, a, b) using Matlab. You can use the 'int command to perform the integration. Compare the values with your hand calculation for n-0 to 5. Compute the compact trigonometric Fourier Series coefficients (co, cn) in Matlab. Plot the magnitude and phase spectrum for n-0 to 5. (Using the 'stem' command in Matlab) i) Plot the original x(t) for 0

Explanation / Answer

%%%%%%%%%MATLAB CODE:

%%%%%MATLAB FUNCTION%%%%%%%%%%%%%%%%%%%%%
%%%%PART 1: COMPUTE THE COEFFICIENTS%%%%%%%%%%%%%%%%%%%
T0=2;
syms x
a(1)=(1/T0)*(int(x/x, 0, 1)-int(x/x,1,2));
b(1)=0;
for i=1:5
a(i+1)=(2/T0)*(int(cos((2*pi*i*x)/T0), 0, 1)-int(cos((2*pi*i*x)/T0),1,2));
b(i+1)=(2/T0)*(int(sin((2*pi*i*x)/T0), 0, 1)-int(sin((2*pi*i*x)/T0),1,2));
end
a
b

%%%%%%%%%%%%When you run the above portion of the code you will get
%%% a =[ 0, 0, 0, 0, 0, 0]%%%
%%% b =[0,1.2732,0,0.4244,0,0.2546]%%%%%%
%%%This matches with ours theoretical results%%%%%%%%%%%%%%%%%%%%
%%%%PART 2: COMPUTE THE FOURIER TRIGNOMETRIC COEFFICIENTS C0, Cn%%%%%%%%%%
c(1)=0;
for i=1:5
c(i+1)=(-1/(2*sqrt(-1)*pi*i))*(2*exp(-sqrt(-1)*pi*i)-exp(-sqrt(-1)*2*pi*i)-1);
end
figure;
stem(0:1:5,abs(c)),xlabel('n'),ylabel('magnitude');title('Magnitude Plot');
figure;
stem(0:1:5,phase(c)),xlabel('n'),ylabel('phase');title('Phase Plot');
%%%%%PART 3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%PART 3 (i)
t=(0:.1:10)*pi;
X=square(t);
plot(t/(2*pi),X);
%%%% PART 3(ii)
N=10;
t=0:.1:10;
X=0*zeros(1,length(t));
for i=1:N
if (mod(i,2)==0)
X=X+0;
else
X=X+(4/(pi*i))*sin(pi*i*t);
end
end
figure
plot(t,X);

%%%% PART 3(iii)
N=30;
t=0:.1:10;
X=0*zeros(1,length(t));
for i=1:N
if (mod(i,2)==0)
X=X+0;
else
X=X+(4/(pi*i))*sin(pi*i*t);
end
end
figure
plot(t,X);
%%%% PART 3(iv)
N=60;
t=0:.1:10;
X=0*zeros(1,length(t));
for i=1:N
if (mod(i,2)==0)
X=X+0;
else
X=X+(4/(pi*i))*sin(pi*i*t);
end
end
figure
plot(t,X);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote