Commit f92492b2 authored by Candre Nathan's avatar Candre Nathan
Browse files

Modification freq_from_HPS : résolution out of bounds

parent 3e46a6ca
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 26 09:45:25 2021
@author: lucasdaniele
"""
#%%
from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt
import fcts as fcts
import importlib
import frequency_estimator.frequency_estimator as f0
importlib.reload(fcts)
importlib.reload(f0)
################################################
# Extraction des données
################################################
#%%
bEnSec = (0*60+0)
duree = 500
samplerate, dataLR = wavfile.read("input/male.wav")#On lit le fichier qui a des infos oreille gauche, oreille droite
dataL = dataLR[:,0]#On recupère que le son de l'oreille gauche
T = 1/samplerate
b = int(round(bEnSec*samplerate))
n = int(round(duree*samplerate))
t = np.linspace(bEnSec, bEnSec+n*T, n)
data = dataL[b:n+b]#On recupere n echantillons depuis b soit depuis bEnSec --> Support temporel
################################################
# Support temporel sans modifs
################################################
#%%
fcts.aff("Support temporel sans modifs",t,data)
fcts.listen("output/extrait.wav", samplerate, data)
################################################
# Support temporel signal découpé
################################################
#%%
dataCut = fcts.decouperExtraits(data)
print(str(len(dataCut))+" cris")
################################################
# Support temporel uniquement cris
################################################
#%%
dataCutCris = fcts.garderUniquementCris(samplerate,0.5,1.5,250,2000,f0.freq_from_HPS, dataCut)
freqArray = []
for i in range(len(dataCutCris)):
fcts.aff("cri"+str(i), t, np.asarray(dataCutCris[i]))
fcts.listen("output/cri"+str(i)+".wav", samplerate, np.asarray(dataCutCris[i]))
print("enregistrement: " + str(i))
print(np.round(f0.freq_from_HPS(np.asarray(dataCutCris[i]),samplerate)))
freqArray.append(f0.freq_from_HPS(np.asarray(dataCutCris[i]),samplerate))
print("________________")
print(np.mean(freqArray))
print(np.std(freqArray))
# %%
......@@ -21,15 +21,15 @@ def aff(titre,x,y):
else:
plt.plot(y.real, "-")
plt.title(titre)
plt.show();
plt.show()
def decouperExtraits(data):
DATA=[]
cut=[]
onAir=False
step=10000
step=5000
k=0
seuil=1500
seuil=2500
for i in range(step,len(data)):
if ((abs(data[i])<seuil) & onAir):
if(k<step):
......@@ -59,6 +59,7 @@ def garderUniquementCris(sampleRate,tMin, tMax, fMin, fMax, f0Func, dataCut):
freq = np.round(f0Func(np.asarray(dataCut[i]),sampleRate))
if((freq>fMin) & (freq<fMax)):
res.append(dataCut[i])
return res
......
File added
File added
File added
File added
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