Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ James Schloss
Nicole Mazzuca
Marius Becker
Gathros
Jeremie Gillet (- Jie -)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Data.List (tails)

convolution :: (Num a) => [a] -> [a] -> [a]
convolution x = map (sum . zipWith (*) (reverse x)) . spread
where spread = init . tails . (replicate (length x - 1) 0 ++)
16 changes: 9 additions & 7 deletions chapters/mathematical_background/convolutions/convolutions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
</script>
$$
$$
\newcommand{\d}{\mathrm{d}}
\newcommand{\bff}{\boldsymbol{f}}
\newcommand{\bfg}{\boldsymbol{g}}
Expand All @@ -24,13 +24,13 @@ $$
# Convolutions
Alright, I am going to come right out and say it: convolutions can be confusing.
Not only are they hard to really describe, but if you do not see them in practice, it's hard to understand why you would ever want to use them.
I'm going to do what I can to describe them in an intuitive way; however, I may need to come back to this in the future.
I'm going to do what I can to describe them in an intuitive way; however, I may need to come back to this in the future.
Let me know if there is anything here that is unclear, and I'll do what I can to clear it up.

If you take two functions $$f(x)$$ and $$g(x)$$, there are a number of ways you can combine them.
If you take two functions $$f(x)$$ and $$g(x)$$, there are a number of ways you can combine them.
All basic operations can do this (addition, subtraction, multiplication, and division), but there are also special operations that only work with functions and do not work on standard variables or numbers.
For example, $$f \circ g$$ is a *composition* of the two functions, where you plug $$g(x)$$ into $$f(x)$$.
A convolution is another function-related operation, and is often notated with a star ($$*$$) operator, where
A convolution is another function-related operation, and is often notated with a star ($$*$$) operator, where

$$f(x)*g(x)=c(x)$$

Expand Down Expand Up @@ -61,13 +61,15 @@ In code, this looks something like:
{% method %}
{% sample lang="jl" %}
[import:1-17, unindent:"true", lang:"julia"](code/julia/conv.jl)
{% sample lang="hs" %}
[import:1-5, unindent:"true", lang:"haskell"](code/haskell/convolution.hs)
{% endmethod %}

Note that in this case, the output array will be the size of `f[n]` and `g[n]` put together.
Sometimes, though, we have an large size for `f[n]` and a small size for `g[n]`.
In this case `g[n]` is often called a *filter*, and often times when we are using a filter on an array (that might represent an image or some form of data), we want the output array to be the same size as the input.
In this case, rather than outputting a larger array, we often do something special at the borders of the array.
Depending on the situation, this may be necessary.
Depending on the situation, this may be necessary.
Note that there are different methods to deal with the edges in this case, so it's best to do whatever seems right when the situation arises.

### Convolutional Theorem
Expand All @@ -76,9 +78,9 @@ Now, let me tell you about a bit of black computational magic:

**Convolutions can be performed with Fourier Transforms!**

That is crazy!
That is crazy!
It's also incredibly hard to explain, so let me do my best.
As described in the chapter on [Fourier Transforms](chapters/computational_mathematics/FFT/cooley_tukey.md), Fourier Tranforms allow programmers to move from real space to frequency space.
As described in the chapter on [Fourier Transforms](chapters/computational_mathematics/FFT/cooley_tukey.md), Fourier Tranforms allow programmers to move from real space to frequency space.
When we transform a wave into frequency space, we see a single peak in frequency space related to the frequency of that wave.
No matter what function we send into a Fourier Transform, the frequency-space image can be interpreted as a seires of different waves with a specified frequency.

Expand Down