Experiment 3
Experiment 3
Experiment 3
Aim: To calculate and plot the convolution of two sequence.
Theory: Convolution is a fundamental operation in digital signal processing used
to combine two sequences to form a third sequence. Convolution helps in
determining the output of a system when an input signal and the system's
impulse response are known. It’s widely used in digital filtering, where the input
signal is convolved with a filter's impulse response to produce the filtered output.
This operation essentially involves the sliding of one sequence over another and
computing the weighted sum at each step. The convolution of two discrete-time
sequences x[n]x[n] and h[n]h[n] is denoted as y[n]y[n] and is given by the
equation:
∞
y [ n]= ∑ x [ k ] . h[n−k ]
k=−∞
Code:
x=[1 2 4 5]; end
h=[2 3 1]; end
x=input('Enter x: '); disp(y);
h=input('Enter h: '); y1=conv(x,h);
lenx=length(x); disp(y1);
lenh=length(h); stem(x,'Color','r','LineWidth',5);
leny=lenx+lenh-1; hold on;
y=zeros(1,leny); stem(h,'Color','b','LineWidth',3);
for n=1:leny hold on;
for k=1:lenh stem(y,'Color','g','LineWidth',1);
if n-k+1>0 && n-k+1<=lenx hold on;
y(n)=y(n)+x(n-k+1)*h(k); legend('x','h','y');
end hold off;
Output: