Skip to content

added convolutional theorem implementation in python #869

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

Merged
merged 7 commits 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
@@ -0,0 +1,19 @@
from scipy.fft import fft, ifft
import numpy as np

# using the convolutional theorem
def convolve_fft(signal1, signal2):
return ifft(np.multiply(fft(signal1),fft(signal2)))

# Sawtooth functions
x = [float(i)/200 for i in range(1,101)]
y = [float(i)/200 for i in range(1,101)]

x /= np.linalg.norm(x)
y /= np.linalg.norm(y)

# Convolving the two signals
fft_output = convolve_fft(x, y)

np.savetxt("fft.dat", np.real(fft_output))

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ For this example code, we will be using two sawtooth functions as we did in the
{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/convolutional_theorem.jl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[import, lang:"julia"](code/julia/convolutional_theorem.jl)
[import, lang:"julia"](code/julia/convolutional_theorem.jl)
{% sample lang="py" %}
[import, lang:"python"](code/python/convolutional_theorem.py)

{% sample lang="py" %}
[import, lang:"python"](code/python/convolutional_theorem.py)
{% endmethod %}

This should produce the following output:
Expand All @@ -52,7 +54,6 @@ This should produce the following output:
<img class="center" src="../res/cyclic.png" style="width:75%">
</p>


<script>
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
</script>
Expand Down