Commit 06c3b71b authored by Marie Tahon's avatar Marie Tahon
Browse files

add diff TF

parent e8f43fae
#!/usr/bin/python3
# Code source by Marie Tahon (2018)
# from original idea of Jean-Marc Chouvel
# cf http://www.ems-network.org/spip.php?article294
# License: ISC
from __future__ import division
import numpy as np
import scipy
import matplotlib.pyplot as plt
import sys, os
import librosa
import librosa.display
import warnings
warnings.filterwarnings(action="ignore", module="scipy", message="^internal gelsd")
BINS_PER_OCTAVE = 12*3
N_OCTAVES = 7
nfft = int(1024*2)
step = int(nfft /2)
if len(sys.argv) < 2:
sys.exit('no audio file')
if len(sys.argv) < 3:
start = 0.0
else:
start = sys.argv[2]
if len(sys.argv) < 4:
duration = None
else:
duration = sys.argv[3]
y, sr = librosa.load(sys.argv[1], offset=start, duration = duration)
## Calculation of differential Fourrier Transform
D_delta = librosa.feature.delta(D**2)
D_time = librosa.istft(np.sqrt(np.abs(D_delta)) * np.exp(np.angle(D)), hop_length = step)
t = np.linspace(0, y.shape[0]*sr, D_time.shape[0])
ty = np.linspace(0, y.shape[0]*sr, y.shape[0])
fig_s = plt.figure(figsize=(12,4))
ax_s0 = fig_s.add_subplot(2,1,1)
librosa.display.specshow(librosa.amplitude_to_db(D, ref=np.max), y_axis='log', sr=sr, hop_length = step, x_axis='time')
ax_s0.set_title('original CQT spectrogram')
ax_s1 = fig_s.add_subplot(2,1,2)
librosa.display.specshow(librosa.amplitude_to_db(D_delta, ref=np.max), y_axis='log', sr=sr, hop_length = step, x_axis='time')
ax_s1.set_title('Differential CQT spectrogram')
plt.tight_layout()
plt.figure()
plt.plot(t, D_time, 'r')
plt.plot(ty, y, alpha=0.5)
plt.xlabel('time (sec.)')
plt.ylabel('amplitude (UA)')
plt.legend(('differential TF', 'original'), loc='upper right')
plt.title('Differential TF')
plt.show()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment