Convolution: MATLAB Script For Convolution of A Discrete Signal With Impulse Response
Convolution: MATLAB Script For Convolution of A Discrete Signal With Impulse Response
Convolution: MATLAB Script For Convolution of A Discrete Signal With Impulse Response
m = length(x);
n = length(h);
for i = 1:n+m-1
y(i) = 0;
for j = 1:m
if (i-j+1>0)
end
end
end
disp(y)
suptitle('Convolution of 2 sequences');
xlabel('time');
ylabel('1st sequence');
subplot(3,1,2); // plot in 3*1 matrix at (2,1) position
stem(h);
xlabel('time');
ylabel('2nd sequence');
stem(y);
xlabel('time');
ylabel('Convoluted sequence');
Example:
[3 8 0 8 6 4 6 8 3 8 4 8 6]
[3 5 3 9 3 3]
Convoluted sequence is
9 39 49 75 139 99 152 144 145 147 163 137 175 123 126 90 42 18
MATLAB Script for Convolution of a signal with impulse response :
m = length(x);
n = length(h);
for i = 1:n+m-1
y(i) = 0;
for j = 1:m
if (i-j+1>0)
end
end
end
disp(y)
suptitle('Correlation of 2 sequences');
stem(x);
xlabel('time');
ylabel('1st sequence');
subplot(3,1,2); //plot in 3*1 matrix at (2,1) position
stem(h);
xlabel('time');
ylabel('2nd sequence');
stem(y);
xlabel('time');
ylabel('Correlated sequence');
Example:
[1 2 3 4 5]
[4 0 9 4]
Correlated sequence is
4 17 30 47 64 57 16 20
[1 2 9 4 5 7 3 8 7 4 9 0 5 0 6 9 6 3 8 0]
[3 4 7 6 8 8 7 4]
Correlated sequence is
Columns 1 through 21
4 15 58 103 142 186 205 247 264 273 283 263 255 221 198 218 213 236 229
239 211
Columns 22 through 27
178 120 86 41 24 0
MATLAB Script for Correlation of two input signals:
Y = sin(x);
H = cos(h);
m = length(x);
n = length(h);
X = [x,zeros(1,n)];
H = [h,zeros(1,m)];
for i = 1:n+m-1
y(i) = 0;
for j = 1:m
if (i-j+1>0)
y(i) = y(i)+Y(j)*H(i-j+1);
end
end
end
disp('Correlated sequence is')
disp(y);
suptitle('Correlation of 2 sequences');
subplot(3,1,1);
plot(Y);
xlabel('time');
ylabel('1st sequence');
subplot(3,1,2);
plot(H);
xlabel('time');
ylabel('2nd sequence');
subplot(3,1,3);
plot(y);
xlabel('time');
ylabel('Correlated sequence');
[0:0.01:pi]
[0:0.01:pi]
Difference b/w Convolution and Correlation:
Correlation is measuring how similar two signals are to each other, and convolution is a filtering
operation