필터 지우기
필터 지우기

issues with indexing in a convolution calculation

조회 수: 3 (최근 30일)
justin stephens
justin stephens 2018년 2월 27일
so here is my issue. When i compute the convolution of x[n]= -delta[n+1] + 0.5 delta[n] + 2 delta[n-1] with h[n]= 2 delta[n] + delta[n-1] i am getting the correct amplitudes but at the wrong position. here is what i am getting,
y[n]= -2delta[n+1] + 4.5 delta [n+3] + 2 delta[n+4] where is should be getting
y[n]= -2 delta[n+1] + 4.5 delta[n-1] + 2 delta[n-2].
here is my code:
if true
% code
function [y] = myconv( x,h )
m=length(x);
n=length(h);
x=[x,zeros(1,m)];
h=[h,zeros(1,n)];
for i=1:(n+m-1)
y(i)=0;
for j=1:m
if(i-j+1>0) && (i-j+1<m)
y(i)=y(i)+x(j)*h(i-j+1);
else
end
end
en
stem(y,'filled');%grid
% plot the resulting sequence y[n]
title('convolution of two sequence') % add title to the plot
ylabel('y[n]=x[n]*h[n]')
% label the y-axis
xlabel('index,[n]')
end
any help would be greatly appreciated!!!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by