Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small changes to convolutional theorem chapter #872

Merged
merged 1 commit into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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