-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.py
More file actions
34 lines (29 loc) · 1.05 KB
/
Test.py
File metadata and controls
34 lines (29 loc) · 1.05 KB
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
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import correlate2d
# Generate example spectrogram data (n_freq, n_time)
n_freq = 128
n_time = 256
spectrogram1 = np.random.rand(n_freq, n_time)
spectrogram2 = np.roll(spectrogram1, shift=(10, 5), axis=(0, 1)) # Shift the spectrogram
# Perform cross-correlation on the spectrograms
cross_correlation = correlate2d(spectrogram1, spectrogram2, mode='same', boundary='wrap')
print(np.shape(spectrogram1))
print(np.shape(cross_correlation))
print(np.shape(spectrogram2))
# Display the original and shifted spectrograms
plt.figure(figsize=(12, 6))
plt.subplot(2, 2, 1)
plt.imshow(spectrogram1, cmap='viridis', aspect='auto', origin='lower')
plt.title('Spectrogram 1')
plt.colorbar()
plt.subplot(2, 2, 2)
plt.imshow(spectrogram2, cmap='viridis', aspect='auto', origin='lower')
plt.title('Spectrogram 2')
plt.colorbar()
plt.subplot(2, 1, 2)
plt.imshow(cross_correlation, cmap='viridis', aspect='auto', origin='lower')
plt.title('Cross-Correlation of Spectrograms')
plt.colorbar()
plt.tight_layout()
plt.show()