Linear Convolution Of Two Sequences Using MATLAB
Logic used in Linear Convolution Of Two Sequences Using MATLAB
- First, we need to input sequence x1 from the command window and plot it in the figure.
- We need to input sequence x2 value from the command window and plot it the figure.
- 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);
w = conv(
u,v
)
gives the convolution of vectorsu
andv
.
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
- Linear Convolution Basics
- MATLAB Tutorials
MATLAB Tutorials
- Sampling Theorem Verification MATLAB
VHDL Tutorials
- HDL Code To Simulate Full Adder
- HDL Code To Simulate 1-Bit Comparator
- HDL Code to Simulate 8:3 Priority Encoder
- HDL Code To Simulate 4-Bit Binary To Gray Converter
- HDL Code To Simulate 1:4 Demux
The post Linear Convolution Of Two Sequences Using MATLAB appeared first on Techgeetam.com.