Skip to content

Commit

Permalink
small changes to convolutional theorem chapter and code to make thing…
Browse files Browse the repository at this point in the history
…s more reproduceable (#872)
  • Loading branch information
leios authored Oct 10, 2021
1 parent 448a796 commit 7c19ec6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FFTW
using LinearAlgebra
using DelimitedFiles

# using the convolutional theorem
Expand All @@ -8,11 +9,9 @@ end

function main()

# Random distribution in x
x = rand(100)

# Gaussian signals
y = [exp(-((i-50)/100)^2/.01) for i = 1:100]
# sawtooth functions for x and y
x = [float(i)/200 for i = 1:200]
y = [float(i)/200 for i = 1:200]

# Normalization is not strictly necessary, but good practice
normalize!(x)
Expand All @@ -22,6 +21,10 @@ function main()
fft_output = convolve_fft(x, y)

# outputting convolutions to different files for plotting in external code
writedlm("fft.dat", fft_output)
# note: we are outputting just the real component because the imaginary
# component is virtually 0
writedlm("fft.dat", real(fft_output))

end

main()
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ Also note that the Fourier Transform is a periodic or cyclic operation, so there

## Example Code

For this example code, we will be using two sawtooth functions as we did in the chapter on [one-dimensional convolutions](../1d/1d.md):

{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/convolutional_theorem.jl)
{% endmethod %}

This should produce the following output:

<p>
<img class="center" src="../res/cyclic.png" style="width:75%">
</p>


<script>
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
</script>
Expand All @@ -54,6 +63,11 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);

The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).

##### Images/Graphics

- The image "[Cyclic](../res/cyclic.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).


##### Text

The text of this chapter was written by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
Expand Down

0 comments on commit 7c19ec6

Please sign in to comment.