# Why i am not getting same convolution plots?

I am trying to implement convolution using fourier transform property but i am not getting exactly same shape of output that i get by using conv command

First portion of graph obtained using conv command is same as that obtained using fourier transform property but second portion of graph obtained using conv command is inverted as compared to that obtained using fourier transform property

My MATLAB code is below

clc;clear;close all
syms t w
x = exp(-t).*cos(2*pi*t).*heaviside(t);
h = exp(-t).*heaviside(t);
X = fourier(x, w);
H = fourier(h, w);
X1 = ifourier(X*H, t);
ezplot(X1, [-2 2 -0.1 0.15]);
title('using fourier technique')
t=-1:0.01:1
x = exp(-t).*cos(2*pi*t).*heaviside(t);
h = exp(-t).*heaviside(t);
figure
y=conv(h,x)*0.01
plot(y)
title('using conv command')


• Does this answer your question? Why is circular convolution used in DSP? Why not linear convolution? Commented Mar 28 at 10:44
• Linear convolution in the frequency domain requires overlap-add/save or equivalent algorithm. Commented Mar 28 at 13:40
• @Hilmar, It does not require. It can be done with proper padding.
– Royi
Commented Mar 29 at 16:49
• @Royi: probably semantics: I would consider this a special case for overlap add with a single frame. Commented Mar 30 at 11:58

The problem is your use of Matlab's conv function. You compute your signals over a time interval of [-1,1], but are presenting the convolution over the interval of [-2,2]. To return a convolution that big, Matlab is padding your signals with zeros automatically, which is what is causing the result outside your range of data that is perplexing you. Look at the Matlab help document for conv and notice the shape argument, which you need to pass 'valid' for rather than letting it default to 'full', you need to pass your first signal computed over the interval [-4,4], and you need to pass your second signal computed over the interval [-2,2]. This will solve your problem. You would notice the same artefact on the left if your functions were non-zero there, but the fact that they're zero means it just so happens that Matlab's zero padding on that side is equal to the function values. Here is some Matlab code that produces the result you expected:

t = -4:0.01:4; h = exp(-t).*heaviside(t);
t = -2:0.01:2; x = exp(-t).*cos(2*pi*t).*heaviside(t);
y = conv(h,x,'valid')*0.01;


The convolution you compute in the frequency domain is fine as you are using the Fourier transform of a continuous function, which extends for all time, and therefore the comments on circular convolution do not apply (circular convolution is an artefact of the discrete Fourier transform, which inherently assumes that the finite period transformed is repeating for all time).

As a suggestion that might help further understanding, think about what Matlab is doing as it computes the convolution, which is it takes your first signal and multiplies it by a time reversed version of your second signal, and where they don't overlap, uses values of zero for the signals, then sums all elements, then time shifts and repeats. The different shape argument for Matlab's convolution function corresponds to telling Matlab which section to keep. The 'full' shape means it keeps everything. The 'valid' shape means it only keeps convolution results where the longer signal fully overlaps the shorter signal. Moreover, it then becomes apparent that your "convolution technique" is only a numerically integrated approximation of your "Fourier technique", and that it is only possible because your signals are zero over the interval (-inf, 0), which allows the section of the convolution you show to be computed using a finite dataset.

• I have tried to go through your answer multiple times. Your provided code has solved issue but I am confused why you choose different time intervals for two signals? Commented May 22 at 19:25
• If I use exactly same time interval for both signals, wether the interval is -2:2 or -4:4, my plot is blank Commented May 22 at 19:40
• If you call Matlab's conv function with two same length signals and ask for the 'valid' shape, then it will return a single value. It might help to think that the shorter signal is like a book resting on top of a table which is the longer signal, and that the book is being slid from one end of the table to the other. If the length of the book is the same as the table, then it has nowhere to slide. Commented May 22 at 22:52
• As an alternative, you could use the 'same' shape argument and use the same time interval of [-2, 2], which works because the first half of each signal is zero. Commented May 22 at 23:07

What you need to do is pad the signals properly.
By padding you'll be able to extract the inner part of the circular convolution applied by the frequency domain multiplication.

You may have a look at Show Equivalence Between Multiplication in Time Domain to Convolution in Frequency Domain.

• Can you please specify,which signal i need to pad,x,h or y? and pad with zeros or ones? Commented Mar 31 at 10:45
• I have checked your suggested link that shows use of fft command but i am trying to use fourier command as my signals are continous time signals Commented Mar 31 at 10:49