legacy/CorrelationCoefficient.py

49 lines
1.3 KiB
Python

#!/usr/bin/env python
# coding: utf-8
import thinkdsp
#segment: ebben a hangmintaban keressuk az eredeti hangmintaval "original_sample" leginkabb korrelalo reszt
#original_sample: az eredeti madarhang minta
# A fuggveny a bemeneti hangmintat mintavetelenkent osszehasonlitja az altalunk keresett hangmintaval es vissza adja annak
# a maximalis korrelaciot.
def calculatecorr(segment,original_sample):
maxcorr = 0
time = 0
#1minta 1 masodperc(framerate szama = utolso elem)
lastsample = segment.framerate
for timestamp in segment.ts[:-lastsample]:
#mindig az adott mintaveteltol szamitott 1mp-es mintat vesszuk
segment_chunk = segment.segment(start=timestamp, duration=1)
#Correlation coefficient two waves.
correlation = original_sample.corr(segment_chunk)
if correlation > maxcorr :
maxcorr = correlation
time = timestamp
print(correlation)
if maxcorr > 0.9:
return maxcorr
break
print("Vegeredmeny:")
print(maxcorr)
print("Masodperc:")
print(time)
return maxcorr
sturnusVulgaris = thinkdsp.read_wave("wavs/sturnus/CommonStarling_100962.wav")
train_sample = sturnusVulgaris.segment(start=4,duration=1)
test_sample = sturnusVulgaris.segment(start=0,duration=5)
calculatecorr(test_sample,train_sample)