2
    audio_sample, sampling_rate = librosa.load('a.wav', sr=None)

    S = np.abs(librosa.stft(audio_sample, n_fft=1024, hop_length=512, win_length=1024, window=signal.hann))
    
    mag_db = librosa.amplitude_to_db(S)
    mag_n = _normalize(mag_db)
    librosa.display.specshow(mag_n, y_axis='linear', x_axis='time', sr=sampling_rate)

I did some stft and then spechow. but I want to find the point(time) where wave discontinuity.

example) I want to know discontinuity point of the wave file

I mean like this enter image description here

Girish Hegde
  • 1,420
  • 6
  • 16

1 Answers1

1

You just need to use derivatives to find discontinuities in a wave. To take the derivative of the wave we can use convolution with a filter. Here's a sample code:

import numpy as np
import  matplotlib.pyplot as plt

# generating the wave
angle1 = np.linspace(0, 5*np.pi/2, 100)
wave1  = np.sin(angle1)
angle2 = np.linspace(0, 3*np.pi/2)
wave2  = np.sin(angle2)
angle3 = np.linspace(np.pi/2, 2*np.pi)
wave3  = np.sin(angle3)
wave   = np.append(wave1, wave2)
wave   = np.append(wave, wave3)

# differentiation
filter = [-1, 1]
dif    = np.convolve(wave, filter)
absdif = np.abs(dif)
print('discontinuity at:', np.where(absdif > 0.75)[0])

plt.subplot(3, 1, 1)
plt.plot(wave, label='input wave')
plt.subplot(3, 1, 2)
plt.plot(dif, label='dirivative')
plt.subplot(3, 1, 3)
plt.plot(absdif, label='absolut of derivative')

plt.show()

Output graph: enter image description here

Girish Hegde
  • 1,420
  • 6
  • 16
  • can you give me some more guide? i tried but i got these error – sunchul choi Aug 26 '20 at 05:31
  • dif = np.convolve('a.wav', filter) File "<__array_function__ internals>", line 6, in convolve File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\numeric.py", line 817, in convolve return multiarray.correlate(a, v[::-1], mode) ValueError: data type must provide an itemsize – sunchul choi Aug 26 '20 at 05:32
  • You r directly passing file to convolve so it is giving error. First read the .wav file then convert into numpy array and then take derivative using convolve function – Girish Hegde Aug 26 '20 at 09:07