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

By using MATLAB, design a C program that calculates FS partial-sum approximation

ID: 2083188 • Letter: B

Question

By using MATLAB, design a C program that calculates FS partial-sum approximation and FT coefficients of the signals given in Fig. 1

o Based on the calculated FS partial sum approximation, plot one period of the approximated signal r (t) for J-1, 3, 7, 29, and 99. o Based on the calculated FT coefficients, depict the normalized magnitude spectrum of signals in dB. O Verification of Designed Program o Find t) for J-1, 3, 7, 29, and 99 using by the C program and depict one period of the Jth term in this sum. 1/2 B kl (2/(kT)) (-1) (k-1)/2 k odd k even. o Use the FT to depict the normalized magnitude spectrums of Fig 1. 8/3 To/2 To/2 0 To/2 To 2 (b) (a) Fig 1. (a) Rectangular pulse. (b) Raised cosine pulse.

Explanation / Answer

clc;
close all;
clear all;

%% QUESTION 1
t = 0:1:100;
w0 = 2*pi;
xt = zeros(1,length(t));

J = 1;
for k = 0:J;
    t = 0:1:100;
    if (k==0)
        Bk = 0.5;
    elseif(rem(k,2)==0)
        Bk = 0 ;
    elseif(rem(k,2)==1)
        Bk = ((2/(k*pi))*(-1).^((k-1)/2));
    end
    dxt = Bk.*cos(k*w0*t);
    xt = plus(xt,dxt);
end
figure
stem(xt);

xt = zeros(1,length(t));
J = 3;
for k = 0:J;
    t = 0:1:100;
    if (k==0)
        Bk = 0.5;
    elseif(rem(k,2)==0)
        Bk = 0 ;
    elseif(rem(k,2)==1)
        Bk = ((2/(k*pi))*(-1).^((k-1)/2));
    end
    dxt = Bk.*cos(k*w0*t);
    xt = plus(xt,dxt);
end
figure
stem(xt);

xt = zeros(1,length(t));
J = 7;
for k = 0:J;
    t = 0:1:100;
    if (k==0)
        Bk = 0.5;
    elseif(rem(k,2)==0)
        Bk = 0 ;
    elseif(rem(k,2)==1)
        Bk = ((2/(k*pi))*(-1).^((k-1)/2));
    end
    dxt = Bk.*cos(k*w0*t);
    xt = plus(xt,dxt);
end
figure
stem(xt);

xt = zeros(1,length(t));
J = 29;
for k = 0:J;
    t = 0:1:100;
    if (k==0)
        Bk = 0.5;
    elseif(rem(k,2)==0)
        Bk = 0 ;
    elseif(rem(k,2)==1)
        Bk = ((2/(k*pi))*(-1).^((k-1)/2));
    end
    dxt = Bk.*cos(k*w0*t);
    xt = plus(xt,dxt);
end
figure
stem(xt);

xt = zeros(1,length(t));
J = 99;
for k = 0:J;
    t = 0:1:100;
    if (k==0)
        Bk = 0.5;
    elseif(rem(k,2)==0)
        Bk = 0 ;
    elseif(rem(k,2)==1)
        Bk = ((2/(k*pi))*(-1).^((k-1)/2));
    end
    dxt = Bk.*cos(k*w0*t);
    xt = plus(xt,dxt);
end
figure
stem(xt);


%% QUESTION 2

To = 50E-6;
N = 50;
t = -To : To/(3*N): To -(To/(3*N));
length(t)
num = (sqrt(8)/3)*rcosine(1,ceil(length(t)/6));
num = num(1:length(t));
plot(t,num);

y_rcos = fft(num);
figure
plot(t,abs(y_rcos));

rect_t = (t>=(-To/2)).*1 + (t<=(To/2)).*1;
figure
plot(t,rect_t/2);

y_rect = fft(rect_t/2);
figure
plot(t,abs(y_rect));