0% found this document useful (0 votes)
26 views7 pages

Write A Program For - A) Addition B) Subtraction C) Convolution of Two Sequences

The document describes a MATLAB assignment to write programs for addition, subtraction, and convolution of sequences. It also provides code to generate unit step, ramp, and impulse signals, and perform shifting operations on signals. The assignment includes taking input sequences, plotting the original and processed signals, and outputting the results of the mathematical operations.

Uploaded by

Shivani waje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Write A Program For - A) Addition B) Subtraction C) Convolution of Two Sequences

The document describes a MATLAB assignment to write programs for addition, subtraction, and convolution of sequences. It also provides code to generate unit step, ramp, and impulse signals, and perform shifting operations on signals. The assignment includes taking input sequences, plotting the original and processed signals, and outputting the results of the mathematical operations.

Uploaded by

Shivani waje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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