Systems and signals square wave

Case I: Square-wave x1(t), 50% duty cycle

f0=500 Hz

To=1/500=0.002s=2 ms

Mathematically, the square-wave can be expressed for a single period as

systems and signals square wave image 1

Therefore the trigonometric Fourier series coefficients of x1(t) are

systems and signals square wave image 2

Case II: Square-wave x2 (t), 25% duty cycle

Mathematically, the square-wave x2 (t) can be expressed for a single period as

systems and signals square wave image 3

Sinusoids from -8 to -1;

systems and signals square wave image 4
    clear
clc
f_0= 500; % fundamental frequency 
t= -0.001:0.00001:0.006; %time axis 
Z_50= zeros(1,length(t)); % container for 50% duty cycle waveform 
Z_25= zeros(1,length(t)); % container for 25% duty cycle waveform 
n=1:16; 
n1=sin(pi.*n./2);
d1=(pi.*n./2);
n2=sin(pi.*n./4); 
d2=((pi).*n./4); 
a_50=[n1./d1]; %fourier coefficients for 50% duty cycle
a_25=[0.5*(n2./d2)]; %fourier coefficients for % duty cycle
for k=1:length(n) 
    wa=1*cos(2*pi*(k)*f_0*t); 
    Z_50=Z_50+ a_50(k)*wa;
    Z_25=Z_25+ a_25(k)*wa; 
end
soundsc(Z_50)
figure (1)
plot(t,Z_50) 
hold on 
grid on
axis tight 
xlabel('time') 
ylabel('Amplitude') 
title('Square-wave with 50% duty cycle');

figure(2) 
plot(t,Z_25)
grid on 
axis tight
xlabel('time') 
ylabel('Amplitude'); 
title('Square-wave with 25% duty cycle');
Want latest solution of this assignment