Looking for a BSS algorithm that works with Real World audio recordings
I am looking for a Blind Audio Source Separation algorithm that I can use to reconstruct human voices from real world recordings. My application is simultaneously recording 2 people speaking using 2 microphones and saving the recordings as mono audio files.
I have tried several implementations of FastICA (including FastICA Package for MATLAB from Aalto University, scikit learn BSS using FastICA, and several other university professors’ implementations) and a couple DUET implementations, but none have worked to separate real world recordings of 2 speakers. I know that FastICA fails when there is delay between the sources, which would be true in the real world so I am not surprised that FastICA did not work for me. Also, DUET makes the assumption that the sources are in separate frequency bands, which is not true of human voices.
Several of the algorithms have been able to separate the “manual mixing” case (speakers are recorded separately and then linearly mixed together using MATLAB). However my project requires that the voices be recorded simultaneously in real time.
I have come across others who seem to be looking for similar algorithms (Real World Blind Source Separation), and I am aware that there are other algorithms (Jade, AMUSE). My understanding is that JADE is another ICA algorithm so I expect that I would get results similar to the results I got from FastICA.
I was wondering if anyone had a BSS algorithm that has worked for reconstructing real world audio samples and could post a link to it. My project is running on a Unixbased OS that does not have MATLAB so preferably the algorithm is not coded for MATLAB, but I have access to MATLAB on another computer so I could still work with it.
Thanks!
See also questions close to this topic

Keras Lambda Layer Before Embedding: Use to Convert Text to Integers
I currently have a
keras
model which uses anEmbedding
layer. Something like this:input = tf.keras.layers.Input(shape=(20,) dtype='int32') x = tf.keras.layers.Embedding(input_dim=1000, output_dim=50, input_length=20, trainable=True, embeddings_initializer='glorot_uniform', mask_zero=False)(input)
This is great and works as expected. However, I want to be able to send text to my model, have it preprocess the text into integers, and continue normally.
Two issues:
1) The Keras docs say that Embedding layers can only be used as the first layer in a model: https://keras.io/layers/embeddings/
2) Even if I could add a
Lambda
layer before theEmbedding
, I'd need it to keep track of certain state (like a dictionary mapping specific words to integers). How might I go about this stateful preprocessing?In short, I need to modify the underlying Tensorflow DAG, so when I save my model and upload to ML Engine, it'll be able to handle my sending it raw text.
Thanks!

PySpark: Sort or OrderBy DataFrame Column *Numerically* not working correctly
I have some fitness data that I'm trying to sort numerically, however the results are not turning out as the manual, and other examples, e.g. Spark DataFrame groupBy and sort in the descending order (pyspark), show:
display(df.sort(col("Calories Burned").desc()))#fails to sort correctly, shows 876, then 4756, display(df.orderBy("Calories Burned", ascending = False))#fails to sort correctly, shows 876, then 4756 display(df.sort(desc("Calories Burned")))
All these examples display the following two columns data (there are more columns, but I'm abbreviating for space):
Date Calories Burned 20181018 876 20180526 4756 20180505 4440
As you can see, these are not sorting numerically. Spark isn't taking the number of digits into account, so 876 appears before 4756.
Whether or not I include the
col
function makes no difference, either.How can this dataset be sorted numerically so the data looks more like this?
Date Calories Burned 20180526 4756 20180505 4440 20181018 876

Turtle is not reacting to onkeypress [SOLVED]
So, I am new in python so I took some time and watched some videos about how to make a simple "snake" game, I was doing everything that dude was saying, but when it came to the keyboard binding something went wrong and I can't move my turtle..
code:
https://pastebin.com/GLSRNKLRimport turtle import time delay = 0.1 # Screen wn = turtle.Screen() wn.title("Snake Game By AniPita") wn.bgcolor('black') wn.setup(600, 600) wn.tracer(0) # Snake Head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("white") head.penup() head.goto(0, 0) head.direction = "stop" # Functions def go_up(): head.direction == "up" def go_down(): head.direction == "down" def go_left(): head.direction == "left" def go_right(): head.direction == "right" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 10) if head.direction == "down": y = head.ycor() head.sety(y  10) if head.direction == "left": x = head.xcor() head.setx(x  10) if head.direction == "right": x = head.xcor() head.setx(x + 10) # Keyboard Bindings wn.onkeypress(go_up(), 'w') wn.onkeypress(go_down(), 's') wn.onkeypress(go_left(), 'a') wn.onkeypress(go_right(), 'd') wn.listen() # Main Game while True: wn.update() time.sleep(delay) move() wn.mainloop()

Efficient algorithm for grouping variablelength tuples
I am trying to devise an efficient algorithm for grouping a sequence of tuples of integers of any length, such as:
[(), (1,), (1,1), (1,2), (2,), (2,1,1), (2,1,2), (2,2)]
The grouping rule, in Python for example, is the following:
def tupleSameGroup(tuple1, tuple2): sameGroup = True for index in range(min(len(tuple1), len(tuple2))): if tuple1[index] != tuple2[index]: sameGroup = False return sameGroup
In rough words, if one tuple is a "subset" of another matching from the beginning, they are the same group. An empty tuple is in the same group as any tuple.
Based on this rule, I want my algorithm to produce as output a list of all unique groups of tuples; so a list of list of tuples, where within the inner list the tuples are all in the same group, but between there is a pair that is not. For the above example, the desired output is:
[[(), (1,), (1,1)], [(), (1,), (1,2)], [(), (2,), (2,1,1)], [(), (2,), (2,1,2)], [(), (2,), (2,2)]]
Any help would be much appreciated! Thank you.

Algorithm question: finding next non overlapping interval
Lets say we have a list of interval sorted by start point in ascending order. we want an algorithm to find for each interval, the next nonoverlapping interval with smallest start point.
For example we have list of interval as {(1,5), (2,4), (4, 6),(6, 10)}, for 0th interval (1, 5), the nearest nonoverlapping interval is 3rd interval which is (6, 10), for 1st (2,4) it should be 2nd (4,6). Therefore the desired output is [3, 2, 3, 1].
I can come up with an brute force O(N^2) algorithm which is to do linear scan for each interval. But I think there might exist an O(N) algorithm, anyone know the is there a better solution for this problem?

Datastructure to store database record
I want to store employees record. I don't want to use any external libraries or framework. I am trying to build the data structure from scratch.
There will be three fields,
EmployeeName Age Salary
We also want to query like,
Get all the salary where EmployeeName = "Bill" Get all the EmployeeName where salary > 2000 Get all the Salary where age='50'
I am open to use any language but not any builtin package. What is the recommended datastructure to achieve it ?

How to loop through an n x n matrix and replace values in MATLAB?
I have an n x n matrix in MATLAB. I am trying to iterate through each row and column of this matrix. If the value in each element is higher than a certain threshold, I want to replace that element with a 1. If the value in each element is lower than a certain threshold, I want to replace that element with a 0.
I am trying to use two for loops, but it's not leading me anywhere.Any suggestions?

How solve this MILP problem with Pulp Python module?
I think I'm facing a Milp problem but I'm not sure.
The problem in a simplified form is:
There are 3 suppliers of materials (trucks) for 3 cities. The real problem is 30 Suppliers and 100 cities...
Supliers capacity: a:1; b:2; c:3.
Cities Demand: a:2; b:3; c:1
Distances Supplier(Cities): a(a:2;b:4;c:6)
 b(a:4;b:2;c:4)
 c(a:6;b:4;c:2)
like this with each Capacity and Demand
Sa1  Ca2
Sb2  Cb3
Sc3  Cc1
The goal its optimize the suply but there is one (devil) condition: Just one supplier per city.
Whitout the contidion the problem is a simple problem to solve with basic Linear Programming.
With the condition I think that could be solved with Mixed Integer Linear Programming  MILP. But not figure it out how to solve this with MILP Method and Pulp (python module).If someone can help me
Thanks!My first try
from scipy.optimize import linprog c = [2,4,6,4,2,4,6,4,2] Ae = [[1,1,1,0,0,0,0,0,0], [0,0,0,1,1,1,0,0,0], [0,0,0,0,0,0,1,1,1], [1,0,0,1,0,0,1,0,0], [0,1,0,0,1,0,0,1,0], [0,0,1,0,0,1,0,0,1], ] be = [1,2,3,2,3,1] x0_bounds = (0,None) x1_bounds = (0,None) x2_bounds = (0,None) x3_bounds = (0,None) x4_bounds = (0,None) x5_bounds = (0,None) x6_bounds = (0,None) x7_bounds = (0,None) x8_bounds = (0,None) sol = linprog(c, A_eq= Ae, b_eq = be, bounds = ((x0_bounds,x1_bounds,x2_bounds,x3_bounds,x4_bounds,x5_bounds,x6_bounds,x7_bounds,x8_bounds)) ) print(sol) fun: 18.0 message: 'Optimization terminated successfully.' nit: 10 slack: array([], dtype=float64) status: 0 success: True x: array([1., 0., 0., 0., 2., 0., 1., 1., 1.]) Process finished with exit code 0

How to pass 2d array from java to matlab(R2018b) using JMI package and get results back from matlab to java?
I want to implement SVD, PCA and LDA algorithms using java and matlab. I am extracting data and forming a 2D matrix using java, which then I want to pass to matlab's svd, pca functions. However, I am getting error in matlab as "First input must be single or double."
I am establishing javamatlab communication as (using JMI package) 
MatlabProxyFactory factory = new MatlabProxyFactory(); MatlabProxy proxy = factory.getProxy(); String path ="cd(Matlab path)"; proxy.eval(path);
For instance, my 2D array is created like this 
double [][] A = new double[][] {{1.0,2.0,3.0},{4.0,5.0,6.0},{7.0,8.0,9.0}};
My matlab function is written as 
function svd1(A) [U,S,V] = svd(A); end
Now, I am calling matlab function from java as 
proxy.feval("svd1",(Object) A);
This is working fine when I pass one dimensional array but failing in case of 2D arrays.
Any pointers on how to pass 2D array from java to matlab and how to get results back will be really helpful.

Call odeint inside Python class
I am trying to call the odeint inside a method in a python class:
from scipy.integrate import odeint
class Test:
@staticmethod def mathfunc(y, t arg1, arg2): x , xdot = y #some equations return xdot, xddot def numericalsim(self, y0, t): y = odeint(mathfunc, y0, t, args(self.param1, self.param2)) return y
However, I get the error: name 'mathfunc' is not defined. Please can you help me in calling odeint inside a class.

Scipy gives wrong result for matrix multiplication
I am using
scipy
to do matrix multiplication of sparse matrix. For some reason,.power()
method doesn't work for sparse matrix. I have checked it using three methods:Here's my code:
import scipy as sp import scipy.sparse
Method1: Plain matrix multiplication
row = np.array([0, 3, 1, 0]) col = np.array([0, 3, 1, 2]) data = np.array([4, 5, 7, 9]) P1 = sp.sparse.coo_matrix((data, (row, col)), shape=(4, 4)) #Method 1 P1.power(4).todense() #gives wrong result
Result:
matrix([[ 256, 0, 6561, 0], #6561 isn't right [ 0, 2401, 0, 0], [ 0, 0, 0, 0], [ 0, 0, 0, 625]], dtype=int32)
Method 2:
P = P1.copy() #calculate ^4 for loop in range(2): P = P.dot(P) P.todense()
Output
matrix([[ 256, 0, 576, 0], [ 0, 2401, 0, 0], [ 0, 0, 0, 0], [ 0, 0, 0, 625]], dtype=int32)
Method3
P1.dot(P1).dot(P1).dot(P1).todense()
Output:
matrix([[ 256, 0, 576, 0], [ 0, 2401, 0, 0], [ 0, 0, 0, 0], [ 0, 0, 0, 625]], dtype=int32)
Method 4:
One can check the result at this website (symbolab.com)
Other threads on this topic (Elementwise power of scipy.sparse matrix, Matrix power for sparse matrix in python), focus on how to do matrix multiplication. I'd appreciate any help.

How can I modify a pandas dataframe I'm iterating over?
I know  this is verboten. But when optimize.curve_fit hits a row of (maybe 5) identical values, it quits and returns a straight line.
I don't want to remove ALL duplicates, but I thought I might remove the middle member of any identical triplets, without doing too much damage to the fit.
So I wanted to use iterrows, and drop rows as I go, but I understand I may be working on a copy, not the original.
Or, I could just do an oldfashioned loop with an index.
How can I do this safely, and in such a way that the end parameter of the loop is updated each time I do a deletion?
Here's an example:
i = 1 while i < len(oneDate.index)1: print("triple=",oneDate.at[i1,"Nprem"],oneDate.at[i,"Nprem"],oneDate.at[i+1,"Nprem"]) if oneDate.at[i,"Nprem"]==oneDate.at[i1,"Nprem"] and oneDate.at[i,"Nprem"]==oneDate.at[i+1,"Nprem"]: print("dropping i=",i,oneDate.at[i,"Nprem"]) oneDate.drop([i]) oneDate = oneDate.reset_index(drop=True) pause() else: i = i +1
I assumed that when I dropped and reset, the next item would move into the deleted slot, so I wouldn't have to increment the index. But it didn't, so I got an infinite loop.

Superpowered: can't get TimeStretching to work correctly, the output sound is distorted
I'm trying to use the Superpowered SDK to apply a realtime Time Stretching and Pitch Shifting on an mp3 file which is being played and also recorded at the same time. The problem is that no matter what I do the output sound quality is terrible (to the point of it being distorted).
I suspect that it's due to the conflicting samples per frame number. Here is the complete source code of my cpp file:static SuperpoweredAndroidAudioIO *audioIO; static SuperpoweredTimeStretching *stretching; static SuperpoweredAudiopointerList *outputBuffers; static SuperpoweredDecoder *decoder; static SuperpoweredRecorder *recorder; const char *outFilePath; const char *tempFilePath; static short int *intBuffer; static float *playerBuffer; bool audioInitialized = false; bool playing = false; static bool audioProcessing( void *__unused clientData, // custom pointer short int *audio, // buffer of interleaved samples int numberOfFrames, // number of frames to process int __unused sampleRate // sampling rate ) { if (playing) { unsigned int samplesDecoded = decoder>samplesPerFrame; if (decoder>decode(intBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) return false; if (samplesDecoded < 1) { playing = false; return false; } SuperpoweredAudiobufferlistElement inputBuffer; inputBuffer.samplePosition = decoder>samplePosition; inputBuffer.startSample = 0; inputBuffer.samplesUsed = 0; inputBuffer.endSample = samplesDecoded; inputBuffer.buffers[0] = SuperpoweredAudiobufferPool::getBuffer(samplesDecoded * 8 + 64); inputBuffer.buffers[1] = inputBuffer.buffers[2] = inputBuffer.buffers[3] = NULL; SuperpoweredShortIntToFloat(intBuffer, (float *) inputBuffer.buffers[0], samplesDecoded); stretching>process(&inputBuffer, outputBuffers); if (outputBuffers>makeSlice(0, outputBuffers>sampleLength)) { while (true) { int numSamples = 0; float *timeStretchedAudio = (float *) outputBuffers>nextSliceItem(&numSamples); if (!timeStretchedAudio) break; SuperpoweredFloatToShortInt(timeStretchedAudio, intBuffer, (unsigned int) numSamples); SuperpoweredShortIntToFloat(intBuffer, playerBuffer, (unsigned int) numSamples); recorder>process(playerBuffer, (unsigned int) numSamples); SuperpoweredFloatToShortInt(playerBuffer, audio, (unsigned int) numSamples); }; outputBuffers>clear(); return true; }; } return false; } extern "C" JNIEXPORT void Java_com_example_activities_DubsmashActivity_InitAudio( JNIEnv __unused *env, jobject __unused obj, jint bufferSize, jint sampleRate, jstring outputPath, jstring tempPath ) { decoder = new SuperpoweredDecoder(); outputBuffers = new SuperpoweredAudiopointerList(8, 16); outFilePath = env>GetStringUTFChars(outputPath, 0); tempFilePath = env>GetStringUTFChars(tempPath, 0); } extern "C" JNIEXPORT jdouble Java_com_example_activities_DubsmashActivity_OpenFile( JNIEnv *env, jobject __unused obj, jstring filePath) { const char *path = env>GetStringUTFChars(filePath, 0); decoder>open(path); intBuffer = (short int *) malloc(decoder>samplesPerFrame * 2 * sizeof(short int) + 32768); playerBuffer = (float *) malloc(decoder>samplesPerFrame * 2 * sizeof(short int) + 32768); audioIO = new SuperpoweredAndroidAudioIO( decoder>samplerate, decoder>samplesPerFrame, false, true, audioProcessing, NULL, 1, 1, decoder>samplesPerFrame * 2 ); stretching = new SuperpoweredTimeStretching(decoder>samplerate); stretching>setRateAndPitchShift(1, 0); recorder = new SuperpoweredRecorder( tempFilePath, decoder>samplerate, 1, 2, false, recorderStopped, NULL ); return 0; }
Some notes to consider:
 This is not a duplicate of this question, since the solution in that thread doesn't work for me
 I have tried playing with the
decoder>samplesPerFrame
andnumSamples
but I can't get a decent output.  If I set the Time Stretching to
1
and Pitch Shift to0
the sound plays seamlessly.

Shift OpenCV matrix elements, extend and overlap add
I am working on a realtime system, for that I have to store and process dynamically elements in an OpenCV matrix. To address that, in every iteration step I delete the last element and extend it with a new one (with a zero). After that I overlapadd the (in that step) calculated results. There is a 256 length (
WINDOW_SIZE
) final signal length initialized with zeros, every step a 40 window length (STEP_SIZE
) signal calculated and overlap added with a sliding step of 1. When the end of the container (256) is reached, the shifting starts: the last element is deleted, and extended with a zero (push_back style). In my implementation the first (filling) part is working, but the second, shifting part is malfunctioning:cv::Mat tmpP, tmpZ, Pshift, Zshift; cv::Mat P = cv::Mat::zeros(WINDOW_SIZE, K*4, CV_64FC1); cv::Mat Z = cv::Mat::zeros(WINDOW_SIZE, K*4, CV_64FC1); cv::Mat zero_row = cv::Mat::zeros(1, K*4, CV_64FC1); int shift_idx = 0; while(true) { if( shift_idx + STEP_SIZE < WINDOW_SIZE) { // Calculate POS in every step, and overlap add signal if(Jt.size() == STEP_SIZE) { std::tie(tmpP, tmpZ) = pos(Jt, ordering); Jt.erase(Jt.begin()); // Overlap add for(int frms = 0; frms<STEP_SIZE; ++frms) { for(int wmsks = 0; wmsks < K*4; ++wmsks) { P.at<double>(frms+shift_idx, wmsks) += tmpP.at<double>(frms, wmsks); Z.at<double>(frms+shift_idx, wmsks) += tmpZ.at<double>(frms, wmsks); } } // [DEBUG] w.dispPulse(P.col(1)); // > This part is OK!! ++shift_idx; } } else { // In this case we have to remove old data and replace with new (1 frame...) to keep the WINDOW_SIZE length // Delete last row, and extend with a new filled with zeros. P(cv::Range(1, P.rows), cv::Range(0, P.cols)).copyTo(Pshift); Pshift.push_back(zero_row); P = Pshift; Z(cv::Range(1, Z.rows), cv::Range(0, Z.cols)).copyTo(Zshift); Zshift.push_back(zero_row); Z = Zshift; // Calculate POS and overlap add std::tie(tmpP, tmpZ) = pos(Jt, ordering); Jt.erase(Jt.begin()); // Overlap add for(int frms = 0; frms<STEP_SIZE; ++frms) { for(int wmsks = 0; wmsks < K*4; ++wmsks) { P.at<double>(frms+shift_idx, wmsks) += tmpP.at<double>(frms, wmsks); Z.at<double>(frms+shift_idx, wmsks) += tmpZ.at<double>(frms, wmsks); } } // [DEBUG] w.dispPulse(P.col(1)); } }
In the first filling part, the program functions well: If I plot at different time points the results:
At this point, the container is filled, and the program enters the other segment. Instead of extending and shifting the signal (and remove the old points) it seems only the new
STEP_SIZE
length signal is present:Where could be the problem?

FIR filter (Tap =50) using using a separate .txt file for the coefficients. How to read these numbers as a 16bit signed fixed point
I'm designing an FIR filter (Tap =50) using Verilog on Modelsim. I have a separate .txt file for the coefficients, which has a total of 50 decimal number entries. However, I am supposed to read these numbers as a 16bit signed fixed point. So what should I do?