フィルターのクリア

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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by