How can i cross check convolution in matlab
Show older comments
My x(n)=delta(n) -delta(n-1)-delta(n-2) my h(n)= delta(n)+2delta(n-1)+3delta(n-2)-delta(n-4)
i have convolved them by hand i want to cross check my plot in matlab
how can i do that
Answers (1)
Daniel Shub
on 27 Oct 2011
The hard part is that you want n to go from 0 to N-1, but MATLAB wants n to go from 1 to N. To get around this do everything in terms of m = n+1 and then subtract it off in the end ...
m = 1;
N = 10;
x = zeros(N, 1);
x(m) = 1;
x(m+1) = -1;
x(m+2) = -1;
h = zeros(N, 1);
h(m) = 1;
h(m+1) = 2;
h(m+2) = 3;
h(m+4) = -1;
figure;
subplot(2,2,1);
stem((1:N)-m, x);
title('x');
subplot(2,2,2);
stem((1:N)-m, h)
title('h');
subplot(2,2,3:4);
stem((1:(2*N-1))-m, conv(x,h));
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!