Пример #1
0
 def test_windowingSignal(self):
     sig, force, fs, firings = getSignal(1, 30, "../signals/")
     preparedFirings = prepareFiringSignal(firings[0], len(sig[0, 0][0]))
     sdSig = calculateSD(sig)
     signal, label = windowingSig(sdSig, preparedFirings, windowSize=15)
     TestCase.assertTrue(self, len(signal) > 0)
     TestCase.assertTrue(self, len(label) > 0)
Пример #2
0
    def test_featureSelection(self):
        sig, force, fs, firings = getSignal(1, 30, "../signals/")
        sdSig = calculateSD(sig)
        whitenSdSig = calculateWhiten(sdSig)
        preparedFirings = prepareFiringSignal(firings[0], len(sig[0, 0][0]))
        signalWindow, labelWindow = windowingSig(whitenSdSig, preparedFirings, windowSize=124)
        signalWindow, labelWindow = calculateNormalizedOnCorr(signalWindow, labelWindow)
        featureExtracted=extractFeatures(signalWindow)

        TestCase.assertTrue(self, len(featureExtracted) > 0)
Пример #3
0
 def test_train_test_split(self):
     sig, force, fs, firings = getSignal(1, 30, "../signals/")
     preparedFirings = prepareFiringSignal(firings[0], len(sig[0, 0][0]))
     sdSig = calculateSD(sig)
     signalWindow, labelWindow = windowingSig(sdSig, preparedFirings, windowSize=15)
     X_train, X_test, y_train, y_test = trainTestSplit(signalWindow, labelWindow, 0.7)
     TestCase.assertTrue(self, len(X_train) > 0)
     TestCase.assertTrue(self, len(X_test) > 0)
     TestCase.assertTrue(self, len(y_train, ) > 0)
     TestCase.assertTrue(self, len(y_test) > 0)
Пример #4
0
 def test_CKC(self):
     sig, force, fs, firings = getSignal(1, 30, "../signals/")
     sdSig = calculateSD(sig)
     whitenSdSig = calculateWhiten(sdSig)
     preparedFirings = prepareFiringSignal(firings[0], len(sig[0, 0][0]))
     signalWindow, labelWindow = windowingSig(whitenSdSig, preparedFirings, windowSize=124)
     index = 50
     Rx = autocorr(signalWindow[index])
     t = pinv(Rx) @ signalWindow[index]
     plt.plot(t[1, :])
     plt.show()
     TestCase.assertTrue(self, len(t) > 0)
Пример #5
0
def prepareDataWithForce(sig, force):
    sdSig = calculateSD(sig)
    sdSig = butter_bandpass_filter(sdSig, 20, 450, fs2)
    # sdSig = calculateICA(sdSig, 64)

    signalWindow, labelWindow = windowingSig(
        sdSig, force, windowSize=maxFeatures)  # should be divideable to 4

    # signalWindow = calculateFFTOnWindows(signalWindow)
    labelWindow = calculateForceAverage(labelWindow)
    # signalWindow, labelWindow = calculateNormalizedOnCorr(signalWindow, labelWindow)
    # signalWindow, labelWindow = calculateICA(signalWindow, labelWindow, 4)

    # signalWindow = extractPhaseSpace(signalWindow)
    # signalWindow = extractSoundFeatures(signalWindow)

    return signalWindow, labelWindow
Пример #6
0
def prepareData(sig, firings):
    sdSig = calculateSD(sig)
    # sdSig = calculateICA(sdSig, 64)
    sdSig = butter_bandpass_filter(sdSig, 20, 450, 2048)
    sizeInputSignal = sdSig.shape[1]
    preparedFirings = prepareFiringSignal(firings[0], sizeInputSignal)
    signalWindow, labelWindow = windowingSig(
        sdSig, preparedFirings,
        windowSize=maxFeatures)  # should be divideable to 4
    # signalWindow = calculateFFTOnWindows(signalWindow)
    labelWindow = calculateCdr(labelWindow)
    # signalWindow, labelWindow = calculateNormalizedOnCorr(signalWindow, labelWindow)
    # signalWindow, labelWindow = calculateICA(signalWindow, labelWindow, 4)

    signalWindow = extractPhaseSpace(signalWindow)
    # signalWindow = extractSoundFeatures(signalWindow)

    return signalWindow, labelWindow
    def prepareData(self, sig, firings):
        sdSig = calculateSD(sig)
        sdSig = scale(sdSig, axis=0)

        # sdSig = calculateICA(sdSig, 64)
        sdSig = butter_bandpass_filter(sdSig, 20, 450, 2048)
        sizeInputSignal = sdSig.shape[0]
        preparedFirings = prepareFiringSignal(firings[0],
                                              sizeInputSignal,
                                              numSignals=12)
        signalWindow, labelWindow = windowingSig(
            sdSig.transpose(), preparedFirings,
            windowSize=256)  # should be divideable to 4
        # signalWindow = calculateFFTOnWindows(signalWindow)
        # labelWindow = convertLabel2OneDimentional(labelWindow)
        # signalWindow, labelWindow = calculateNormalizedOnCorr(signalWindow, labelWindow)
        # signalWindow, labelWindow = calculateICA(signalWindow, labelWindow, 18)

        # signalWindow = extractPhaseSpace(signalWindow)
        # signalWindow = extractSoundFeatures(signalWindow)
        return signalWindow, np.asarray(labelWindow)
Пример #8
0
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv1D, MaxPooling1D
from keras.optimizers import SGD, RMSprop
from keras.layers.advanced_activations import LeakyReLU

import numpy as np

from Utils.SignalUtils import getSignal, calculateSD, prepareFiringSignal, windowingSig, trainTestSplit, \
    calculateCdr, calculateNormalizedOnCorr

sig, force, fs, firings = getSignal(1, 30, "../signals/")
sdSig = calculateSD(sig)
# sdSig = calculateICA(sdSig, 64)
sizeInputSignal = sdSig.shape[1]
preparedFirings = prepareFiringSignal(firings[0], sizeInputSignal)
signalWindow, labelWindow = windowingSig(sdSig, preparedFirings, windowSize=8)  # should be divideable to 4
labelWindow = calculateCdr(labelWindow)
signalWindow = calculateNormalizedOnCorr(signalWindow)
x_train, x_test, y_train, y_test = trainTestSplit(signalWindow, labelWindow, 0.7)
# convert to one-hot vector
# y_train = to_categorical(y_train)
# y_test = to_categorical(y_test)

signal_size_row = x_train[0].shape[0]
signal_size_col = x_train[0].shape[1]
x_train = np.reshape(x_train, [-1, signal_size_row, signal_size_col])
x_test = np.reshape(x_test, [-1, signal_size_row, signal_size_col])
input_shape = (signal_size_row, signal_size_col)

model = Sequential()
model.add(Conv1D(16, 5, padding='same', input_shape=input_shape))
Пример #9
0
 def test_save_data_as_images(self):
     sig, force, fs, firings = getSignal(1, 30, "../signals/")
     preparedFirings = prepareFiringSignal(firings[0], len(sig[0, 0][0]))
     sdSig = calculateSD(sig)
     signalWindow, labelWindow = windowingSig(sdSig, preparedFirings, windowSize=15)
     saveDataAsImage(signalWindow, labelWindow)