In [1]:
# imports libraries
import os
import sys
import glob
#import scipy.io.wavfile
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
#import importlib

%matplotlib inline 

# Grabs the preprocessing and automatic_sync files
sys.path.append(os.path.join(os.getcwd(),'pythonCode'))
import preprocessing as pp
import automatic_sync as autoS

In [59]:
rawDataPath = os.path.join(os.getcwd(),'rawData')
files = glob.glob(os.path.join(rawDataPath,'*.wav'))
names = []
        
for name in files:
    fileName = os.path.basename(name).split(".")[0]
    names.append(fileName)

# Determines which cameras will be selected (['Bents'],['Camera Location'],['Motion #'])

filt = (['B1'],['SL'],['12']) # Selects the bent 1 cameras during motion 18

# Applies filter to camera names and returns only selected subset names
audioFiles = pp.getKeys(names,filt);

# Reads the .wav files from the list generted by getKeys
(names,cDataset) = pp.readWAV(rawDataPath,audioFiles);


Opening GP_B1_SL_12 ...

In [70]:
def test_shift(signal,shift):
    ''' Bool = test_shift(signal,shift) Tests the find_offset function by:
        (1) Takes a signal size (N,) as input
        (2) Aritifically shifts signal by counts input into function
        (3) Calls the find_offset function to determine signal offsets
        (4) Returns "True" if the identified offset = input shift
            Returns "False" if the identified offset != input shift
    '''
    # makes some "phony" data
    phonyData = {}
    phonyData['Original'] = np.transpose(np.vstack((signal,signal)))
    
    if shift < 0:
        # negtive shift
        phonyData['Shifted'] = np.vstack((np.zeros((abs(shift),2)),phonyData['Original'])) 
    else:
        # positive shift
        phonyData['Shifted'] = phonyData['Original'][shift:,:] 
        
    phonyOffsets = autoS.find_offset(phonyData,'Original',['Shifted'])

    #print(phonyOffsets) # prints the offsets in counts
    if phonyOffsets['Shifted'] == shift:
        return True
    else:
        return False

In [71]:
print(test_shift(cDataset[names[0]][:,0],-200))
print(test_shift(cDataset[names[0]][:,0],300))


True
True

In [ ]: