Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
120 views1 page

Convolution Using For Loop

This document demonstrates how to perform convolution using a for loop in MATLAB. It defines two signals, x[n] and h[n], plots them, then uses a nested for loop to calculate their convolution y[n] = x[n]*h[n] sample by sample and plot the result.

Uploaded by

dfbbvcx
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)
120 views1 page

Convolution Using For Loop

This document demonstrates how to perform convolution using a for loop in MATLAB. It defines two signals, x[n] and h[n], plots them, then uses a nested for loop to calculate their convolution y[n] = x[n]*h[n] sample by sample and plot the result.

Uploaded by

dfbbvcx
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/ 1

Convolution Using For loop

clc;
clear all;
close all;
x = [0.5 1.5 0.5]; %Defining x[n]
subplot(1,3,1);
stem(x);
xlabel('n-->');
ylabel('x[n]-->');
xlim([-4,4]);
ylim([0,3]);
h = [1 1 1]; %Defining h[n]
subplot(1,3,2);
stem(h);
xlabel('n-->');
ylabel('h[n]-->');
xlim([-4,4]);
ylim([0,3]);
n = 3;
y = zeros(1,n); %Convolving x[n] and h[n]
for i = 1:n
for j = 1:i
y(i) = y(i) + x(j)*h(i-j+1); %Defining y[n] = x[n]*h[n]
end
end
subplot(1,3,3);
stem(y);
xlabel('n-->');
ylabel('y[n]-->');
xlim([-4,4]);
ylim([0,3]);

You might also like