フィルターのクリア

convolve two signals using coonv, filter, cconv, freq domain multiplication (this one gives a wrong answer)

1 回表示 (過去 30 日間)
DDD
DDD 2015 年 5 月 26 日
コメント済み: Matt J 2015 年 5 月 26 日
only the last one is not giving me an equal answer.
u=@(n)1.0.*(n>=2);
y=@(n)abs(2.*n+1).*(u(n+1)-u(n-5));
n_x=1:10;
n_y=-2:20;
y_n=u(n_y);
x_n=y(n_x);
c=conv(x_n,y_n);
n_c= n_x(1)+n_y(1):n_x(end)+n_y(end);
figure()
%
subplot(4,1,1)
stem(n_c,c)
xlabel('n')
xlim([-3,15])
title('u(n) * |2n+1|(u(n+1)-u(n-5)) using conv')
%
cf=filter(x_n,1,y_n);
cf=[cf,zeros(1,length(n_c)-length(cf))];
subplot(4,1,2)
stem(n_c,cf)
xlabel('n')
xlim([-3,15])
title('u(n) * |2n+1|(u(n+1)-u(n-5)) using filter')
%
cc=cconv(y_n,x_n);
subplot(4,1,3)
stem(n_c,cc)
xlabel('n')
xlim([-3,15])
title('u(n) * |2n+1|(u(n+1)-u(n-5)) using cconv')
subplot(4,1,4)
z=ifft(fft(x(-2:20)).*fft(y(-2:20)));
stem(-2:20 ,z);
xlabel('n')
title('u(n) * |2n+1|(u(n+1)-u(n-5)) multiplying in frequency domain')
what is wrong?
Thanks
  1 件のコメント
Matt J
Matt J 2015 年 5 月 26 日
Maybe you're not running the code that you think you are The indexing expression
x(-2:20)
is not legal, because of the negative indices. You should be getting an error message.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by