Anda di halaman 1dari 4

LABSHEET 2

QU. 1
t = 0:0.001:20;
N=1001;
%period of the square wave
omega = 1;
%Cut-off angular frequency and Q-factor of the lowpass filter
W = 100;
Q = 0.7;
x = 0;
y = 0;
for n = -N:2:N
s = 1i*(omega*n);
a = (2/(1i*n*pi))*exp(1i*n*omega*t);
b = (W^2)/(s^2 + (W/Q)*s + W^2);
x = x + a;
y = y + a*b;
end
%subplot(m,n,p)breaks the Figure window into an m-by-n matrix of small axes,selects the p-th
axes for the current plot, and returns the axes handle.
subplot(2,1,1);
plot(t,x);
xlabel('Time index,t/s');
ylabel('X(t)');
title('Bipolar Square Wave X(t)');
grid on;
subplot(2,1,2);
plot(t,y);
xlabel('Time index,t/s');
ylabel('Y(t)');
title('Output waveform after lowpass filtering');
grid on;

QU 2.
t = 0:0.001:20;
N=1001;
%period of the square wave
omega = 1;
%Cut-off angular frequency and Q-factor of the highpass filter
W = 5;
Q = 0.7;
x = 0;
y = 0;
for n = -N:2:N
s = 1i*(omega*n);
a = (2/(1i*n*pi))*exp(1i*n*omega*t);
b = (s^2)/(s^2 + (W/Q)*s + W^2);
x = x + a;
y = y + a*b;
end
%subplot(m,n,p)breaks the Figure window into an m-by-n matrix of small axes,selects the p-th
axes for the current plot, and returns the axes handle.
subplot(2,1,1);
plot(t,x);
xlabel('Time index,t/s');
ylabel('X(t)');
title('Bipolar Square Wave X(t)');
grid on;
subplot(2,1,2);
plot(t,y);
xlabel('Time index,t/s');
ylabel('Y(t)');
title('Output waveform after highpass filtering');
grid on;

QU 3.
t = 0:0.001:20;
N=1001;
%period of the square wave
omega = 1;
%Cut-off angular frequency and Q-factor of the Bandpass filter
W = 3;
Q = 10;
x = 0;
y = 0;
for n = -N:2:N
s = 1i*(omega*n);
a = (2/(1i*n*pi))*exp(1i*n*omega*t);
b = (W*s)/(s^2 + (W/Q)*s + W^2);
x = x + a;
y = y + a*b;
end
%subplot(m,n,p)breaks the Figure window into an m-by-n matrix of small axes,selects the p-th
axes for the current plot, and returns the axes handle.
subplot(2,1,1);
plot(t,x);
xlabel('Time index,t/s');
ylabel('X(t)');
title('Bipolar Square Wave X(t)');
grid on;
subplot(2,1,2);
plot(t,y);
xlabel('Time index,t/s');
ylabel('Y(t)');
title('Output waveform after Bandpass filtering');
grid on;

QU 4.
T = 2*pi;
f = 1/T;
w = 2*pi*f;
x = 101;
cn = zeros(1,x);
i = 1;
for n=1:1:x
an = @(t) ((2*cos(t)) + 0.05*(2*cos(t)).^3).*cos(n*w*t);
bn = @(t) ((2*cos(t)) + 0.05*(2*cos(t)).^3).*sin(n*w*t);
a = (2/T)*quad(an,0,T);
b = (2/T)*quad(bn,0,T);
cn(i) = a^2 + b^2;
i = i + 1;
end
S = sum(cn) - cn(1);
var = S/(cn(1));
THD = 10* log10(var);
perTHD = sqrt(var) * 100;
sprintf('The total harmonic distortion in output is %0.3f dB or %0.3f percent', THD, perTHD)

Anda mungkin juga menyukai