-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added convolutional theorem implementation in python (#869)
* 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
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
contents/convolutions/convolutional_theorem/code/python/convolutional_theorem.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters