diff --git a/contents/convolutions/convolutional_theorem/code/julia/convolutional_theorem.jl b/contents/convolutions/convolutional_theorem/code/julia/convolutional_theorem.jl index 31a504eaf..9016bf3d8 100644 --- a/contents/convolutions/convolutional_theorem/code/julia/convolutional_theorem.jl +++ b/contents/convolutions/convolutional_theorem/code/julia/convolutional_theorem.jl @@ -1,4 +1,5 @@ using FFTW +using LinearAlgebra using DelimitedFiles # using the convolutional theorem @@ -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) @@ -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() diff --git a/contents/convolutions/convolutional_theorem/convolutional_theorem.md b/contents/convolutions/convolutional_theorem/convolutional_theorem.md index 0063c992c..7aa5c3fdf 100644 --- a/contents/convolutions/convolutional_theorem/convolutional_theorem.md +++ b/contents/convolutions/convolutional_theorem/convolutional_theorem.md @@ -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: + +
+ +
+ + @@ -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).