Stem time convolution using conv, filter, cconv and multiplication in frequency domain
조회 수: 1 (최근 30일)
이전 댓글 표시
It is asked to graph time convolution using conv, filter, cconv and multiplication in frequency domain. All the answers seem to agree except the multiplication in frequency domain. What is wrong with it? Any suggestions?
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_n).*fft(y_n));
stem(n_ ,z);
xlabel('n')
xlim([-3,15])
title('u(n) * |2n+1|(u(n+1)-u(n-5)) multiplying in frequency domain')
Thanks
댓글 수: 0
답변 (1개)
Nalini Vishnoi
2015년 5월 20일
Hi,
Your last section when executed gave error because you are multiplying two vectors (element by element) when they are of different lengths. The correct way to use 'fft' to perform 'convolution' is the following:
% ensures the vectors being multiplied are of the same size/length
z=ifft(fft(x_n, numel(n_c)).*fft(y_n, numel(n_c)));
stem(n_c,z);
I hope this helps.
Nalini
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!