Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

MATLAB ASSIGNMENT

1. Write a program for -

a) Addition b) Subtraction c) Convolution of two sequences.

ANS:
A) Addition
x=input('Enter the first sequence');
subplot(3,1,1);
stem(x);
title('X');
y=input('Enter the second sequence');
subplot(3,1,2);
stem(y);
title('Y');
z=x+y;
subplot(3,1,3);
stem(z);
title('Z=X+Y');

OUTPUT

Enter the first sequence[3 5 6 8 7]


Enter the second sequence[6 9 4 3 2]
b) Subtraction

x=input('Enter the first sequence');


subplot(3,1,1);
stem(x);
title('X');
y=input('Enter the second sequence');
subplot(3,1,2);
stem(y);
title('Y');
z=x-y;
subplot(3,1,3);
stem(z);
title('Z=X-Y');

OUTPUT
Enter the first sequence[6 5 9 8]
Enter the second sequence[2 6 9 4]
c)Convolution

x=input('Enter the first sequence');


subplot(3,1,1);
stem(x);
title('X');
y=input('Enter the second sequence');
subplot(3,1,2);
stem(y);
title('Y');
z=conv(x,y);
subplot(3,1,3);
stem(z);
title('Convolution');

OUTPUT

Enter the first sequence[1 2 4 1]

Enter the second sequence[2 5 4 8]


2. Generate following signals using MATLAB.

a) Unit step signal

b) Ramp signal

c) Impulse signal

ANS: Generation of unit step, Ramp and Impulse signal.

t = (-1:0.1:3)';

impulse = t==0;
unitstep = t>=0;
ramp = t.*unitstep;
figure(1); stem(t,impulse);
figure(2); stem(t,unitstep);
figure(3); stem(t,ramp);

Impulse signal
Unit Step signal

Ramp Signal
3. Perform following operations on any signal.

a) Shifting

Ans:
Shifting Operation
clc;
clear all;
close all;
x=input('Enter the sequence of x(n)');
xl=input('Enter the lower limit of x(n)');
d=input('Enter the number of samples to be delayed');
a=input('Enter the number of samples to be advanced');
l=length(x);
xu=l+xl-1;
p=xl:1:xu;
subplot(4,1,1);
stem(p,x);
title('Graph of x(n)');
subplot(4,1,2);
stem(-p,x);
title('Graph of x(-n)');
q=(xl+d):1:(xu+d);
subplot(4,1,3);
stem(q,x);
title('Graph of delayed sequence of x(n)');
r=(xl-a):1:(xu-a);
subplot(4,1,4);
stem(r,x);
title('Graph of advanced sequence of x(n)');

You might also like