You are on page 1of 16

# Q.1. A sequence is given by x(n)=u(-n-9), for 0<=n<=5.

## Write a program to plot

the sequences y[n]=x[4-n]

Program:
n=0:5;
u=[ones(1,6)];
x=fliplr(u);
n=-fliplr(n);
n=n+9;
subplot(2,1,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
y=fliplr(x);
n=-fliplr(n);
n=n-4;
subplot(2,1,2);
stem(n,y);
xlabel('n');
ylabel('y(n)');
PLOT
Q.2.Write a MATLAB program to test whether the following systems are linear or
non linear.
(a).y[n]=x[n]*cos(pi*n/6)
(b).y[n]=sin(x[n])
(c).5*dy/dt+y(t) = 5*x(t)

Program:
x1 = [1 3 4 6 4];
x2 = [3 2 6 4 1];
a = 0.74; b = 2;
y1_1(1,5)=0;y1_2(1,5)=0;y1_12(1,5)=0;
y2_1(1,5)=0;y2_2(1,5)=0;y2_12(1,5)=0;
y3_1(1,5)=0;y3_2(1,5)=0;y3_12(1,5)=0;
%01
x12 = a*x1 + b * x2;
for i=1:5
y1_1(1,i) = x1(1,i)*cos(pi*i/6);
y1_2(1,i) = x2(1,i)*cos(pi*i/6);
y1_12(1,i) = x12(1,i)*cos(pi*i/6);
y2_1(1,i) = sin(x1(1,i));
y2_2(1,i) = sin(x2(1,i));
y2_12(1,i) = sin(x12(1,i));
y3_1(1,i) = exp(-i/5)*x1(i);
y3_2(1,i) = exp(-i/5)*x2(i);
y3_12(1,i) = exp(-i/5)*x12(i);
end
y1 = a*y1_1 + b * y1_2;
y2 = a*y2_1 + b * y2_2;
y3 = a*y3_1 + b * y3_2;
%01
y11 = y1_12 - y1;
if (abs(y11) > 0.1 )
fprintf ('\nThe system (1) is not linear.\n');
else
fprintf ('\nThe system (1) is linear.\n');
end
%02
y22 = y2_12 - y2;
if (abs(y22) > 0.1 )
fprintf ('\nThe system (2) is not linear.\n');
else
fprintf ('\nThe system (2) is linear.\n');
end
%03
y33 = y3_12 - y3;
if (abs(y33) > 0.1 )
fprintf ('\nThe system (3) is not linear.\n');
else
fprintf ('\nThe system (3) is linear.\n');
end

Output:
For part(a) y[n] is linear
For part(b) y[n] is non linear
For part(c) y[n] is non linear
Q.3.Write a MATLAB program to check whether the system are time variant or
invariant in Q.2.

Program:
x1 = [1 3 4 6 4];
k = 3;
y1(1,8)=0;y1_s(1,8)=0;
y2(1,8)=0;y2_s(1,8)=0;
y3(1,8)=0;y3_s(1,8)=0;
%01
for i=1:5

end

%01
y11 = y1_s - y1;
if (abs(y11) > 0.1 )
fprintf ('\nThe system (1) is not time variant.\n');
else
fprintf ('\nThe system (1) is time variant.\n');
end
%02
y22 = y2_s - y2;
if (abs(y22) > 0.1 )
fprintf ('\nThe system (2) is not time variant.\n');
else
fprintf ('\nThe system (2) is time variant.\n');
end
%03
y33 = y3_s - y3;
if (abs(y33) > 0.1 )
fprintf ('\nThe system (3) is not time variant.\n');
else
fprintf ('\nThe system (3) is time variant.\n');
end

Output:
Part (a) is time variant
Part (b) is time invariant
Part (c) is time invariant
Q.4. Write a Program to implement a non causal three sample average given by
Y[n]=1/3*(x[n+1]+x[n]+x[n-1])

Program:
clear all;
n=-5:10;
x=2*n;
n1=n-1;
n3=n+1;
m=min(min(n1(1),n(1)),n3(1)):max(max(n1(16),n(16)),n3(16));
m;
y1=[zeros(1,length(m))];y2=y1;y3=y2;
l=1:length(n);
k=-1;
for i=m(1):n1(1)
k=k+1;
end
y1(k+l)=x;
k=-1;
for i=m(1):n(1)
k=k+1;
end
y2(k+l)=x;
k=-1;
for i=m(1):n3(1)
k=k+1;
end
y3(k+l)=x;
y1=(y1+y2+y3)/3;
Q.5.Write a program to compute and plot the impulse response of a system given
by
Y[n]=0.8y(n-1) - 0.6y(n-2) + 0.866x(n)
Also determine stability of the system

Program:
a=[1,-0.8,0.64];
b=.866;
n=-25:25
x=[zeros(1,25) 1 zeros(1,25)];
h=filter(b,a,x);
stem(n,h);
xlabel('n');
ylabel('h(n)');
if(sum(abs(h))<realmax)
disp('The system is stable');
else
disp('The system is not stable');
end

Output:
The system is stable
PLOT
Q.6.Write a program to determine output y[n], n>=0 of the system determined by
the system described by the difference equation
Y[n] = x[n] - 2*x[n-1] + x[n-2]
Where input is x[n]=u[n]. Also plot y[n] for 0<=n<=25.
For this system, determine the impulse response. And then verify using the
convolution function.

Program:
clear all;
n=0:1:25;
x=[ones(1,26)];

x1=[zeros(1,1),ones(1,25)]

x2=[zeros(1,2),ones(1,24)];

y=x-(2*x1)+x2;
stem(n,y);
PLOT
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 5 10 15 20 25
Q.7.Write a program to determine the convolution of the two sequence given
below
X[n]={3,11,7,0,-1,4,2}
H[n]={2,3,0,-5,2,1}

Program:
x=[3 11 7 0 -1 4 2];
h=[2 3 0 -5 2 1];
y=conv(x,h);
disp('The convolved sequence is');
y

Output:
The convolved sequence is

y=

6 31 47 6 -51 -5 41 18 -22 -3 8 2
Q.8.Write a program to compute and plot the correlation sequences rxy[m] and
rxx[m] for the following signal sequences
X[n]=1, for n = -3<=n<=7
0, Otherwise
y[n]=1, for n = -5<=n<=5
0, Otherwise
Where m is shift parameter

Program:
x=[ones(1,11)];
y=[ones(1,11)];
n1=-3:7;
n2=-5:5;
y1=fliplr(y);
n3=-fliplr(n2);
rxy=conv(x,y1);
nb=n1(1)+n3(1);
ne=n1(11)+n3(11);
n=nb:ne;
subplot(2,1,1);
stem(n,rxy);
xlabel('n');
ylabel('Rxy');
clear y1;
clear n3;
clear n;
y1=fliplr(x);
n3=-fliplr(n1);
rxx=conv(x,y1);
nb=n1(1)+n3(1);
ne=n1(11)+n3(11);
n=nb:ne;
subplot(2,1,2);
stem(n,rxx);
xlabel('n');
ylabel('Rxx');
PLOT
Q.9. A system has the impulse response sequence given as
H(n)=(1/2)n,0<=n<=3
0,Otherwise
Write a Program to compute output of the system, Where input are the following
sequences
(a). x[n] =(-1/2)n*u(n)
(b).x[n]=cos(π*n/16)
(c). A song generated in lab 02 q.6

Program:
n=0:3;
h=(0.5).^n;
n1=0:20;
%For part (a)
x=(-0.5).^n1;
y1=conv(x,h);
clear x;
%For part (b)
x=cos(pi*n/16);
y2=conv(x,h);
clear x;
%For part (c)
t=20;
f=[440 493.88 554.37 587.33 659.26 739.99];
x=sin(2*pi*f*t);
y=conv(x,h);
Q.10.A signal is given by
X[n] = cos(0.025*n)+0.3*cos(0.75*n)
Is filtered using FIR filter represented as
Y[n] = x[n]/6 + x[n-1]/3 + x[n-3]/6 + x[n-2]/3
Determine y[n] and plot x[n] and y[n]

Program:
n=0:20;
x=cos(0.025*n)+0.3*cos(0.75*n);
a=1;
b=[1/6 1/3 1/3 1/6];
y=filter(b,a,x);
subplot(2,1,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
subplot(2,1,2);
n=0:length(y)-1;
stem(n,y);
xlabel('n');
ylabel('y(n)');
PLOT