Reputation: 128
I'm trying to convolve a rectangular pulse with itself by taking the Fourier transform, squaring it, and then taking the inverse Fourier transform. I realize there is a conv() function but I would prefer to do it in the frequency domain for future, more complex problems. My problem is that when I do this, it does not produce a triangular function as expected. The code I'm using is below:
clc
clear all
x=-5:.01:5;
y=rectangularPulse(x);
Y=fft(y);
H=Y.^2;
h=ifft(H);
plot(x,h)
Upvotes: 0
Views: 1191
Reputation: 933
You need to zeropad in order to ensure that the convolution is linear. Currently you are performing a circular convolution. Try something like this:
y = ones(100,1);
N = length(y);
Nfft = 2*length(y) - 1;
Y=fft(y,Nfft);
H=Y.^2;
h=ifft(H);
plot(h);
Upvotes: 2