conv from conv function and ifft

I am trying to find the conv for a specific impulse and signal. Now when I try to use the conv function I ge the answer I need. But when I try to find fft for the impulse and then fft for the signal then .* both fft then ifft the answer I get a different answer. I tried many times any idea why?
Thanks in advance.

回答 (1 件)

Matt J
Matt J 2021 年 1 月 2 日

0 投票

9 件のコメント

Omar Abulayla
Omar Abulayla 2021 年 1 月 2 日
編集済み: Image Analyst 2021 年 1 月 2 日
I tried to convert the cconv to linear conv so I did
l1=length(x);
l2=length(h);
N=max(l1,l2);
xpad=[x zeros(1,N-l1)];
hpad=[h zeros (1,N-l2)];
ccirc = ifft(fft(xpad).*fft(hpad));
I got the exact results from the fft the 1st time, although I am pretty sure its incorrect.
Matt J
Matt J 2021 年 1 月 2 日
N=(l1+l2-1);
Omar Abulayla
Omar Abulayla 2021 年 1 月 2 日
Error using horzcat Dimensions of arrays being concatenated are not consistent.
Matt J
Matt J 2021 年 1 月 2 日
The length has to be l1+l2-1 because that is the expected length of the output with conv().
Omar Abulayla
Omar Abulayla 2021 年 1 月 2 日
I got this error ‘’Error using horzcat Dimensions of arrays being concatenated are not consistent’’
Matt J
Matt J 2021 年 1 月 2 日
The error has nothing to do with the code you've shown, or my proposed modification:
x=rand(1,3); h=rand(1,5);
l1=length(x); l2=length(h);
N=l1+l2-1;
xpad=[x zeros(1,N-l1)];
hpad=[h zeros(1,N-l2)];
ccirc = ifft(fft(xpad).*fft(hpad))
ccirc = 1×7
0.1116 0.2622 0.4966 0.5405 0.5278 0.3675 0.1407
Image Analyst
Image Analyst 2021 年 1 月 2 日
This works fine, so what did you do?
fprintf('Beginning to run %s.m ...\n', mfilename);
% Make random signal.
signalLength = 32;
x = rand(1, signalLength);
% Make impulse function:
h = zeros(1, signalLength);
h(signalLength/2) = 1;
% Pad the signal and kernel.
l1=length(x)
l2=length(h)
N = max(l1,l2)
xpad=[x, zeros(1,N-l1)];
hpad=[h, zeros(1,N-l2)];
ccirc = ifft(fft(xpad).*fft(hpad));
fprintf('Done running %s.m.\n', mfilename);
Matt J
Matt J 2021 年 1 月 2 日
Looks fine. No error messages.
Matt J
Matt J 2021 年 1 月 2 日
編集済み: Matt J 2021 年 1 月 3 日
Please post your code in code wells, so that it can be more easily read, copied, and run.
Aside from that, why are we talking about your early version that doesn't incorporate my modification? I've already told you that that version had insufficient zero-padding for that to work.

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

製品

リリース

R2020a

質問済み:

2021 年 1 月 2 日

編集済み:

2021 年 1 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by