Skip to content

Commit c8a0702

Browse files
committed
added convolutional theorem implementation in python
1 parent 4bb16db commit c8a0702

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from scipy.fft import fft, ifft
2+
import numpy as np
3+
4+
def convolve_fft(signal1, signal2):
5+
return ifft(np.multiply(fft(signal1),fft(signal2)))
6+
7+
8+
x = np.random.rand(100)
9+
y = [np.exp(-((i-50)/100)**2/.01) for i in range(1,101)]
10+
11+
x /= np.linalg.norm(x)
12+
y /= np.linalg.norm(y)
13+
14+
fft_output = convolve_fft(x, y)
15+
np.savetxt("fft.dat", fft_output)
16+

contents/convolutions/convolutional_theorem/convolutional_theorem.md

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ Also note that the Fourier Transform is a periodic or cyclic operation, so there
4444
[import, lang:"julia"](code/julia/convolutional_theorem.jl)
4545
{% endmethod %}
4646

47+
48+
{% method %}
49+
{% sample lang="py" %}
50+
[import, lang:"python"](code/python/convolutional_theorem.py)
51+
{% endmethod %}
52+
53+
4754
<script>
4855
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
4956
</script>

0 commit comments

Comments
 (0)