def cocktail(self):
        eps = 0.00000001
        rate1, data1 = wavfile.read(self.path1)
        rate2, data2 = wavfile.read(self.path2)
        if(data1.ndim != 1 or data2.ndim != 1):
            self.alarm("Please Chose another file with 1D data")
        else:
            data1 = data1 - np.mean(data1)
            data1 = data1/max(data1)
            data2 = data2 - np.mean(data2)
            data2 = data2/max(data2)
            signals = [data1, data2]
            matrix = np.vstack(signals)
            whiteMatrix = utl.whitenMatrix(matrix)
            X = whiteMatrix
            vectors = []
            for i in range(0, X.shape[0]):
                vector = FA(X, vectors, eps)
                vectors.append(vector)
                
            
            W = np.vstack(vectors)
            

            S = np.dot(W, whiteMatrix)

            utl.plotSounds([S[0], S[1]], ["source_1", "source_2"], rate1, "plot_results/cocktail_party/song_separation_plot.png")
            wavfile.write("sound_results/cocktail_party/source1.wav" ,rate1, 5000*S[0].astype(np.int16))
            wavfile.write("sound_results/cocktail_party/source2.wav" , rate1, 5000*S[1].astype(np.int16))
            img = pg.QtGui.QGraphicsPixmapItem(pg.QtGui.QPixmap('plot_results/cocktail_party/song_separation_plot.png'))
            self.ui2.widget_party.addItem(img)
            self.ui2.widget_party.invertY(True)
            self.alarm("Check Plot & Sound Results Files")
示例#2
0
# Read the mixed signals
rate1, data1 = wavfile.read('./mixed' + name[0] + '.wav')
rate2, data2 = wavfile.read('./mixed' + name[1] + '.wav')

# Centering the mixed signals and scaling the values as well
data1 = data1 - np.mean(data1)
data1 = data1 / 32768
data2 = data2 - np.mean(data2)
data2 = data2 / 32768

# Creating a matrix out of the signals
signals = [data1, data2]
matrix = np.vstack(signals)

# Whitening the matrix as a pre-processing step
whiteMatrix = utils.whitenMatrix(matrix)

X = whiteMatrix

# Find the individual components one by one
vectors = []
for i in range(0, X.shape[0]):
    # The FastICA function is used as is from FastICA_image.py, and the it works out of the box
    vector = FastICA(X, vectors, eps)
    vectors.append(vector)

# Stack the vectors to form the unmixing matrix
W = np.vstack(vectors)

# Get the original matrix
S = np.dot(W, whiteMatrix)
示例#3
0
eps = 0.00000001

# Read the images from ./images/mixed
names = ["unos", "dos", "tres"]
images = utl.listImages(names, "mixed")

# The images are mean centered
centImages = []
for image in images:
    rescaleImage = image
    centImage = rescaleImage - np.mean(rescaleImage)
    centImages.append(centImage)

# The images are whitened, the helper function is in utilities.py
whiteImages = utl.whitenMatrix(utl.list2matrix(centImages))

# Uncomment the lines below to plot the images after whitening
# utl.plotImages(utl.matrix2list(whiteImages), names, "../white_tranform", True, False)

# The images are now converted into time series data
# X is a 3*image_size matrix, with each row representing a image
X = whiteImages

# Find the individual components one by one
vectors = []
for i in range(0, len(images)):
    vector = FastICA(X, vectors, eps)
    # print vector
    vectors.append(vector)
plt.title("data2")
plt.show()

# Creating a matrix out of the signals
signals = [data1, data2]

plt.figure()
plt.plot(signals[0], signals[1], '*b')
plt.ylabel('Signal 2')
plt.xlabel('Signal 1')
plt.title("Original data")

matrix = np.vstack(signals)

# Whitening the matrix as a pre-processing step
whiteMatrix = utl.whitenMatrix(matrix)

X = whiteMatrix

#Display the whitened matrix
plt.figure()
plt.plot(X[0], X[1], '*b')
plt.ylabel('Signal 2')
plt.xlabel('Signal 1')
plt.title("Whitened data")
plt.show()


# Find the individual components one by one
vectors = []
for i in range(0, X.shape[0]):
def separate_sound3(b, name):
    name = ["1", "2", "3"]
    eps = 0.00000001

    #Read the mixed signals
    rate1, data1 = wavfile.read(b[0])
    rate2, data2 = wavfile.read(b[1])
    rate3, data3 = wavfile.read(b[2])

    #Centering the mixed signals and scaling the values as well
    data1 = data1 - np.mean(data1)
    data1 = data1 / 32768
    data2 = data2 - np.mean(data2)
    data2 = data2 / 32768
    data3 = data3 - np.mean(data3)
    data3 = data3 / 32768

    #Creating a matrix out of the signals
    signals = [data1, data2, data3]
    matrix = np.vstack(signals)

    #Whitening the matrix as a pre-processing step
    whiteMatrix = utl.whitenMatrix(matrix)

    X = whiteMatrix

    #Find the individual components one by one
    vectors = []
    for i in range(0, X.shape[0]):
        #The FastICA function is used as is from FastICA_image.py, and the it works out of the box
        vector = FastICA(X, vectors, eps)
        vectors.append(vector)

    #Stack the vectors to form the unmixing matrix
    W = np.vstack(vectors)

    #Get the original matrix
    S = np.dot(W, whiteMatrix)

    #Unmixing matrix through FOBI
    fobiW = FOBI(X)

    #Get the original matrix using fobiW
    fobiS = np.dot(fobiW.T, whiteMatrix)

    #Plot the separated sound signals
    utl.plotSounds([S[0], S[1], S[2]], ["1", "2", "3"], rate1, "separated")

    #Write the separated sound signals, 5000 is multiplied so that signal is audible
    wavfile.write(
        "C:/SPEECH_SEPARATION--FinalYear/Separated/separate-" + name[0] +
        ".wav", rate1, 5000 * S[0].astype(np.int16))
    wavfile.write(
        "C:/SPEECH_SEPARATION--FinalYear/Separated/separate-" + name[1] +
        ".wav", rate1, 5000 * S[1].astype(np.int16))
    wavfile.write(
        "C:/SPEECH_SEPARATION--FinalYear/Separated/separate-" + name[2] +
        ".wav", rate1, 5000 * S[2].astype(np.int16))

    #Plot the separated sound signals
    utl.plotSounds([fobiS[1], fobiS[0], fobiS[2]], ["1", "2", "3"], rate1,
                   "separated_FOBI")

    #Write the separated sound signals, 5000 is multiplied so that signal is audible
    wavfile.write(
        "C:/SPEECH_SEPARATION--FinalYear/Separated/separate-" + name[0] +
        ".wav", rate1, 5000 * fobiS[1].astype(np.int16))
    wavfile.write(
        "C:/SPEECH_SEPARATION--FinalYear/Separated/separate-" + name[1] +
        ".wav", rate1, 5000 * fobiS[0].astype(np.int16))
    wavfile.write(
        "C:/SPEECH_SEPARATION--FinalYear/Separated/separate-" + name[2] +
        ".wav", rate3, 5000 * fobiS[2].astype(np.int16))