-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_manualConvolution.py
executable file
·48 lines (39 loc) · 1.46 KB
/
12_manualConvolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Author: Can Metan
# GPL v3 License
# ____________________________________________________________________________
# In this script, we will manually convolve two signals. The manual convolution
# code is in the "common.py" file. So this script checks the integrity of the
# function and compares with the speed of the convolution provided by numpy.
# ____________________________________________________________________________
import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack
from scipy import signal
import sys
import common
import time
# Assert that the user is using python above version 3.1
assert sys.version_info >= (3, 1)
# Testing code from the Richard Lyons Signal Processing book version 3.
xk = [1.0, 2.0, 3.0]
hk = [1.0, 1.0, 1.0, 1.0]
resultingList = common.convolve(hk, xk)
print('Convolving x(k): ', xk)
print('with h(k): ', hk)
print("\nIn-house convolution function result: ", resultingList)
print("\nStandard convolution function result: ", np.convolve(xk, hk).tolist())
print('\nTime it takes to run 1000000 in-house convolutions:')
start_time = time.time()
i = 0
while (i < 1000000):
resultingList = common.convolve(hk, xk)
i += 1
print(time.time() - start_time)
print('\nTime it takes to run 1000000 standard convolutions:')
start_time = time.time()
i = 0
while (i < 1000000):
resultingList = np.convolve(xk, hk).tolist()
i += 1
print(time.time() - start_time)
print('\nWeird!')