Skip to content

Commit

Permalink
added convolutional theorem implementation in python (#869)
Browse files Browse the repository at this point in the history
* added convolutional theorem implementation in python

* fixed chapter linking

* added comments to the code

* changed random distribution to sawtooth

* corrected previous commit

* fixed comments

Co-authored-by: James Schloss <jrs.schloss@gmail.com>
  • Loading branch information
pillarxyz and leios authored Oct 10, 2021
1 parent 7c19ec6 commit 46bf5a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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)
{% 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

0 comments on commit 46bf5a3

Please sign in to comment.