-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconvolve
executable file
·24 lines (20 loc) · 872 Bytes
/
convolve
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
import numpy as np
from scipy import signal
def get_maximum_of_convolution(sample_file, ir_file):
sig1 = np.fromfile(sample_file)
sig2 = np.fromfile(ir_file)
sig3 = signal.fftconvolve(sig1, sig2, mode='full')
return max(abs(np.amax(sig3)), abs(np.amin(sig3))), sig3
ir_left = 'convolve_test_ir_left.raw'
ir_right = 'convolve_test_ir_right.raw'
sample_left = 'convolve_test_sample_left.raw'
sample_right = 'convolve_test_sample_right.raw'
left_max, left_raw = get_maximum_of_convolution(sample_left, ir_left)
right_max, right_raw = get_maximum_of_convolution(sample_right, ir_right)
left_right_max = max(left_max, right_max)
left_raw = left_raw * (1.0 / left_right_max)
right_raw = right_raw * (1.0 / left_right_max)
left_raw.tofile('convolve_test_convolve_left.raw')
right_raw.tofile('convolve_test_convolve_right.raw')
print(left_right_max)