NMF.ipynb#
Non-Negative Matrix Factorization (NMF) is the factorization technique we used to get certain sound feature. Turns out you can easily distinguish repeating sound feature using algorithm like NMF. The state of the art is actually a deep learning model, but I don’t have the required knowledge to do deep learning, so I settled for more traditional signal processing algorithm.
NMF is a blind source separation algorithm, which means that you don’t need to know about the input to separate it to multiple components. The way they do this is by approximating the original sound (matrix). If you know SVD (Singular Value Decomposition) you basically know everything about this algorithm, it basically uses sum of rank-1 matrices. I won’t be explaining too too much in this documentation, but I will provide a link for any of you that are interested in this algorithm.
The algorithm I use isn’t created by me though, credit to Zahra Benslimane for this. Her blog also explain a little bit of the implemented algorithm. Finally here is a few resources for you to learn about NMF:
How to Use#
To use the algorithm, open the
Audio-Source-Separation-using-NMF.ipynb.Install all the dependencise (mainly librosa)
Select your audio file in the
audio_filevariableChoose a sample rate, usually I downsample the signal because it will take too too much ram otherwise
On header 3, first cell there is a variable called
Sthere, this specify how many feature you can get. You can just specify a large number for this if you want toAlso you can modify the
betavariable, which is your loss function, basically a family of probability distribution.Beta = 2is your usual distance squared, other common choice ofBetais 1 and 0Run all except the save file cell
Just wait for the algorithm to finish, it takes quite a while
Once it’s finished, there will be displayed sound and spectogram of the separated sound sources
Hear which sound you want to extract, keeping note of the indices
Put your indices on a variable such as
heartbeat_indexSplice and combine your sound signal