Commit cf306722 authored by LucasDANIELE's avatar LucasDANIELE
Browse files

ajout des f0

parent 9ddf8f20
......@@ -9,6 +9,9 @@ Created on Thu Mar 25 10:04:06 2021
from scipy.io import wavfile
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import blackmanharris, correlate
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
def listen(nom,sampleRate, data):
wavfile.write(nom, sampleRate, data.real)
......@@ -116,6 +119,19 @@ def garderUniquementCris(sampleRate,tMin, tMax, dataCut):
if((len(dataCut[i])>nSamplesMin) & (len(dataCut[i])<nSamplesMax)):
res.append(dataCut[i])
return res
def parabolic(f, x):
xv = 1/2. * (f[x-1] - f[x+1]) / (f[x-1] - 2 * f[x] + f[x+1]) + x
yv = f[x] - 1/4. * (f[x-1] - f[x+1]) * (xv - x)
return (xv, yv)
def freq_from_fft(sig, fs):
windowed = sig * blackmanharris(len(sig))
f = rfft(windowed)
i = argmax(abs(f)) # Just use this for less-accurate, naive version
true_i = parabolic(log(abs(f)), i)[0]
return fs * true_i / len(windowed)
......
......@@ -50,8 +50,7 @@ fcts.listen("extraitSansSilence.wav", samplerate, dataSansSilence)
################################################
dataCut = fcts.decouperExtraits(dataSansSilence)
print(len(dataCut))
print("____________")
################################################
# Support temporel uniquement cris
################################################
......@@ -61,9 +60,9 @@ for i in range(len(dataCutCris)):
plt.plot(dataCutCris[i], "-")
plt.show()
fcts.listen("cri"+str(i)+".wav", samplerate, np.asarray(dataCutCris[i]))
print("enregistrement: " + str(i))
print(np.round(fcts.freq_from_fft(np.asarray(dataCutCris[i]),samplerate)))
print("________________")
......
Markdown is supported
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