# Convolution of Signal with a Gaussian Filter / Kernel

Following up on Analytical Solution for the Convolution of Signal with a Box Filter, I am now trying to convolve a Gaussian filter with the sine signal by hand.

My method is to use the definition of convolution and attempt to integrate: \begin{align*} \overline{\phi} &= \phi(x) * h(x) = \int_{-\infty}^{+\infty} \! \phi(x') h(x - x') \, \mathrm{d} x' \\ \Rightarrow \overline{\phi} &= \int_{-\infty}^{+\infty} \! \sin(x') \left( \frac{6}{\pi \Delta^2} \right)^{1/2} \exp(-\frac{6 (x - x')^2}{\Delta^2}) \, \mathrm{d} x' \\ \overline{\phi} &= \left( \frac{6}{\pi \Delta^2} \right)^{1/2} \int_{-\infty}^{+\infty} \! \sin(x') \exp(-\frac{6 (x - x')^2}{\Delta^2}) \, \mathrm{d} x' \\ \end{align*} At this stage, the integration seems impossible by hand (e.g., integration by parts).

I also tried moving to wave space by taking Fourier transforms and instead using multiplication:

\begin{align*} \mathscr{F}\{\phi(x)*h(x)\} &= \mathscr{F}\{\phi(x)\} \cdot \mathscr{F}\{h(x)\} \\ \end{align*}

I get the Fourier transform of sine as $$\sqrt{\pi/2} i (\delta(k - 1) - \delta(k + 1)$$, but am not sure how to multiply this with the exponential and how the inverse Fourier transform will work. Am I missing something clever and/or elegant? Is such a solution possible? I don't have a good understanding of the Dirac delta and how to multiply it with an exponential in wave space.

• short question, between line one and two, when inserting the Gaussian filter, what happened to your argument $(x-x')$? – Irreducible Oct 11 '19 at 6:27
• Why are you trying to do it in Frequency Domain? Probably, speed wise, you'd better do that on time domain and it is easier. – Royi Oct 11 '19 at 8:54
• @Irreducible -- Typo--good catch. Thanks. – coffeecake Oct 11 '19 at 11:51
• @Royi -- thanks for the input. I can definitely stay in the time domain if it's easier--I just can't figure out the integration by hand. – coffeecake Oct 11 '19 at 11:53
• Why do you need analytical solution? – Royi Oct 11 '19 at 12:37

If you have an implementation you want to validate the best way to do it is by validating it versus a reference implementation.

For instance, the above, in MATLAB, would be something like:

% Setting the Grid Parameters
leftBound = -10;
rightBound = 10;
numSamples = 10000;

% Signals Parameters
gaussianKernelStd   = 2;
gaussianKernelMean  = -1; %<! Basically its shift on the grid
sineAmp             = 0.1;
sineFreq            = 1;
sinePhase           = 0;

% Generating the grid
vX = linspace(leftBound, rightBound, numSamples + 1);
vX = vX(:);

samplingInterval    = mean(diff(vX));
samplingFrequency   = 1 / samplingInterval;

% Generating the Sine Signal
vS = sineAmp * sin((2 * pi * sineFreq * vX) + sinePhase);
% Generating the Gaussian Kernel
vK = exp(-((vX - gaussianKernelMean) .^ 2) / (2 * gaussianKernelStd * gaussianKernelStd));
vK = vK / sum(vK * samplingInterval); %<! Normalization

vY = conv(vS, vK, 'same');

figure();
% plot(vX, vK);
% figure();
% plot(vX, vS);
plot(vX, [vS, vK, vY], 'LineWidth', 2);
legend({['Sine Signal'], ['Gaussian Kernel'], ['Convolution Result']});


The result is given by: • Very helpful. Thanks for taking the time to put this together. – coffeecake Oct 13 '19 at 18:25

Hint: any sine, convolved by a linear kernel, yields a sine with the same frequency (and a different amplitude or phase). This is a fundamental property of linear systems, thus of convolutive filters. Hence, you only have to find the amplitude. Luckily, there is a close-form solution for the integral of a Gaussian function:

$$\int_{-\infty}^\infty e^{-f x^2 + g x + h}\,dx=\sqrt{\frac{\pi}{f}}\,\exp\left(\frac{g^2}{4f} + h\right)$$

by pluging in Euler's formula: $$\sin(x')=\frac{\exp( \imath x')-\exp(- \imath x')}{2\imath}$$ into $$\int_{-\infty}^{+\infty} \! \exp(\pm \imath x')\exp(-\frac{6 (x - x')^2}{\Delta^2}) \, \mathrm{d} x'$$

• Thank you for the answer. Based on this hint, I was able to find a nice closed-form solution, which aligns nicely with the discrete numerical approach I wrote. – coffeecake Oct 13 '19 at 18:26
• Do not hesitate to share, I was lazy enough to avoid the computation – Laurent Duval Oct 13 '19 at 18:36