Merge pull request #11 from username-still-not-available/added-missing-function

added missing function
This commit is contained in:
Logan Williams
2021-10-21 11:49:24 +02:00
committed by GitHub
2 changed files with 32 additions and 221 deletions

View File

@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "raw",
"id": "gross-fever",
"id": "needed-surface",
"metadata": {},
"source": [
"Notebook extracts ENF signal by pyenf_extraction application\n",
@@ -12,7 +12,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "complete-exchange",
"id": "endangered-scott",
"metadata": {
"scrolled": true,
"tags": []
@@ -21,146 +21,35 @@
"source": [
"!wget https://github.com/ghuawhu/ENF-WHU-Dataset/blob/master/ENF-WHU-Dataset/H1/002.wav?raw=true\n",
"!wget https://github.com/ghuawhu/ENF-WHU-Dataset/blob/master/ENF-WHU-Dataset/H1_ref/002_ref.wav?raw=true\n",
"!git clone https://github.com/deerajnagothu/pyenf_extraction"
]
},
{
"cell_type": "raw",
"id": "fixed-aging",
"metadata": {},
"source": [
"pip install scipy==1.1.0\n",
"pip install numpy==1.21.0\n",
"pip install matplotlib==3.4.2\n",
"pip install librosa==0.8.1"
"!git clone https://github.com/deerajnagothu/pyenf_extraction\n",
" \n",
"!pip install scipy==1.1.0\n",
"!pip install numpy==1.21.0\n",
"!pip install matplotlib==3.4.2\n",
"!pip install librosa==0.8.1"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "premier-minimum",
"id": "failing-upset",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import numpy as np"
"import numpy as np\n",
"from lib import extract_enf_signal"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "regular-boundary",
"metadata": {},
"outputs": [],
"source": [
"sys.path.append('./pyenf_extraction/')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "remarkable-ready",
"id": "helpful-employer",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n",
"11\n",
"12\n",
"13\n",
"14\n",
"15\n",
"16\n",
"17\n",
"18\n",
"19\n",
"20\n",
"21\n",
"22\n",
"23\n",
"24\n",
"25\n",
"26\n",
"27\n",
"28\n",
"29\n",
"30\n",
"31\n",
"32\n",
"33\n",
"34\n",
"35\n",
"36\n",
"37\n",
"38\n",
"39\n",
"40\n",
"41\n",
"42\n",
"43\n",
"44\n",
"45\n",
"46\n",
"47\n",
"48\n",
"49\n",
"50\n",
"51\n",
"52\n",
"53\n",
"54\n",
"55\n",
"56\n",
"57\n",
"58\n",
"59\n",
"60\n",
"61\n",
"62\n",
"63\n",
"64\n",
"65\n",
"66\n",
"67\n",
"68\n",
"69\n",
"70\n",
"71\n",
"72\n",
"73\n",
"74\n",
"75\n",
"76\n",
"77\n",
"78\n",
"79\n",
"80\n",
"81\n",
"82\n",
"83\n",
"84\n",
"85\n",
"86\n",
"87\n",
"88\n",
"89\n"
]
},
{
"name": "stderr",
"output_type": "stream",
@@ -168,102 +57,6 @@
"/Users/radekludacka/miniconda3/envs/enf/lib/python3.7/site-packages/numpy/core/fromnumeric.py:1970: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
" result = asarray(a).shape\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n",
"11\n",
"12\n",
"13\n",
"14\n",
"15\n",
"16\n",
"17\n",
"18\n",
"19\n",
"20\n",
"21\n",
"22\n",
"23\n",
"24\n",
"25\n",
"26\n",
"27\n",
"28\n",
"29\n",
"30\n",
"31\n",
"32\n",
"33\n",
"34\n",
"35\n",
"36\n",
"37\n",
"38\n",
"39\n",
"40\n",
"41\n",
"42\n",
"43\n",
"44\n",
"45\n",
"46\n",
"47\n",
"48\n",
"49\n",
"50\n",
"51\n",
"52\n",
"53\n",
"54\n",
"55\n",
"56\n",
"57\n",
"58\n",
"59\n",
"60\n",
"61\n",
"62\n",
"63\n",
"64\n",
"65\n",
"66\n",
"67\n",
"68\n",
"69\n",
"70\n",
"71\n",
"72\n",
"73\n",
"74\n",
"75\n",
"76\n",
"77\n",
"78\n",
"79\n",
"80\n",
"81\n",
"82\n",
"83\n",
"84\n",
"85\n",
"86\n",
"87\n",
"88\n",
"89\n"
]
}
],
"source": [
@@ -273,8 +66,8 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cutting-click",
"execution_count": 3,
"id": "genuine-grass",
"metadata": {},
"outputs": [],
"source": [

View File

@@ -0,0 +1,18 @@
import sys
from io import StringIO
from pyenf_extraction.pyenf import pyENF
def extract_enf_signal(wav_file_path):
mysignal = pyENF(filename=wav_file_path, nominal=50, harmonic_multiples=8, duration=0.1, strip_index=0)
x, fs = mysignal.read_initial_data()
spectro_strip, frequency_support = mysignal.compute_spectrogam_strips()
sys.stdout = StringIO()
weights = mysignal.compute_combining_weights_from_harmonics()
sys.stdout = sys.__stdout__
OurStripCell, initial_frequency = mysignal.compute_combined_spectrum(
spectro_strip, weights, frequency_support
)
return mysignal.compute_ENF_from_combined_strip(OurStripCell,initial_frequency)