Search code examples
matlabsignal-processingconvolution

Why convolution obtained from matlab differs from what is obtained theoretically?


Theoretical result for convolution of an exponential function with a sinusoidal function is shown below.

enter image description here

When I plot the function directly using matlab, I get this, Direct plot of the analytical result

However Matlab conv command yields this, Plot obtained from Matlab

The two plots look similar but they are not the same, see the scales. The matlab yield is ten times of the theoretical result. Why?

The matlab code is here.

clc;
clear all;
close all;
t = 0:0.1:50;
x1 = exp(-t);
x2 = sin(t);
x = conv(x1,x2);
x_theory = 0.5.*(exp(-t) + sin(t) - cos(t));

figure(1)
subplot(313), plot(t, x(1:length(t))); subplot(311), plot(t, x1(1:length(t))); subplot(312), plot(t, x2(1:length(t)))

figure(2)
subplot(313), plot(t, x_theory); subplot(311), plot(t, x1(1:length(t))); subplot(312), plot(t, x2(1:length(t)))

Solution

  • conv does discrete-time convolution, it does not do the mathematical integral function. Numerically, this basically means multiplying and adding the result of the two signals many times, once for each point, with a small shift of one of the signals.

    If you think about this, you will realize that the sampling of the signals will have an effect. i.e. if you have a point every 0.1 values, or 0.001 values, the amount of points you multiply is different, and thus the result is different in value (not in shape).

    Therefore, every time you do numerical convolution, you always need to multiply with the sampling rate, to "normalize" the operation.

    Just change your code to do

    sampling_rate= 0.1;
    t = 0:sampling_rate:50;
    x = conv(x1,x2)*sampling_rate;