Linear Convolution Of Two Sequences Using MATLAB

By | December 7, 2017
Spread the love

Linear Convolution Of Two Sequences Using MATLAB

Logic used in Linear Convolution Of Two Sequences Using MATLAB

  1. First, we need to input sequence x1 from the command window and plot it in the figure.
  2. We need to input sequence x2 value from the command window and plot it the figure.
  3. We have to find convolution by conv function. We have to display its output to the command window and plot this signal in the figure.

MATLAB Program To Find Linear Convolution  

%1)Enter the input sequence x1 from  command window	
x1=input('Enter first sequence')
	
n1=0:length(x1)-1;	
subplot (2,2,1);	
stem(x1);	
xlabel('time index n');	
ylabel('amplitude ');	
title('plot of x1');	

%2)Enter the input sequence x2 from command window	
x2=input('Enter second sequence');
	
n2=0:length(x2)-1;	
subplot (2,2,2);	
stem(x2);	
xlabel('time index n');	
ylabel('amplitude ');	
title('plot of x2');

%3)Convolve x1 and x2 to find y  
y=conv(x1,x2);	
disp('linear convolution of x1 & x2 is y=');

% display in command window
disp(y);

	                                 
subplot(2,1,2);	
stem(y);	
xlabel('time index n');	
ylabel('amplitude ');	
title('convolution output');

Basics To Understand The Linear Convolution Of Two Sequences Using MATLAB

subplot(m,n,p)
  • Divides figure into m rows and n columns, p represents the axes specified for that subplot.
  • The first subplot is the first column of the first row, the second subplot is the second column of the first row, and so on.
  • In this case, subplot(4,1,1)- In entire figure, 4 rows, 1 column ,and its position is 1.
plot(x,y)
  • 2D line plot of data y v/s x.( plot is used only for analog signal).
title, xlabel, ylabel
  • title represents the title of a subplot.
  • xlabel represents the X-axis name.
  • ylabel represents y-axis name.
stem(n1, x1n)
  • It plots data sequences of n1 at a specified value of x1n.
  • stem is used only for a discrete sequence.
figure
  • It is used to get the second sequence.

MATLAB Predefined Functions used in Linear Convolution Of Two Sequences

w = conv(u,v);

Explanation of Each Step involved in Linear Convolution Of Two Sequences Using MATLAB

1) Enter the input sequence x1 from command window
% command window	
x1=input('Enter first sequence')
  
n1=0:length(x1)-1;	
subplot (2,2,1);	
stem(x1);	
xlabel('time index n');	
ylabel('amplitude ');	
title('plot of x1');
  • We have to input x1 sequence from the command window.
  • For plotting, we need time index.
  • If you see the output figure you will understand the time index.
  • n1=0:length(x1)-1;   n1 is time vector running from 0 to 3. If length(x1)=4.
  •  So, the first sample is at 0, the second sample is at 1, the third sample is at 2, the fourth sample is at 3.
  • Understand the difference between stem, plot.
  • The plot is used to plot analog signal.
  • Stem is used to plot data sequences.
  • stem(x1) means plotes data sequence x1, extend along baseline x-axis.
  • If you see the output figure, x1 is in the 1st row, 1st column.
  • x2 is in the 1st row, 2nd column.
  • output convolution is in the 2nd row.
  • Remeber this statement to get clarity on subplot: The first subplot is the first column of the first row, the second subplot is the second column of the first row, and so on.
  • Now you can understand, subplot(2,2,1) means 2rows, 2columns, its position is the 1st subplot. Now read the statement above.
3) Convolve x1 and x2 to find y
y=conv(x1,x2);	
disp('linear convolution of x1 & x2 is y=');

% display in command window
disp(y);
  • We use conv function to find convolution of x1 and x2.
  • To diplay the output, we use disp function.

Output of linear convolution of two sequences using MATLAB

Related Blogs

  1.  Linear Convolution Basics
  2.  MATLAB Tutorials

MATLAB Tutorials

  1. Sampling Theorem Verification MATLAB

VHDL Tutorials

  1. HDL Code To Simulate Full Adder
  2. HDL Code To Simulate 1-Bit Comparator
  3. HDL Code to Simulate 8:3 Priority Encoder
  4. HDL Code To Simulate 4-Bit Binary To Gray Converter
  5. HDL Code To Simulate 1:4 Demux

Spread the love
Category: Electronics MATLAB Tutorials

About Manojkumar M M

Manojkumar is a Digital Marketing Expert from Bangalore, India. He has got 3 years of experience in the field of Digital Marketing. He worked with many start-ups to help them in improving their Business Lead Generation through online. He blogs about digital marketing tips, technology updates, programming language tips at this blog Techgeetam.com. Contact me for any kind of help in the field of Digital Marketing. Mail Id - digimanoj98@gmail.com

Leave a Reply

Your email address will not be published.