You are on page 1of 8

Department of Electrical Engineering

Semester:4th Subject: Signals and Systems Lab. No. 08


Objective:
Simulation of M-point Moving Average Filter using Matlab
Apparatus:
Personal Computer, MATLAB
Procedure:

Task:1
Run the above program for M = 2 to generate the output signal with x[n] = s1[n]+ s2[n]
as the input. Which component of the input x[n] is suppressed by the discrete time system
simulated by this program.
Ans:

n=0:100;
f1=0.05;
f2=0.47;
s1=cos(2*pi*f1*n);
s2=cos(2*pi*f2*n);
x=s1+s2;
M=2;
b=ones(1,M);
figure;
subplot(221)
plot(n,s1);grid;xlabel('n')
ylabel('s2(n)');title('s2(n)')
subplot(233)
plot(n,x);grid;xlabel('n')
ylabel('x(n)');title('x(n)')
ylabel('y(n)');title('y(n)')
Department of Electrical Engineering

Task:2
If the LTI system is changed from y[n] 0.5(x[n] + x[n - 1]) to y[n] =0.5(x[n] - x[n - 1]),
what would be its effect on the input x[n] = s1[n] + s2[n]?
Ans:
clc;close all;clear all;
n=0:100;
f1 = 0.05;
f2 =0.47;
s1=cos(2*pi*f1*n);
s2=cos(2*pi*f2*n);
x=s1+s2;
M=2;
b=[0.5-0.5];
y=filter(b,1,x)/M;
figure;
subplot(221)
plot(n,s2);grid;xlabel('n');
ylabel('s1(n)');title('s1(n)')
subplot(222)
plot(n,s2);grid;xlabel('n')
ylabel('s2(n)');title('s2(n)')
subplot(223)
plot(n,x);grid;xlabel('n')
ylabel('x(n)');title('X(n)')
subplot(224)
plot(n,y);grid;xlabel('n')
Department of Electrical Engineering
ylabel('y(n)');title('y(n)')

Task:3
Run Program P7_ 1 for other values of filter length M, and various values of
thefrequencies of the sinusoidal signals s1[n] and s2[n]. Comment on your results.

Ans:
n=0:100;
f1 = 0.07;
f2 =0.50;
s1=cos(2*pi*f1*n);
s2=cos(2*pi*f2*n);
x=s1+s2;
M=4;
b=ones(1,M);
y=filter(b,1,x)/M;
figure;
subplot(221)
plot(n,s2);grid;xlabel('n');
ylabel('s1(n)');title('s1(n)')
subplot(222)
plot(n,s2);grid;xlabel('n')
ylabel('s2(n)');title('s2(n)')
subplot(223)
Department of Electrical Engineering
plot(n,x);grid;xlabel('n')
ylabel('x(n)');title('X(n)')
subplot(224)
plot(n,y);grid;xlabel('n')
ylabel ('y(n)') ;title('y(n)for M=10 & f1=0.4');
Department of Electrical Engineering
Department of Electrical Engineering
Department of Electrical Engineering

Task:5
Use sinusoidal signals with different frequencies as the input signals and compute the
output signal for each input. How do the output signals depend on the frequencies of the input
signal? Can you verify your observation mathematically?
Ans:
n = 0:200;
x = cos(2*pi*0.05*n);
% Compute the output signal
x1 = [x 0 0]; % x1[n] = x[n+1]
x2 = [0 x 0]; % x2[n] = x[n]
x3 = [0 0 x]; % x3[n] = x[n-1]
y = x2.*x2-x1.*x3;
y = y(2:202);
% Plot the input and output signals
subplot(2,1,1)
plot(n, x)
xlabel('Time index n');ylabel('Amplitude');
title('Input Signal')
subplot(2,1,2)
plot(n,y)
xlabel('Time index n');ylabel('Amplitude');
title('Output signal');
Department of Electrical Engineering

Checked and verified by


Lab Prepared By: Farkhan Wasil_3252
(Lab Instructor)

You might also like